ORACLE的基础用法
ORACLE的基礎用法
轉 自:http://blog.163.com/kelly_19831017/blog/static/6196787020083133348873/
sqlplus sys/oracle as sysdba? //以SYS用戶名進入數據庫
startup? //啟動數據庫
shutdown immediate? //正常關閉數據庫(迫使每個用戶執(zhí)行完SQL語句時斷開連接)
shutdown abort //強行關閉數據庫(不建議使用)
help index //查詢sqlplus所有功能
set sqlblanklines on //支持空格行
select * from dept where deptno=&tt //tt為變量,要給tt副值
list //查看在緩沖區(qū)查看數據(l是簡寫)
l2 4 //查看在緩沖區(qū)查看數據(第二行到第4行)
change //修改
c/n/m //把n改成m
/ //執(zhí)行緩沖區(qū)的命令
del 4 //刪除緩沖區(qū)第行
a from dept //追加緩沖區(qū)的信息
save c:\text.txt //保存緩沖區(qū)的信息到C盤下text.txt
@c:\text.txt? //對記事本的信息保存緩沖區(qū)里頭
get c:\text.txt //獲得腳本內容
edit //用記事本打開緩沖區(qū)的內容
col deptno heading "編號" //把deptno改成編號
desc dept //查看數據庫對象dept表字段類型
col dname format a10 //取10個字符格式華輸出
connect //改變連接用戶
break on dept //對重復的數據只顯示一條
comp count label "別名" of 字段 on 字段? //對重復的字段進行記數
-------
create table abc? //創(chuàng)建表
alter table abc add c number? //向表abc追加一個字段
alter table abc drop column c? //向表abc刪除一個字段
grant select on dept to tt??? //授權dept這張表給TT用戶
revoke select on dept from tt //收回使用這張表的權限
select to_char(sysdate,'yyyy-mm-dd') from dual //把日期轉化為yyyy-mm-dd這種格式
select user from dual //查詢當前用戶
decode? //做統(tǒng)計用
---
create sequence identity
increment by 1
start with 1000
nomaxvalue??????? //創(chuàng)建自動增長列
---
insert into 表 select 字段 from 表? //從一張表插入多條數據到另外一張表
create table 表 as (select 字段 from 表)? //創(chuàng)建一張新表并且把另外一張表的數據插入進去
exp scott/oracle file=路徑? //把scott這個空間的表備份到這個路徑
imp scott/oracle ignore=true file=路徑 //把這個路徑下的文件導入到scott這個空間里面
---
declare
x number;? //定義一個變量
begin
x:=0;?? //給變量賦值
loop??? //循環(huán)
x:=x+1;? //記數
if x>=3 then exit; //當變量>=3時,跳出當前循環(huán)
end if;
end loop;
dbms_output.put_line('x='||x); //打印X的值
end;
---
while x<3 loop
x:=x+1;
end loop;
---
begin
for i in 1..5 loop? //循環(huán)i從1到5
dbms_output.put_line('x='||x);
end loop;
end;
---
begin
for i in reverse 1..5 loop? //循環(huán)i從1到5,倒序輸出
dbms_output.put_line('x='||x);
end loop;
end;
---
declare num number;
begin
select ClassID into num from Class where id=1000;?? //把查詢出來的ClassID這個值放入num這個變量中
exception
when no_date_found then dbms_output.put_line('沒有找到數據');
end;
---觸法器創(chuàng)建格式
create or replace trigger 觸法器名
after delete on 表名
for each row?? //對每一行進行觸發(fā)
begin
?~~~~~~~~~~~~~~~``
end
----
raise_application_error(-2000,"錯誤內容")? //強行不準刪除
---
alter user scott identified by aaa? //把scott用戶的表空間密碼改成aaa
alter user scott account lock? //把Scott表空間進行鎖定
alter user scott account unlock? //把Scott表空間進行解除鎖定
create user qqq identified by qqq123 default tablespace user //創(chuàng)建一個qqq,密碼為的用qqq123戶表空間, 默認表空間為qqq123
grant connect to qqq? //為qqq創(chuàng)建連接
with grant option //下放權限
grant all on scott.dept to tt //把所有權限給TT用戶
grant execute on tt.proc01 to text //把使用存貯過程的權限給Test用戶
grant create user to text //把創(chuàng)建用戶的權限給text用戶
grant drop user to text //把刪除用戶的權限給text用戶
grant connect,resource to userBook? //把一般的權限受給這個用戶
---
creare tablespace tabs?
datafile 'E:\Oracle\product\10.1.0\oradata\oracle\tabs.dbf' size 10M autoextend on;//創(chuàng)建一個tabs的表空間,默認的文件路徑,大小為10M
grant unlimited tablespace ,dba to test? //給表空間授權
---
select constraint_name,constraint_type from user_constraints
where table_name='emp';
日期函數:
select * from XiangMuBiao where kaishishijian<=last_day(sysdate) and kaishishijian>=add_months(last_day(sysdate)+1,-1)? //在本月中的所有字段
Select last_day(sysdate) from dual;//一個月的最后一天
select add_months(last_day(sysdate)+1,-1) month from dual;//本月的第一天
select?? to_date('20040401 122525','yyyymmdd?? hh24miss') from dual;//轉換為日期格式
轉載于:https://www.cnblogs.com/lzx_ok/archive/2010/10/20/1856649.html
總結
以上是生活随笔為你收集整理的ORACLE的基础用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用verilog语言写的任意整数的分频器
- 下一篇: 不同存储区域的数组分析