数据库:循环语句--1:if then/elsif/end if.

if循环语句:

1:语法:

IF <布尔表达式> THEN

PL/SQL 和 SQL语句
END IF;
--或
IF <布尔表达式> THEN
PL/SQL 和 SQL语句
ELSIF
其它语句
END IF;

2:实例:

--查询姓名是Scott的工资。
declare
V_ename emp.ename%type :='SCOTT';
V_sal emp.sal%type;
V_comment varchar2(60);

begin
select sal into V_sal from emp where ename=V_ename;
if V_sal<1500 then
V_comment :='Fairly less';
elsif V_sal<3000 then
V_comment :='A little more';
else
V_comment :='Lots of money';
end if;
dbms_output.put_line(V_sal);
dbms_output.put_line(V_comment);
end;

posted @ 2017-07-18 18:30  maqiang_66  阅读(1377)  评论(0编辑  收藏  举报