oracle存储过程case写法,oracle 存储过程语法小结及相关写法复习 if、case、loop等...

当前位置:我的异常网» 数据库 » oracle 存储过程语法小结及相关写法复习 if、case、

oracle 存储过程语法小结及相关写法复习 if、case、loop等

www.myexceptions.net  网友分享于:2013-03-27  浏览:301次

oracle 存储过程语法总结及相关写法复习 if、case、loop等

--1.存储过程之if

clear;

create or replace procedure mydel(

in_a in integer)

as

begin

if in_a<100 then

dbms_output.put_line('小于100.');

elsif in_a<200 then

dbms_output.put_line('大于100小于200.');

else

dbms_output.put_line('大于200.');

end if;

end;

/

set serveroutput on;

begin

mydel(1102);

end;

/

---------------------------------------------

--2.存储过程之case1

clear;

create or replace procedure mydel(

in_a in integer)

as

begin

case in_a

when 1 then

dbms_output.put_line('小于100.');

when 2 then

dbms_output.put_line('大于100小于200.');

else

dbms_output.put_line('大于200.');

end case;

end;

/

set serveroutput on;

begin

mydel(2);

end;

/

------------------------------------------------

--1.存储过程之loop1

clear;

create or replace procedure mydel(

in_a in integer)

as

a integer;

begin

a:=0;

loop

dbms_output.put_line(a);

a:=a+1;

exit when

a>301;

end loop;

end;

/

set serveroutput on;

begin

mydel(2);

end;

/

--------------------------------------------------

--1.存储过程之loop2

clear;

create or replace procedure mydel(

in_a in integer)

as

a integer;

begin

a:=0;

while a<300 loop

dbms_output.put_line(a);

a:=a+1;

end loop;

end;

/

set serveroutput on;

begin

mydel(2);

end;

--------------------------------------------------

--1.存储过程之loop3

clear;

create or replace procedure mydel(

in_a in integer)

as

a integer;

begin

for a in 0..300

loop

dbms_output.put_line(a);

end loop;

end;

/

set serveroutput on;

begin

mydel(2);

end;

/

clear;

select ename,cc:=(case

when comm=null then sal*12;

else (sal+comm)*12;

end case from emp order by salpersal;

----------------------------------------------------

clear;

create or replace procedure getstudentcomments(

i_studentid in int,o_comments out varchar)

as

exams_sat int;

avg_mark int;

tmp_comments varchar(100);

begin

select count(examid) into exams_sat from studentexam

where studentid=i_studentid;

if exams_sat=0 then

tmp_comments:='n/a-this student did not attend the exam!';

else

select avg(mark) into avg_mark from studentexam

where studentid=i_studentid;

case

when avg_mark<50 then tmp_comments:='very bad';

when avg_mark<60 then tmp_comments:='bad';

when avg_mark<70 then tmp_comments:='good';

end case;

end if;

o_comments:=tmp_comments;

end;

/

set serveroutput on;

declare

pp studentexam.comments%type;

begin

getstudentcomments(8,pp);

dbms_output.put_line(pp);

end;

/

--------------------

delete from emp where empno<6000;

clear;

create or replace procedure insertdata(

in_num in integer)

as

myNum int default 0;

emp_no emp.empno%type:=1000;

begin

while myNum

insert into emp values(emp_no,'hui'||myNum,'coder',7555,current_date,8000,6258,30);

emp_no:=emp_no+1;

myNum:=myNum+1;

end loop;

end;

/

set serveroutput on;

begin

insertdata(10);

end;

/

select * from emp;

------------------------------

clear;

select studentname,averageMark,case

when averageMark<60 then '不及格'

when averageMark<70 then '考得好'

when averageMark<80 then '考得很好'

end case

from (select (

select b.name from student b where b.studentid=a.studentid) as studentname,

round(avg(mark),2) as averageMark from studentexam a group by a.studentid);

我的异常网推荐解决方案:oracle存储过程,http://www.myexceptions.net/oracle-develop/177537.html

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值