此文为本人学习ORACLE 8 PL/SQL 程序设计的学习笔记
1.PL/SQL描述
2.PL/SQL功能特性
1.PL/SQL描述
PL/SQL是Procedural Language/SQL(过程性语言/SQL)的缩写。
正如其名字所表达的,PL/SQL通过增加了用在其他过程性语言中的结构来对SQL进行了扩展。
过程性结构与oracle SQL 无缝地集成到一起,这样便产生了一种结构化地强有力地语言。
2.PL/SQL功能特性
A.PL/SQL中的基本单位是块("block"),所有的PL/SQL程序都是由块构成的,这些块可以相互进行嵌套。
通常,每一个块执行程序的一个单元的工作,这样每一个块就分担不同的任务。
一个块拥有下述的结构
DECLARE
/*Declarative section
-PL/SQL variables,types,cursors
and local subprograms go here
that's option
*/
BEGIN
/* Executable section- procedural and SQL statements go here
This is the main section of the block and the only one
that is required.
*/
EXCEPTION
/* Exception handing section --error-handling statements go here
that's option
*/
END;
B.变量和类型
在PL/SQL和数据库之间是通过变量(variable)来传递信息的,
每个变量对应一种特定的类型,同时该类型也决定了该变量所能够存储的是什么类型的信息
类型有:同数据库列类型,用户定义的table and record,也支持对象类型(属性和方法)
例如:
Declare
v_StudentName Varchar2(20);
v_CurrentDate Date;
v_NumberCredits NUMBER(3);
TYPE t_StudentRecord is RECORD
(
FirstName Varchar2(10);
LastName Varchar2(10);
CurrentCredits Number(3);
);
v_Student t_StudentRecord;
C.循环结构
loop
exit when ;
end loop;
for i in 1..50 loop
end loop
cursor
open C_cursor
loop
fetch C_cursor into v_varible
exit when c_cursor%notfound;
end loop
close c_cursor
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/41594/viewspace-50568/,如需转载,请注明出处,否则将追究法律责任。