1、表
create table test (names varchar2(12),
dates date,
num int,
dou double);
2、檢視
create or replace view vi_test as
select * from test;
3、同義詞
create or replace synonym aa
for dbusrcard001.aa;
4、儲存過程
create or replace produce dd(v_id in employee.empoy_id%type)
asbegin
enddd;
5、函式
create or replace function ee(v_id in employee%rowtype) return varchar(15)
isvar_test varchar2(15);
begin
return var_test;
exception when others then
end6、三種觸發器的定義
create or replace trigger ff
alter delete
on test
for each row
declare
begin
delete from test;
if sql%rowcount < 0 or sql%rowcount is null then
rais_replaction_err(-20004,"錯誤")
end if
endcreate or replace trigger gg
alter insert
on test
for each row
declare
begin
if :old.names = :new.names then
raise_replaction_err(-2003,"編碼重複");
end if
endcreate or replace trigger hh
for update
on test
for each row
declare
begin
if updating then
if :old.names <> :new.names then
reaise_replaction_err(-2002,"關鍵字不能修改")
end if
end if
end7、定義游標
declare
cursor aa is
select names,num from test;
begin
for bb in aa
loop
if bb.names = "oracle" then
end if
end loop;
end8、速度優化,前一語句不後一語句的速度快幾十倍
select names,dates
from test,b
where test.names = b.names(+) and
b.names is null and
b.dates > date('2003-01-01','yyyy-mm-dd')
select names,dates
from test
where names not in ( select names
from b
where dates > to_date('2003-01-01','yyyy-mm-dd'))
9、查詢重覆記錄
select names,num
from test
where rowid != (select max(rowid)
from test b
where b.names = test.names and
b.num = test.num)
10、查詢表test中時間最新的前10條記錄
select * from (select * from test order by dates desc) where rownum < 11
11、序列號的產生
create sequence row_id
minvalue 1
maxvalue 9999999999999999999999
start with 1
increment by 1insert into test values(row_id.nextval,....)
Oracle基本語法
1 window下啟動oracle服務 net start oracle服務名 net start oracle的 名 2 建立使用者 create user 建立使用者的名稱 identified by 建立使用者的密碼 3 修改使用者口令 alter user 需要修改使用者 identifie...
Oracle基本語法
檢視表結構 descride 修改表型別 alter table tablename modify.alter table emp modify empname char 55 修改表字段 alter table tablename add.alter table emp add enote1 ch...
Oracle基本語法
約束條件 唯一鍵 unique constraint constraint name unique columu constraint name 約束名稱columu 欄位名稱 例子 constraint emp uk unique empid 查詢表的約束條件 select constraint ...