oracle 儲存過程和游標的使用

2021-06-20 18:24:17 字數 1786 閱讀 3620

--1、編寫乙個函式,輸入員工編號將每位員工工作了多少年零多少月零多少天輸出來:如

-- 年份:***x  月份:xx  天數:xx

create or replace procedure proc_workofyear(eno number)

iscursor curs_workofyear is select ename ,   

floor(months_between(sysdate,hiredate)/12) as wyear,   

mod(floor(months_between(sysdate,hiredate)),12) as wmonth,   

mod(floor(sysdate-hiredate),30) as wday

from emp where empno=eno;

begin

for i in curs_workofyear loop

dbms_output.put_line(i.ename||':工作了'||i.wyear||'年'||i.wmonth||'月'||i.wday||'天。');

end loop;

end;

declare

v_empno number(10):=&empno;

begin

proc_workofyear(v_empno);

end;

--2、編寫乙個儲存過程,輸入某位員工的編號,如果某個員工的工資低於200 元,就新增100 元,否則新增50。

create or replace procedure proc_emp(eno number) 

iscursor curs_emp is select sal from emp where empno=eno for update;

begin

for i in curs_emp 

loop

if i.sal>200 then 

update emp set sal=sal+100 where current of curs_emp;

else

update emp set sal=sal+50 where current of curs_emp;

end if;

end loop;

end;

declare

v_empno emp.empno%type :=&empno;

begin

proc_emp(v_empno);

end;

--3、編寫乙個儲存過程,可以輸入部門號,並顯示該部門所有員工姓名和工

create or replace procedure proc_dept(dno in number,ename out varchar2,sal out varchar2)

iscursor curs_dept is select ename,sal into ename,sal from emp where deptno=dno;

begin

for i in curs_dept loop

dbms_output.put_line('員工姓名:'||i.ename||'   工資:'||i.sal);

end loop;

end;

declare

v_deptno emp.deptno%type :=&deptno;

v_ename varchar2(10);

v_sal emp.sal%type;

begin

proc_dept(v_deptno,v_ename,v_sal);

end;

oracle帶游標的儲存過程

create or replace procedure xs test add19 is bachelor edu varchar2 2000 new bachelor edu varchar2 2000 aa varchar2 2000 bb varchar2 2000 edu length in...

oracle 帶游標的儲存過程

如果各位以前從來沒有寫儲存過程,可得仔細了,因為在進行儲存過程編寫的時候,新手很容易出錯,非常容易。執行儲存過程各個oracle客戶端是不是樣的 可能你在網上看到的是呼叫exec,但是你再怎以呼叫你都執行不了,原因何在,因為exec是pl sql develop裡面的乙個程式,而你當前使用oracl...

oracle 含參帶游標的儲存過程

系統中有個模組的基礎資料需要導到資料庫,由於資料量比較大,而且 內容分布較凌亂。就先將資料匯入臨時表,然後根據臨時表進行有效的檢索並新增到對應的表中。今天下午寫了個含有引數,帶游標的儲存過程。算是把這個問題給解決了。本人需求大致如下 現有臨時表 sheet1 資料是直接從excel的sheet1中讀...