pl/sql case when then

--查询出150号员工的工资,若其工资大于或等 于10000,则打印'打印salary>=10000';
--若其工资大于5000且小于10000,则打印出“5000<salary<10000”否则打印出“salary<5000”
可以这样写
declare
v_sal employees.salary% type;
v_tem VARCHAR2(30);
begin 
select salary into  v_sal from employees where employee_id=100;
 v_tem:=
case
when  v_sal>=10000 then'salary>=10000'
when  v_sal>5000 and v_sal <10000 then  '5000<salary<10000'
else 'salary<5000'
end ;
dbms_output.put_line(v_tem);
end;
这样写也能输出,暂时无法搞明白其中原由,但可见其规律
set serveroutput on;
declare
v_sal employees.salary% type;
v_tem VARCHAR2(30);
begin 
select salary into  v_sal from employees where employee_id=100;
case
when  v_sal>=10000 then v_tem:='salary>=10000';
when  v_sal>5000 and v_sal <10000 then  v_tem:='5000<salary<10000';
else v_tem:='salary<5000';
end case;
dbms_output.put_line(v_tem);
end;




declare
v_jobid employees.job_id % TYPE;
v_temp VARCHAR2(30);
begin 
select job_id into v_jobid from employees where employee_id=122;
v_temp:=
case v_jobid
when 'IT_PROG' then 'a'
WHEN 'AC_MGT' then 'b'
when 'AC_ACCOUNT' then 'c'
ELSE 'D'
end ;
dbms_output.put_line(v_temp);
end;
set serveroutput on;
方法二:
declare
v_jobid employees.job_id % TYPE;
v_temp VARCHAR2(30);
begin 
select job_id into v_jobid from employees where employee_id=122;


case v_jobid
when 'IT_PROG' then v_temp:= 'a';
WHEN 'AC_MGT' then v_temp:= 'b';
when 'AC_ACCOUNT' then v_temp:= 'c';
ELSE v_temp:= 'D';
end case;
dbms_output.put_line(v_temp);
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值