createorreplacepackagepack1--创建包头/规范
is
aanumber:=1;--在包头声明的为公有变量
procedureupdate_student(update_rowinstudent%rowtype);--声明一个更新过程
procedureinsert_student(insert_rowinstudent%rowtype);--声明一个插入过程
endpack1;--结束包头
--Package created
createorreplacepackagebodypack1--创建包体/主体
is
bbnumber:=2;--在包体声明的变量类私有变量
procedureinsert_student(insert_rowinstudent%rowtype)--创建过程主体
as
begin
insertintostudent(id,name,age)values(insert_row.id,insert_row.name,insert_row.age);
dbms_output.put_line('bb = '||bb||'aa = '||aa);
endinsert_student;--结束过程主体
procedureupdate_student(update_rowinstudent%rowtype)--创建过程主体
as
begin
updatestudent ssets.name='赵北'wheres.id=update_row.id;
endupdate_student;--结束过程主体
endpack1;--结束主体/包体
--Warning: Package body created with compilation errors
-----------------------------在程序包中创建ref游标---------------
createorreplacepackagepack3
is
typeref_cursorisrefcursor;--声明一个ref游标类型
procedureref_student_pro;
endpack3; --Package created
createorreplacepackagebodypack3
is
procedureref_student_pro
is
student_row student%rowtype;
student_ref_cursor ref_cursor;--声明一个ref游标类型的变量
begin
openstudent_ref_cursorforselect*fromstudent;
fetchstudent_ref_cursorintostudent_row;
whilestudent_ref_cursor%found
loop
dbms_output.put_line('学号 = '||student_row.id||'姓名 = '||student_row.name);
fetchstudent_ref_cursorintostudent_row;
endloop;
closestudent_ref_cursor;
endref_student_pro;
endpack3;
createorreplaceprocedurepro_utl_file(path_fileinvarchar2,name_fileinvarchar2)
is
utl_file_contentsvarchar2(2000);--定义内存变量
utl_file_type utl_file.file_type;--定义文件类型变量
begin
utl_file_type:=utl_file.fopen(path_file,name_file,'r',2000);--打开文件
loop
utl_file.get_line(utl_file_type,utl_file_contents);--读取文件内容到内存变量中
dbms_output.put_line(utl_file_contents);--,并打印
endloop;
exception--异常处理部分
whenno_data_found
then
utl_file.fclose(utl_file_type);
end;
Procedurecreated
SQL>setserverouton
SQL>executepro_utl_file('DIR_UTL_FILE','utl_file');
DECLARE
V1VARCHAR2(32767);
F1 UTL_FILE.FILE_TYPE;
BEGIN -- In this example MAX_LINESIZE is less than GET_LINE's length request -- so the number of bytes returned will be 256 or less if a line terminator is seen.
F1:=UTL_FILE.FOPEN('MYDIR','MYFILE','R',256);
UTL_FILE.GET_LINE(F1,V1,32767);
UTL_FILE.FCLOSE(F1);
-- In this example, FOPEN's MAX_LINESIZE is NULL and defaults to 1024, -- so the number of bytes returned will be 1024 or less if a line terminator is seen.
F1:=UTL_FILE.FOPEN('MYDIR','MYFILE','R');
UTL_FILE.GET_LINE(F1,V1,32767);
UTL_FILE.FCLOSE(F1);
-- In this example, GET_LINE doesn't specify a number of bytes, so it defaults to -- the same value as FOPEN's MAX_LINESIZE which is NULL in this case and defaults to 1024. -- So the number of bytes returned will be 1024 or less if a line terminator is seen.
F1:=UTL_FILE.FOPEN('MYDIR','MYFILE','R');
UTL_FILE.GET_LINE(F1,V1);
UTL_FILE.FCLOSE(F1);
END;