函数:
Pl/sql:
基本语法:
set ServerOutput on;[定义输出]
declare[定义]
bookName varchar2(40);
begin[开始]
bookName :=[给变量赋值]'gouchao';
dbms_output[输出].put_line(bookName);
end[结束];
/
条件语句 if
set ServerOutput on ;
declare
num integer :=-11 ;
begin
if num < 0 then
dbms_output.put_line('负数');
elsif num > 0 then
dbms_output.put_line('正数');
else
dbms_output.put_line('0');
end if ;
end;
/
分支语句case:
set ServerOutput on ;
declare
num integer :=3 ;
result varchar2(30);
begin
result:= case num
when 1 then '星期一'
when 2 then '星期二'
when 3 then '星期三'
when 4 then '星期四'
when 5 then '星期五'
when 6 then '星期六'
when 7 then '星期天'
else '数据越界'
end;
dbms_output.put_line(result);
end;
/
循环语句loop...next...end
循环语句loop...exitwhen ... end loop
set ServerOutput on;
declare
num integer :=10;
begin
loop
dbms_output.put_line(num);
num := num -1;
exit when num <= 0;
end loop;
end ;
/
循环语句 while...loop...end loop
set ServerOutput on;
declare
num integer :=10;
begin
while(num > 0)
loop
dbms_output.put_line(num);
num := num -1;
end loop;
end ;
/
循环语句for...in...loop...end loop
set ServerOutput on;
declare
i integer ;
begin
for i in 1..10
loop
dbms_output.put_line(i);
end loop;
end ;
/
set ServerOutput on;
declare
i integer ;
begin
for i in 1..10
loop
if(i=5) then
exit;
end if;
dbms_output.put_line(i);
end loop;
end ;
/