oracle里這種declare語句塊叫什么家伙
declare age number(4);--聲明一個參數 a 類型為 number類型 長度為4begin select teaAge into age from teacher where teaid = 122; --查詢 teaid為122的teaAge 把teaAge的值放到age中 if age>24 then --當age的值大于24 dbms_*_line('da'); --就在控制臺輸出da dbms_output 是一個系統包 調用了包里面的put_line函數 else dbms_*_line('xiao');--如果小于24 輸出 xiao end if;--結束if語句end; --結束這個程序。
oracle begin 語句塊求助
給你個例子,不知道是不是你說的這樣
先說一下,oracle不能直接用select語句而不把查出的結果放到變量里,不過可以這樣
--這個是只能輸出一條記錄,多了會報錯,因為一個變量只能接收一個數值
declare
v_a int;
v_b number(10,2);
begin
select empno,sal into v_a,v_b from emp where empno=7369 ;
dbms_*_line(v_a||','||v_b);
end;
--再給你寫個結果集的
declare
v_a int;
v_b number(10,2);
cursor v_cur is select empno,sal from emp order by empno;
begin
open v_cur;
loop
fetch v_cur into v_a,v_b;
exit when v_cur%notfound;
dbms_*_line(v_a||','||v_b);
end loop;
close v_cur;
end;
oracle begin 語句塊求助
給你個例子,不知道是不是你說的這樣先說一下,oracle不能直接用select語句而不把查出的結果放到變量里,不過可以這樣--這個是只能輸出一條記錄,多了會報錯,因為一個變量只能接收一個數值declarev_a int;v_b number(10,2);begin select empno,sal into v_a,v_b from emp where empno=7369 ;dbms_*_line(v_a||','||v_b);end;--再給你寫個結果集的declarev_a int;v_b number(10,2);cursor v_cur is select empno,sal from emp order by empno;begin open v_cur; loop fetch v_cur into v_a,v_b; exit when v_cur%notfound; dbms_*_line(v_a||','||v_b); end loop; close v_cur;end;。
編寫PL/SQL語句塊
a.建立sequence
create sequence yao.s_app
start with 0
maxvalue 100000
minvalue 0
nocycle
nocache
noorder;
b.寫pl/sql塊
variable v_dname;
begin
insert into department
values(:dname,s_*l);
end;
————————————————————
環境:oracle 10g/toad 以上代碼均通過測試,如有問題,請聯系,謝謝
Oracle代碼塊中語句重復使用問題
用rowid方法: 據據oracle帶的rowid屬性,進行判斷,是否存在重復,語句如下: 查數據: select * from table1 a where rowid !=(select max(rowid) from table1 b where *1=*1 and *2=*2。
。)刪數據: delete from table1 a where rowid !=(select max(rowid) from table1 b where *1=*1 and *2=*2。
。)。