構建程序包、
阿新 • • 發佈:2017-08-17
隱式 body scl lec num rep row eight fetch
--構建程序包 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 forselect * from student s where s.class = scla; end; end stuinfo; select * from student;
隱式遊標
DECLARE BEGIN /* insert update delete select(返回單行的查詢) */ 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;
調用程序包執行存儲過程
-- 調用程序包執行存儲過程 declare type stuc is ref cursor; --stuc引用遊標 sts stuc;--聲明stuc類型的變量 stu student%rowtype; --每一行查詢 begin stuinfo.showname(95033,sts); loop fetch sts into stu; exitwhen sts%notfound; dbms_output.put_line(stu.sname); end loop; end;
構建程序包、