oracle_pl_sql 实例精解--3-5章

第三章 pl/sql中的sql
1、select into 进行变量初始化

2、使用序列
create sequence eseq
increment by 1;
create table test(col1 number);
begin
insert into test values (eseq.nextval);
commit;
end;
/
select * from test;
3、使用savepoint;
select eseq.currval from dual;
begin
insert into test values (eseq.nextval);
savepoint a ;
insert into test values (eseq.nextval);
savepoint b ;
insert into test values (eseq.nextval);
savepoint c ;
insert into test values (eseq.nextval);
savepoint d ;
rollback to b;
commit;
end;
/
select * from test;


第四章 if语句
if condition then
end if;
if condition then
else if condition then
else
end if;


declare
v_day varchar2(10):=trim(to_char(sysdate,'DAY'));
begin
if v_day = 'TUESDAY'  then
dbms_output.put_line('today is TUESDAY');
else
dbms_output.put_line('go to play');
end if;
end;
/
第五章 case语句
case selector
when expression then 
statment ;
when expression then
statment ;
else 
statment ;
end case;


declare
v_day varchar2(10):=trim(to_char(sysdate,'DAY'));
begin
case v_day
when 'MONDAY' then 
dbms_output.put_line('today is MONDAY');
when 'FRIDAY' then
dbms_output.put_line('today is FRIDAY');
else 
dbms_output.put_line('today is 2,3,4,6,7');
end case;
end;


declare
v_day number :=to_char(sysdate,'D');
begin
case  
when v_day >6 then 
dbms_output.put_line('today is xingqi6');
when v_day >5 then 
dbms_output.put_line('today is xingqi5');
when v_day >4 then 
dbms_output.put_line('today is xingqi4');
when v_day >3 then 
dbms_output.put_line('today is xingqi3');
else 
dbms_output.put_line('today is 1,2,7');
end case;
end;


declare
v_day number :=to_char(sysdate,'D');
v_c varchar(20);
begin
 v_c :=
  case
  when v_day >6 then 'xingqi6'
  when v_day >5 then 'xingqi5'
  when v_day >4 then 'xingqi4'
  when v_day >3 then 'xingqi3'
  else '1,2,7'
 end;
 dbms_output.put_line('today is'||v_c);
end;


declare
v_day number :=to_char(sysdate,'D');
v_c varchar(20);
begin
select
  case
  when sal >2000 then 'caogao'
  when sal >1000 then 'gao'
  when sal >500 then 'zhong'
  when sal >100 then 'di'
  else 'di'
 end
 into v_c
from scott.emp where empno=7369;
 dbms_output.put_line('gongzhi is '||v_c);
end;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22193071/viewspace-1355438/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22193071/viewspace-1355438/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值