首页 > 数据库 > Oracle > PLSQL简单的程序之一
一般的-PLSQL程序块主要包括三部分,则包括生命部分、执行部分与异常处理部分。执行一个完整的程序需要四部分。
以下简单举例了两个例子,来认识PLSQL程序。
----PLSQL程序块:
---一个完整的PLSQL程序块包括以下三个部分:
Declare #声明部分#
Declarations
Begin #开始执行部分#
Executable code
Exception #处理异常部分#
Exceptional handlers
End; #结束部分#
/ #执行程序必须以“/”为正式结束#
---编写最简单的程序:
打印出:The song is:My heart will go on and on.
scott@PROD>set serveroutput on
scott@PROD>begin
2 dbms_output.put_line('The song is:' ||
3 'My heart will go on and on');
4 end;
5 /
The song is:My heart will go on and on
PL/SQL procedure successfully completed.
#程序执行完成并打印出来要求的文字。如果要显示出来程序执行的结果,则要把
serveroutput 开启。
---编写程序块用来查询员工号为205员工的工资:
hr@PROD>set serveroutput on
hr@PROD>declare
2 v_esalary number(8,2);
3 begin
4 select salary into v_esalary
5 from employees where employee_id =205;
6 dbms_output.put_line('Their salary are: '||v_esalary);
7 end;
8 /
Their salary are: 12008
PL/SQL procedure successfully completed.
#程序执行完成。
这样把查询语句存储在PLSQL程序块里面,可以重复使用,通过修改一些参数值,
就可以查询出不同的结果。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2128345/ ,如需转载,请注明出处,否则将追究法律责任。