日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Oracle PL/SQL匿名块(三)

發布時間:2023/12/19 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle PL/SQL匿名块(三) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載:? http://blog.163.com/lyq_163_2009/blog/static/134082696201071210464738/

//錯誤處理

declare?

? v_temp number(4);

begin

? select empno into v_temp from emp where deptno=10;

exception

? when too_many_rows then

? ? dbms_output.put_line('太多記錄了...');

? when others then

? ? dbms_output.put_line('error...');

end;

/

?

?

//錯誤處理

declare

? v_temp number(4);

begin

? select empno into v_temp from emp where empno=2222;

exception

? when no_data_found then

? ? dbms_output.put_line('沒有數據...');

? when others then

? ? dbms_output.put_line('error...');

end;

/

?

?

//游標

declare

? cursor c is select * from emp;

? v_emp c%rowtype;

begin?

? open c;

? fetch c into v_emp;

? dbms_output.put_line(v_emp.ename);

? close c;

end;

/

?

?

//游標

declare

? cursor c is select * from emp;

? v_emp c%rowtype;

begin

? open c;

? loop

? ? fetch c into v_emp;

? ? exit when(c%notfound);

? ? ? dbms_output.put_line(v_emp.ename);

? end loop;

? close c;

end;

/

?

?

//游標

declare

? cursor c is select * from emp;

? v_emp c%rowtype;

begin

? open c;

? fetch c into v_emp;

? while(c%found)loop

? ? dbms_output.put_line(v_emp.ename);

? ? fetch c into v_emp;

? end loop;

? close c;

end;

/

?

?

//游標

declare

? cursor c is select * from emp;

begin

? for v_emp in c loop

? ?dbms_output.put_line(v_emp.ename);

? end loop;

end;

/

?

//帶參數的游標

declare

? cursor c(v_deptno emp.deptno%type, v_job emp.job%type) is?

? ? select ename,sal from emp where deptno=v_deptno and job=v_job;

? --v_temp c%rowtype;

begin

? --open c(30,'clerk');

? for v_temp in c(30,'CLERK') loop

? ? dbms_output.put_line(v_temp.ename || ' ' || v_temp.sal);

? end loop;

end;

/

?

?

//可以更新的游標

declare

? cursor c is select * from emp2 for update;

? --v_temp c%rowtype;

begin?

? for v_temp in c loop

? ? if(v_temp.sal < 2000)then

? ? ? update emp2 set sal=sal*2 where current of c;

? ? elsif(v_temp.sal =5000)then

? ? ? delete from emp2 where current of c;

? ? end if;

? end loop;

? commit;

end;

/

?

//創建表

create table emp2 as(

? ?select * from emp

);

//刪除表

drop table emp2;

轉載于:https://blog.51cto.com/baidu2013/1118699

總結

以上是生活随笔為你收集整理的Oracle PL/SQL匿名块(三)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。