Oracle-PLSQL基本操作
1.查询记录并打印
declare
--应用型变量:emp.sal是什么类型,那么通过emp.sal%type就可以指明vsal的类型
vsal emp.sal%type;
begin
--将值赋给vsal
select sal into vsal from emp where empno=7369;
--打印
dbms_output.put_line(vsal);
end;
declare
--声明记录型变量
vrow emp%rowtype;
begin
select * into vrow from emp where empno=7369;
dbms_output.put_line('姓名'||vrow.ename);
end;
条件判断
declare
age number := &输入年龄;
begin
if age < 18 then
dbms_output.put_line('未成年');
elsif age >18 and age <=35 then
dbms_output.put_line('年轻人');
elsif age >35 and age <=65 then
dbms_output.put_line('中年人');
else
dbms_output.put_line('老年人');
end if;
end;
while循环
declare
i number := 1;
begin
while i<=10 loop
dbms_output.put_line(i);
i := i+1;
end loop;
end;
for循环
declare
begin
for i in 1..10 loop
dbms_output.put_line(i);
end loop;
end;
加上reverse反转
declare
begin
for i in reverse 1..10 loop
dbms_output.put_line(i);
end loop;
end;
loop循环
declare
i number := 1;
begin
loop
exit when i > 10;
dbms_output.put_line(i);
i := i+1;
end loop;
end;
来源:CSDN
作者:赵昕彧
链接:https://blog.csdn.net/qq_40579464/article/details/103706248