使用declare或begin关键字开头的bai叫匿名块,每次使用均需要进行编译,不能存储在数据库中且不能被其他PL/SQL调用。
而存储过程,存储函数,触发器等叫命名块,一经编译后面就可直接调用,且可以存储在数据库中,被其他PL/SQL 调用;
declare
age number(4);--声明一个参数bai a 类型du为 number类型 长度为4
begin
select teaAge into age from teacher where teaid = 122; --查询 teaid为122的teaAge 把teaAge的值zhi放dao到age中
if age>24 then --当age的值大于zhuan24
dbms_output.put_line('da'); --就在控制台输出da dbms_output 是一个系统包shu 调用了包里面的put_line函数
else
dbms_output.put_line('xiao');--如果小于24 输出 xiao
end if;--结束if语句
end; --结束这个程序