b.BULK COLLECT语句 BULK COLLECT会检索多行数据,这些数据行存储在集合变量中
eg:
DECLARE
TYPE first_name_type IS TABLE OF student.first_name%TYPE;
TYPE last_name_type IS TABLE OF student.last_name%TYPE;
first_name_tab first_name_type;
last_name_tab last_name_type;
BEGIN
select first_name,last_name BULK COLLECT INTO first_name_tab ,last_name_tab FROM student;
FOR i IN first_name_tab.FIRST..first_name_tab.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('fist_name:'||first_name_tab(i));
END LOOP;
END;
17.存储过程
语法如下:
CREATE [OR REPLACE] PROCEDURE name
[(parameter[,parameter,...])]
AS
[local declarations]
BEGIN
executable statements
[EXCEPTION
exception handlers]
END [name];
18.函数
语法如下:
CREATE [OR REPLACE] FUNCTION function_name
[parameter...]
RETURN datatype
IS
BEGIN
RETURN [return_value]
END;
19.包
a.包规范语法:
CREATE OR REPLACE PACKAGE package_name
IS
[declarations of variables and types]
[specifications of cursors]
[specifications of modules]
END [package_name];
b.包体语法:
CREATE OR REPLACE PACKAGE BODY package_name
[declarations of variables and types] 注:只在包体中声明,但在包规范中未声明的变量、函数、存储过程作为私有变量(即只能被包体内的函数、存储过程调用)
[specifications of cursors]
[specifications of modules]
[BEGIN executable statements]
[EXCEPTION
exception handlers]
END [package_name];
eg:
CREATE OR REPLACE PACKAGE test_pkg
AS
PROCEDURE find_name(i_student_id IN student.student_id%TYPE);
FUNCTION id_is_good(i_student_id IN student.studend_id%TYPE)
RETURN BOOLEAN;
END test_pkg;
CREATE OR REPLACE PACKAGE BODY test_pkg
AS
PROCEDURE find_name(i_student_id IN student.student_id%TYPE)
IS
...
BEGIN
...
END find_name;
FUNCTION id_is_good(i_student_id IN student.studend_id%TYPE)
RETURN BOOLEAN
IS
...
BEGIN
...
END id_is_good;
END test_pkg;
20.使用RESTRICT_REFERENCES编译指令实现纯度等级
语法如下:
PRAGMA RESTRICT_REFERENCES( function_name,WNDS [,WNPS] [,RNDS] [,RNPS])
注:该函数必须存储在数据库中,而不是存储在ORACLE工具的库中
函数必须是行函数,而不是列函数或分组函数
对于所有函数(不管是否在SQL语句中使用),参数必须属于IN模式
eg:
CREATE OR REPLACE PACKAGE school_api
AS
FUNCTION new_id
RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(new_id,WNDS,WNPS,RNDS,RNPS);
END school api;
WNDS:write no database state,