--查询出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;
--若其工资大于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;