简单语法:
declare
--声明变量
变量名 变量类型
变量名 变量类型 :=初始值
begin
--编写业务逻辑
end;
条件语句:
declare
age number(4) :=20;--客户端技术:&名称
begin
if age<18 then
dbms_output.put_line('未成年');
elsif age>=18 and age<=24 then
dbms_output.put_line('青年');
elsif age>=24 and age<=40 then
dbms_output.put_line('中年');
else
dbms_output.put_line('老年');
end if;
end;
循环语句:
while循环:
while 条件 loop
end loop;
for循环:
for 变量 in 起始值..结束值 loop
end loop;
loop循环:
loop
exit when 条件
end loop;
PL/SQL打印图形:
打印正三角
begin
for i in 1..5 loop
for j in 1..5-i loop
dbms_output.put(' ');
end loop;
for m in 1..i loop
dbms_output.put('* ');
end loop;
dbms_output.put_line('');
end loop;
end;
打印倒三角
begin
for i in 1..5 loop
for j in 1..i loop
dbms_output.put(' ');
end loop;
for m in 1..5-i loop
dbms_output.put('* ');
end loop;
dbms_output.put_line('');
end loop;
end;
打印菱形
begin
for i in 1..4 loop
for j in 1..5-i loop
dbms_output.put(' ');
end loop;
for m in 1..5 loop
dbms_output.put('* ');
end loop;
dbms_output.put_line('');
end loop;
end;