Chinaunix首页 | 论坛 | 博客
  • 博客访问: 421113
  • 博文数量: 113
  • 博客积分: 2228
  • 博客等级: 大尉
  • 技术积分: 1341
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-24 15:07
文章分类

全部博文(113)

文章存档

2013年(52)

2012年(61)

我的朋友

分类: Oracle

2012-10-26 11:18:58

---------------------------------------------
--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); 

查看全部:

阅读(1246) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~