游標作業1

2022-09-15 18:51:13 字數 1154 閱讀 5767

1:編寫一段程式,通過輸入的員工編碼,查詢並列印員工的姓名、職位和薪水,並定義異常處理。(預定義異常)

2:獲得所有員工的平均工資,如果平均工資大於2000,視為使用者定義的異常,提示「員工工資有點高」,否則列印平均工資。(使用者定義異常)

3:使用顯式游標,(輸入乙個員工工資數)根據員工工資(sal)引數,查詢員工表emp中工資大於等於該引數的員工資訊,

顯示內容包括員工編碼(empno),姓名(ename),工資(sal).用游標無條件迴圈做(for迴圈來做)。

1.declare

v_empno emp.empno%type;

v_ename emp.ename%type;

v_job emp.job%type;

v_sal emp.sal%type;

begin

select ename,job,sal into v_ename, v_job, v_sal from emp where empno='7788'

exception

when no_data_found

dbms_output.put_line('編碼不存在');

when too_many_rows then

abms_output.put_line('查詢的記錄過多');

when others then

abms_output.put_line('其他異常');

end3.

declare

cursor cursor_emp is

select ename,empno,sal from emp where sal=>&v_sal;

v_sal emp.sal%type;

v_ename emp.ename%type;

v_empno emp.empno%type;

begin

open cursor_emp;

loop

fetch cursor_emp v_sal;

exit when cursor_emp%notfound

dbma_ouput.put_line(||編號為:||v_empno||的||v_ename||的工資是:||v_sal);

end loop;

close cursor_emp;

end;

pl sql游標 PL SQL游標 1

pl sql游標 游標 隱式游標 sql返回單行。由oracle server建立。顯式游標 sql重新調整多個記錄行。由使用者建立。游標生命週期 宣告 開啟 獲取 檢查最後一條記錄 關閉 基本語法 declare cursor cursorname param1,param2,is select ...

作業呼叫的游標

作業呼叫的游標 用途 每天晚上執行,對所有未贈送積分的訂單進行贈送積分 修改 07 03 12 新增的積分啟用 修改 07 03 13 註冊驗證積分啟用限制在3個月 修改 07 03 14 註冊驗證積分07 03 15前不受3個月限制 create procedure dbo getetorders...

Oracle 游標使用大全 1

查詢 select語句用於從資料庫中查詢資料,當在pl sql中使用select語句時,要與into子句一起使用,查詢的返回值被賦予into子句中的變數,變數的宣告是在delcare中。select into語法如下 select distict all into variable variable...