oracle儲存過程

2021-08-22 10:39:12 字數 1456 閱讀 3004

-----------------不帶引數  

/* 第乙個儲存過程:列印helloworld

呼叫儲存過程兩種方式:

1. exec sayhelloworld();

2. begin

sayhelloworld();

sayhelloworld();

end;/*/

create or replace procedure sayhelloworld 

asbegin

dbms_output.put_line('hello world');  

end sayhelloworld;

/--------------------------------------帶入參的儲存過程

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? 不要commit  誰呼叫  誰commit

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

end;

/-----------------------------------------------儲存函式

--查詢某個員工的年收入

create or replace function queryempincome(eno in number)

return number

as--月薪和獎金

psal emp.sal%type;

pcomm emp.comm%type;

begin

--得到月薪和獎金

select sal,comm into psal,pcomm from emp where empno=eno;

--返回年收入

return psal*12+nvl(pcomm,0);

end;

/--------------------儲存函式中繫結變數

begin

:result := queryempincome(eno => :eno);  --------  eno => 1  --表示賦值

end ;

儲存過程和儲存函式區別

1.一般來說儲存過程沒有返回值,儲存函式可以有乙個返回值。

2.儲存過程和儲存函式可以通過out指定乙個或者多個輸出引數,可以利用out引數,在儲存過程和儲存函式實現多個返回值。

3.原則來說:只有乙個返回值用儲存函式,多個返回值用儲存過程。

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...