//程式包create or replace package cal as
procedure addtest(a in number, b in number);
end cal;
//程式體
create or replace package body cal as
procedure addtest(a in number, b in number) as
begin
dbms_output.put_line(a +b);
end;
end cal;
利用引用游標構建的程式包 和程式體
--構建程式包create or replace package stuinfo as
type stucur is ref cursor;
procedure showname(scla in number, stus out stucur);
end stuinfo;
--構建程式包體
create or replace package body stuinfo as
procedure showname(scla in number, stus out stucur) as
begin
open stus for select * from student s where s.class=scla;
end;
end stuinfo;
隱式游標
declarebegin
update student s set s.sbirthday = s.sbirthday + 3650 where s.class=95031
; if sql%found then
dbms_output.put_line(
'資料更新成功 !');
dbms_output.put_line(sql%rowcount);
commit;
else
dbms_output.put_line(
'更新失敗 !');
end if;
end;
觸發器語句級觸發器: 乙個 update/delete/insert 語句只使觸發器執行一次
create or replace trigger employees_trigger
after
update on employees
begin
dbms_output.put_line('修改了一條記錄!');
end;
30. 使用 :new, :old 修飾符
create or replace trigger employees_trigger
after
update on employees
for each row
begin
dbms_output.put_line('old salary: ' || :old.salary || ', new salary: ' || :new.salary);
end;
31. 編寫乙個觸發器, 在對 my_emp 記錄進行刪除的時候, 在 my_emp_bak 表中備份對應的記錄
1). 準備工作:
create table my_emp as select employee_id id, last_name name, salary sal from employees
create table my_emp_bak as select employee_id id, last_name name, salary sal from employees where 1 = 2
2).
create or replace trigger bak_emp_trigger
before delete on my_emp
for each row
begin
insert into my_emp_bak values(:old.id, :old.name, :old.sal);
end;
Oracle 游標 引用游標
sql set severoutput on sp2 0735 unknown set option beginning severoutpu.sql set serveroutput on sql remark 引用游標 sql remark sql remark sql remark 引用游標 ...
隱式游標返回游標總數
第乙個應用得知更新的行數 1 隱式游標在正常執 況下更新的行數並不知道,可以根據sql rowcount得知更新的行數 set serveroutput on begin update student set first name d where first name like d dbms out...
mysql隱式游標 MYSQL 游標 動態游標示例
mysql沒有隱式和顯式游標之分,所用的游標都是顯式游標,也就是必須要進行定義游標變數,然後按照正規的流程使用,開啟 遍歷 關閉。以下是具體的使用方法。游標定義 1.declare cursor name cursor for select statement 游標操作 open 開啟游標 1.op...