Oracle儲存過程

2021-08-16 12:19:30 字數 1114 閱讀 2968

儲存過程

1.不帶引數的格式(即使沒有說明部分,as也不能省略)

set serveroutput on;

create or replace procedure sayhelloworld

as--說明部分

begin

dbms_out.put_line(hello world);

end;

2.呼叫儲存過程

(1)exec sayhelloworld();

(2)begin

sayhelloworld();

sayhelloworld();

end;

/3.帶引數的儲存過程

create or replace procedure raisesalary(eno in number)

as--定義乙個變數曹村漲前的薪水

psal emp.sal%type

begin

--得到員工漲前的薪水

select sal into psal from emp where empno=eno;

--給員工漲100

update emp set sal=sal+100 where empno=eno;

--需不需要提交?

--注意:一般不在儲存過程或者儲存函式中,commit和rollback

--列印

dbm_out.put_line('漲前 :'||psal||'  漲後:'||(psal+100));

end;

4.如何呼叫3

begin

raisesalary(7839);

raisesalary(7566);

commit;

end;

5.除錯

(1)提示此會話需要debug connect和debug any procedure使用者許可權

grant debug connect session,debug any procedure to liuzq

儲存函式

函式為一命名的儲存程式,可帶引數,並返回一計算值

函式和過程的結構類似,但必須有乙個return子句,用於返回函式值

Oracle儲存過程呼叫儲存過程

oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...

ORACLE儲存過程

自定義函式開始 create or replace function fn wftemplateidget templatecategoryid number,organid number,templatemode number return number istemplateid number i...

Oracle 儲存過程

create or replace procedure p 有就替換,沒有就建立 iscursor c is select from emp for update begin for v emp in c loop if v emp.deptno 10 then update emp2 set sa...