付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
目一、PL/SQL简 什么是 PL/SQL程序结 PL/SQL运行过 注 二、变量与数据类型 数据类 标量类 变量.............................................................................................................................三、流程控制语句 条件语 循环语 四、PL/SQL中的 PL/SQL中的SQL分 五、PL/SQL中的 select语句的实 record类 record变量的...........................................................................................................cursor的概 cursor的分 显式cursor的处 显式cursor的属 隐式cursor的属 cursor的..................................................................................................................open fetch close 六、集合 什么是 Associativearrays的定 Associativearrays类型和变量 Associativearrays的方 Associativearrays的异 批量绑 七、异 Oralce错 Oralce错误处理机 PL/SQL中的异 异常捕 非Oracle预定义异 sqlcode和 八、子程 子程 九、过程 语 创建过 调用过 过程中的DDL语 变 PL/SQL中的SQL分 案 十、函数 语 对函数function的基本操 案 十一、包 什么是 包的组 包的优 package的语 packagebody的语 案 十二、触发器 12.1问 DML触发器的组 DML触发器的类 DML触发器的触发顺 DML行级触发 :OLD和 十三、其他注意事 PL/SQL的特 写PL/SQL的好 保证所有对象的状态都是 declare中都可什 一、PL/SQL简介什么是PL/SQL(ProceduralLanguage/SQL)是OracleSQL的基础上增加了过程化处理,DMLselectPL/SQL代码的过程性单元中,通过逻辑判断、循环等操作,实PL/SQL程序结构v_AccountIDnumber(5):=1001;v_RealNamevarchar(20);selectreal_nameinfov_RealNamefromv_AccountIDnumber(5):=1001;v_RealNamevarchar(20);selectreal_nameinfov_RealNamefromaccountwhereid=v_AccountID;whenon_data_foundinsertinfoFee_Log(desrc)values('Account1001decenotexit!')eg2:打印oWorld opackage(想要在屏幕上输出需要写:setserveroutputon(begin上面写如何调用过程:begin包名.过程名();javaPL/SQL运行过程注释二、变量与数据类型数据类型标量类型数字类型:①number②numberdec(38)、float(38)、③binary_integer(PL/SQL中用10进制赋值,但存的时候会2进制存。优势是计算快。字符类型:①varchar2、varchar(长度:1.~32767)string(PL/SQL中用,长度:1.~32767)③char(长度:1~32767)④longtrue,false③不能将列值保存到boolean变量语法:var_nametypeconstant][not:PL/:PL/SQLv_c1v_d1datesysdate;--sysdatejavaPL/SQL不行!declarev_RealNamedeclarev_RealNameaccount.real_name%type;declaredeclarev_RealNamedeclarev_RealNameaccount.real_name%type;declarev_TempVarnumber(7,3)notnull:=12.3;setsetserveroutputonv_d1date:=sysdate;v_c1varchar2(20);v_c1:=to_char(v_d1,'yyyymmddhh24:mi:ss');dbms_output.put_line('Currentdateis'||三、流程控制语句条件语句ifififendif;//ififendif; endif:注意事项:elseifPL/SQLelsif!v_b1boolean:=false;ifv_b1thenelsifv_b1isnullthenendif; 循环语句exitendexitenddeclarev_indexbinary_integerdeclarev_indexbinary_integer:=1;v_index:=v_index+1;exitwhenv_index>10;endloop;eg210条记录(静态declaredeclarev_indexbinary_integer:=1;insertintotest_changvalues(v_index);v_index:=v_index+1;exitwhenv_index>10;endloop;declarev_indexbinary_integer:=1;dbms_output.put_line('insertintotest_changdeclarev_indexbinary_integer:=1;dbms_output.put_line('insertintotest_changvalues('''||v_index||''')');v_index:=v_index+1;exitwhenv_index>10;endloop;while循环while<booleanexpr>loopwhile<booleanexpr>loop endwhile循环语句中仍然可以使用exit或exitwhendeclarev_indexbinary_integerdeclarev_indexbinary_integer:=1;whilev_index<=10loopv_index:=v_index+1;endeg210条记录(动态declaredeclarev_indexbinary_integer:=1;whilev_index<=10executeimmediate'insertintotest_changvalues('||v_index||')';v_index:=v_index+1;endfor循环(for循环计数器 in下限..上限loopend (for循环计数器 in下限..上限loopend1;使用关键字reverse1③可以使用exit或者exitwhenin、inreverse后面的数字必须是从小到大的顺序,但不一定是整数,nullforiin1..10loopendforiin1..10loopendeg2inreverseforiinreverse1..10loopendendforiinforiin1..10insertintotest_changvalues(i);endloop;四、PL/SQLPL/SQLSQL分类PL/SQLSQLSQL语句PL/SQL编译阶段编译的。效率高。能用静态就不用动态!DML(insertupdate,delete)和TCL(commitinsertinsertintohost(id)values('10.0.0.11');SQL是使用executeimmediate语句来实现的。executeexecuteimmediatecreatetabletest_chang(c1number)';end;--SQLDDL语句executeimmediate'createtabletest_chang(c1number)';insertintotestvalues(1);executeexecuteimmediate'createtabletest_chang(c1number)';executeimmediate'insertintotest_changvalues(1)';(sqlexecuteimmediate'createtabletest_chang(c1number)';foriin1..10loopexecuteimmediateexecuteimmediate'createtabletest_chang(c1number)';foriin1..10loopexecuteimmediate'insertintotest_changvalues('||i||')';endloop;五、PL/SQLselect语句的实现select…into…语句实现(将结果放入到变量中返回“0cursor注意事项:selectintoselect只返回一条记录,才不报错,否则加异常处理(没v_realnameaccount.real_name%type;v_agenumber(3);selectreal_name,round((sysdate-birthdate)/365)//减出的是天数intov_realname,v_agefromwhereid=1005;--v_realnameaccount.real_name%type;v_agenumber(3);selectreal_name,round((sysdate-birthdate)/365)//减出的是天数intov_realname,v_agefromwhereid=1005;--where1=2报错:异常,无数据;换成where1=1dbms_output.put_line(':'|| :'|①若查询结果是单行单列,into子句后用标量类型(标准类型select子句后的目标record类型typet_cost_rectypet_cost_recidrecord(base_costcost.base_cost%type,--t_cost_recunix_costcost.unit_cost%type);v_costt_cost_rec;--v_cost是记录类型的变量v_cost_1typet_account_recisrecord(real_nameagenumber(3),idcard_nov_accountselectreal_name,round((sysdate-birthdate)/365),idcard_nointov_accountfromaccountwhereid=1005;whereid=1005;当使用%rowtype定义记录变量时,record成员的名称和类型与表或视图的列名称和类型 v_cost v_costrecord变量的v_cost.base_costv_cost.base_costv_cost.unit_cost:=0.4;v_cost_1:=v_cost;selectbase_cost,base_duration,unit_costintov_cost_1fromcostwhereidv_costselect*intov_costfromcostwhereid=1;createtablecreatetablecost_t1asselectbase_cost,base_duration,unix_hostfromcostwhereinsert语句和updateinsertintocost_t1valuesv_cost;updateinsertintocost_t1valuesv_cost;updatecost_t1setrow=v_cost_1;typet_account_recisrecord(real_nameaccount.real_name%type,idcard_nochar(18));v_accountt_account_rec;tselectcount(*)tfromaccountwhereidtypet_account_recisrecord(real_nameaccount.real_name%type,idcard_nochar(18));v_accountt_account_rec;tselectcount(*)tfromaccountwhereid t=1selectreal_name,idcard_nointov_accountfromaccountwhereid=1005; endif;cursor的概念select0条或多条用cursorOralce使用专有SQL工作区(privateSQLworkarea)来执行SQL语句,处理信cursorOracleSQL语句都有唯一的cursorPL/SQL的cursorselectcursor的分类隐式:select…into语句、DMLselect语句用显式cursorcursor的处理cursor的属性目的:获取有关显式cursorcursoropen如果前一个fetch如果前一个fetchnull%notfound和%foundnullfetchsqlplus命令:execcursor的属性目的:获取有关隐式cursorDMLtrue,结束后为true表示DML注意事项:sqlsqlinsertintotest_changvalues(100);insertintotest_changvalues(100);updatetest_changsetc1=10wherec1=100;cursor的可以在查询中变量,但必须在cursor语句之前这些变量cursorcursorc_service_id(p_cost_idnumber)isselectidfromservicewherecost_id=p_cost_id;openopencursorselect语句并标识结果集。2)select语句如果没有返回记录,不会出现异常。3)语法:openc_service_id(5);fetch通过循环检测cursorfetchfetchcursor_nameinto[var1,var2,…|record_name];fetchc_service_idintov_service_idfetchintoselectcursorselect0结果集提取的控制使用显式cursorclosecursor一旦关闭,所有和该cursor相关的资源都会被释放,不可再从关闭的cursor中任何对关闭的cursor的操作都会invalid_cursor错误。5)sessioncursoropen_cursor参数决定。6)语法:closec_service_id;cursorc_accountisselectreal_namefromaccountwhere1=1;v_realnamevarchar2(20);fetchc_accountintocursorc_accountisselectreal_namefromaccountwhere1=1;v_realnamevarchar2(20);fetchc_accountintov_realname;exitwhenc_account%notfound;endclosecursorc_accountisselectreal_namefromaccountwhere1=1;v_realnamevarchar2(20);cursorcursorc_accountisselectreal_namefromaccountwhere1=1;v_realnamevarchar2(20);openfetchc_accountintov_realname;ifc_account%notfoundthendbms_output.put_line('noaccount');fetchc_accountintov_realname;exitwhenc_account%notfound;endloop;endif;closecursorcursorc_accountisselectreal_namefromaccountwhere1=1;v_realnamec_account%rowtype;openfetchc_accountintov_realname.real_name;ifc_account%notfoundthendbms_output.put_line('noaccount');cursorc_accountisselectreal_namefromaccountwhere1=1;v_realnamec_account%rowtype;openfetchc_accountintov_realname.real_name;ifc_account%notfoundthendbms_output.put_line('noaccount');fetchc_accountintov_realname.real_name;exitwhenc_account%notfound;endloop;endif;closecursorc_accountisselectreal_name,idcard_nofromcursorc_accountisselectreal_name,idcard_nofromaccountwhere1=1;v_accountc_account%rowtype;openfetchc_accountintov_account;ifc_account%notfoundthendbms_output.put_line('noaccount');whilec_account%founddbms_output.put_line('dbms_output.put_line('姓名: 身份证fetchc_accountintov_account;endloop;endclose会少打记录,loopforiin(selectreal_name,idcard_nofromaccount) foriin(selectreal_name,idcard_nofromaccount) endclose自动把值fetchii的类型是记录类型。cursorcursorc_accountisselectreal_name,idcard_nofromforiinc_account :'||i.real_name||'endloop;cursorc_accountiscursorc_accountisselectreal_name,idcard_nofromaccountwhere1=1;v_accountc_account%rowtype;openfetchc_accountintov_account;ifc_account%notfoundthendbms_output.put_line('noaccount');closeforiinc_accountendloop;endclosecursorcursorc_accountisselectreal_name,idcard_nofromaccountwhere1=1;tbinary_integer:=0;foriinc_accountloopdbms_output.out_line(rpad(i.real_name,12,'')||''||i.idcard_no);t:=end t=0dbms_output.put_line('accountnotexists!');endif;六、集合什么是Nestedtable嵌套表(本课程不讲解什么是关联数组SQL表,可以按主键来检索数据。Associativearrays的定义indexbytypetype_nametypetype_nameistableofelement_type[notindexbydbms_output.put_line('index:'||v_account.last输出排序后的最后一个下标Associativearrays类型和变量eg:类V1V2typeV1V2typeassociative_array_typeistableofnumberindexbyv_accountv_accounttypeistableofv_accountindexby关联数组的操作typetypet_indtabistableofnumberindexbybinary_integer;v_indtabt_indtab;v_indtab(1)v_indtab(5)v_indtab(6)v_indtab(10):=10;Associativearrays的方法exists②在使用count方法前,建议先用existsifcourses.exists(i)thencourses(i):=ifcourses.exists(i)thencourses(i):=new_course;endcount0;ififprojects.count=25thenfirstlast:返回最小和最大下标号,如果collectionnullprior(n)next(n):返回第nnull。5)trim(n)n个元素。6)deletetypetypet_account_idxtabistableofvarchar2(20)--元素的数据类型indexbybinary_integer;--下标的数据类型cursorc_accountisselectid,real_namefromaccount;--idv_accountforiinc_accountv_account(i.id):=i.real_name;v_account(i.id):=i.real_name;end关联数组的遍历declaredeclarebeginforiinv_indtab.first..v_indtab.lastloopendeg2:关联数组的遍历(用while循环typet_account_idxtabistableofvarchar2(20)--元素的数据类型indexbybinary_integer;--下标的数据类型cursorc_accountisselectid,real_namefromaccount;--idv_accountt_account_idxtab;v_indexbinary_integer;foriinc_accountloopv_account(i.id):=i.real_name;endv_indexwhilev_index<=v_account.lastloopendtypet_account_idxtabistabletypet_account_idxtabistableofvarchar2(20)--元素的数据类型indexbybinary_integer;--下标的数据类型cursorc_accountisselectid,real_namefromaccount;--idv_accountforiinc_accountloopv_account(i.id):=i.real_name;endforiinv_account.first..v_account.lastifv_account.exists(i)thenifv_account.exists(i)thenendif;endforwhile循环好(匹配集合中的next()方法Associativearrays的异常typetypenumlististableofnumberindexbybinary_integer;numsnumlist;--nullnums(null):=3;--value_error,没下标,下标不能为空ifnums(1=1thenno_data_found,下标有,但没元素批量绑定bulkcollectloop采用bulkcollect可以将查询结果的加载到collections中selectinto、fetchinto、returningintobulkcollectcollectinto、fetchbulkcollectinto、fetchbulkcollectintolimit10bulkcollectcursorcursorbulkcollectbulkcollect1cursorisv_accountcursorisv_accountopenfetchbulkcollectintov_accountlimit3;closec_account;typetypet_account_recisrecord(real_namevarchar2(20),agebinary_integer);typet_account_idxtabistableoft_account_recindexbybinary_integer;v_accountt_account_idxtab;v_sumbinary_integerselectreal_name,round((sysdate-birthdate)/365)bulkcollect intov_accountfromaccountwhere1=1;ifv_account.count<>0foriinv_account.first..v_account.lastloopv_sum:=v_sum+v_account(i).age; '||rpad(v_account(i).age,4,'')||' endloop;dbms_output.put_line('noaccount');endif;cursorcursorc_accountisselectreal_name,round((sysdate-birthdate)/365)age-- fromtypet_account_indtabistableofc_account%rowtypeindexbybinary_integer;v_accountt_account_indtab;v_culagebinary_integerselectreal_name,round((sysdate-birthdate)/365)agebulkcollectintov_accountfromaccountifv_account.firstisnotnullforiinv_account.first..v_account.lastloopv_culage:=v_culage+v_account(i).age; '||rpad(v_account(i).age,4,'')||' enddbms_output.put_line('noaccount');endif;七、异常Oralce错误XXXXXOralce错误处理机制(eception异常的类型PL/SQL中的异常异常捕获whenexception_name1thenwhenexception_name1thenwhenexception_name2then[whenothers异常的捕获规则Oralce预定义错误的捕获3)invalid_cursor(ORA-1001)cursoropen就使用。4)zero_divide(ORA-1476)0做了除数。8)Oralce预定义错误的捕获selectselect……commit;whenno_date_foundthenwhentoo_many_rowsthenwhenothersthenv_realnameinsertintotest_changvalues(1);insertintotest_changvalues(1);selectreal_nameintov_realnamefromaccountwhere1=1;whenno_data_foundthen--若不接异常,则报错ORA—1403:nodatefounddbms_output.put_line('nodatafound');whentoo_many_rowsthen--ORA—1422:exactfetchreturnsmorethanrequestednumberofrowsdbms_output.put_line('toodbms_output.put_line('toomanyrows');whendup_val_on_indexthenOracle预定义异常将一个经过命名的异常和一个Oracle在语句块的部分一个异常名称:e_integrityexception;2)pragmaexceptoin_init将异常与一个Oracle错误号相关联:3)在异常处理部分捕获并处理异常:whene_integritythene_noparente_noparentpragmaexception_init(e_noparent,-2291);e_childexistexception;deletefromparent_changwherec1=1;insertintochild_changvalues(1,2);whene_noparentthendbms_output.put_line('noparent');whene_childexistthen用户自定义异常throwv_n1number:=101;e_more100exception;ifv_n1>100thenraisev_n1number:=101;e_more100exception;ifv_n1>100thenraiseendif;whene_more100thenv_n1number:=101;e_more100v_n1number:=101;e_more100exception;insertintotestvalues('abc');--异常ifv_n1>100thenraisee_more100;endif;whene_more100thenwhenothers异常处理总结①e_exception在执行过程中当错误产生时抛出与错误对应的异常:raiseexcepname。sqlcode②如果是ORA-1403:nodatafoundwhenwhenno_data_foundthen--若不接异常,则报错ORA—1403:nodatefounddbms_output.put_line('nodatafound');thanrequestednumberofrowsdbms_output.put_line('toomanyrows');①如果是Oracleexceptionv_n1v_n1numbere_more100e_more100insertintotestvalues('abc');--异常ifv_n1>100thenraisee_more100;endif;whene_more100thenwhenothersdbms_output.put_line('a'||sqlcode);--a-1722dbms_output.put_line('a'||sqlerrm);--aORA-01722:无效数字注意事项:insertintolog_tabvalues(sqlcode,sqlerrm,sysdate);sqlerrm中,要赋给一个变量!v_errm异常的 八、子程序子程序1)子程序,即块declarebeginexception有名子程序有名子程序的分类 有名子程序的优点 九、过程语createcreate[or ce]procedureproc_name[(arg_name[{in|out|inout}])type,…<executablestatements><exception创建过createorre ceprocedurecreateorre ceprocedurep_accountno_chang--create出来的都是数据库对象,类procedureselectcount(id)into tfromaccount; selectstatusfromuser_objectswhereobject_name='P_ACCOUNTNO_CHANG';-selecttypefromuser_sourcewherename='P_ACCOUNTNO_CHANG';--查看是哪--createorreceview(procedure)编译不成动,但数据库对象已创建,只不过状invalid形参和实参createcreateor ceprocedureprocchang(p_n1number)--p_n1v_n1number;--v_n1v_n1number:=1;形参的种类inoutinout的组合。在调用过程的时候,实参的值可以被传递给该过程;在injava中八大基本类型+stringinout相当于java中的类型的类似效果out调用过SQLexecexec过程中的参数createorcreateor ceprocedurep_c2outvarchar2,p_c3inoutvarchar2)v_c1varchar2(10);--v_c1--p_c1:=p_c1||'d';--报错,不能作赋值目标。in在调用过程中,形参只可“p_c2p_c2||'d';不报错。p_c3:=p_c3||'d';--只有变量才能作赋值目标v_c2varchar2(20abc';--v_c2v_c2varchar2(20abc';--v_c2varchar2(20);v_c3varchar2(20):='abc'; out返回,d对实际参数的要求模式为inout或out的形参对应的实际参数必须是“变量用于返回的值,所形式参数的限制带参数的过程调用ame(12,p_outparmv_var1,p_inout10);使用缺省参数1)形参可以指明缺省值:parm_namemodetype|defaultinit_valuecreateorre ceprocedurecreateorre ceprocedurepro_chang1(p_c1number,p_c2number,p_c3number,p_c4numberdefault1,p_c5numberdefault1)dbms_output.put_line(p_c1);dbms_output.put_line(p_c2);dbms_output.put_line(p_c3);dbms_output.put_line(p_c4);execpro_chang1(1,2,3);--1,2,3,1,1过程中的DDL语句createorre ceprocedurecreateorre ceprocedureproc1executeimmediate‘createtabletest(c1exectabletable已经好几天了?!1)DBAcreateroleconnect--connect,是缺省创建的createroleresource--另一种角色resourcegrantconnect,resourcetojsd1304;--两种角色给用户1304userrole:enable、disable--用户角色分为:可用和不可用createrolerole1--grantcreatetabletorole1;--tablerole1grantcreateindextorole1;--indexrole1grantcreateviewtorole1;--viewrole1grantrole1tojsd1304;--role1jsd13044)table的原因:用户被授予了一个角色,而角色是可用的connectroleenablepriviledge可用disable,priviledge不可用了,所以解决方法:grantcreatetabletojsd1304;--disableDDL操作,所需的权限必须通过直接授予的方式,不能通②调用过程时,所有角色都是disable的(系统做的③调用其他用户的过程,必须由过程的属主授予执行权限:grantexecuteonametousername;变量或过程中。程序运行结束,该变量也就不存在了。绑定变量(宿主变量PL/SQLSQL中可以直接使用绑定变量:bv_name,即值foriin1..10 immediate'insertintotest_changvalues(:i)'using 则系endloop;variableivariableinumber:iprinti;--1,printexeci=10000--print②declare..begin之间和is..begin之间定义的变量:叫局部变量,块退出,变③fori:i变量不需要,for循环结束,变量不存在PL/SQLSQL分类SQLPL/SQLSQLSQLPL/SQL编译阶段编译的。SQL书写是有规范的,目的是减少硬分析(cpu、内存的耗费代SQL方式,PL/SQL可以使用静态方式(sql已经编译过了,oraclecursorcache,减少软分析的次数)一个session可以打cursor是有限的(参数open_cursor2)动态SQLPL/SQLSQL语句是不确定的,如根据用户输入的参数的不PL/SQL①Oracle在解析SQL时会吧PL/SQL中定义的变量转化为绑定变量,insertintotest_changvalues(i);减少了硬分析次数。②serverprocessSQLcacheSQL时,不需要SQL1次软分析是由于cursorcreateorre ceprocedurecreateorre ceprocedureproc1foriin1..1000insertintotest_changvalues(i);endloop;SQL end;--1次硬分析,1次软分析,1000次执行,静态SQL1析是由于cursorcreateorre cecreateorre ceprocedureproc1foriin1..1000executeimmediate‘insertintotest_changvalues(’||i||‘)’;endloop; end;--1000次硬分析,1000次软分析,1000createorre ceprocedureproc1createorre ceprocedureproc1foriin1..1000executeimmediate‘insertintotest_changvalues(:i)usingi;endloop; SQL end;--1次硬分析,1000次软分析,1000再一次来看SQL语句的处理过程check语义检查(semanticcheck诸如检查SQL语句中的对象是否存在及该用户是(parestree)及执行计划(executereturn软分析和硬分析OraclehashSQLhashlibrarycache里查找是否hash值。SQLcache对过程procedure的基本操作1)创建并编译过程:createorreceprocedure2)编译过程:alter ame删除过程:drop案例createorre ceprocedurepro_chang(p_idnumber,nameoutvarchar2,ageoutnumber)createorre ceprocedurepro_chang(p_idnumber,nameoutvarchar2,ageoutnumber)selectreal_name,round((sysdate-birthdate)/365)intoname,agefromaccountwhereid=p_id;whenno_data_foundthenname:='noaccount';v_realnamevarchar2(20);v_agenumber(3);dbms_output.put_line(v_realname||''||v_age);variablevariableb_realnamevarchar2;variableb_agenumber;printb_realname;printb_age;注意事项:也可使用execpro_chang(1005,:b_realname,:b_age);十、函数语法create[orre ce]create[orre ce]functionfunc_name[(arg_name[{in|out|inout}])type,…)]returntype<localvariabledeclaration>--函数中要用到的局部变量<executablestatements>returnvalue;<exception创建函数createorre cecreateorre cefunctionfun1(p_innumber,p_outoutnumber)returnnumberp_out:=2;return调用函数v_outv_outnumber(3);v_outv_fun1number;--javaPL/SQL中不可以,有传出要定义变v_fun1fun1(10,v_out);--函数不能单独放,函数的调用方式为表达式右边dbms_output.put_line(v_fun1||''||v_out);variablevariableb_outexecdbms_output.put_line(fun1(10,:b_out));printb_out对函数function的基本操作1)创建并编译函数:createorrecefunction2)编译函数:alter ame调用函数用子程调用允许值的位可以调用数用有名程序调DLeect删除函数:drop过程和函数的比较PL/SQL在过程头中不包含必须在函数头中包含return可以包含return必须包含至少一条return块中的过程和函数v_n1numberfunctionfun1(p_innumber)returnnumberreturnprocedureproc1案例createorre cefunctioncreateorre cefunctionfun1(p_c1varchar2,p_c2outvarchar2)returnvarchar2p_c2:=p_c1||'d';returnp_c1;createorre cecreateorre cefunctiongetaccount(p_idnumber,p_ageoutnumber)returnvarchar2Typet_account_recisrecord(real_nameaccount.real_name%type,agenumber(3));v_accountt_account_rec;selectreal_name,round((sysdate-birthdate)/365)intov_accountfromaccountwhereid=p_age:=v_account.age;returnv_account.real_name;whenno_data_foundthenv_account.real_name:='null';returnv_account.real_name;v_agenumber(3);eg2:提供客户IDv_c2varchar2(20);十一、包什么是包的组成过程函数变量游标SQL类型常量异常包的优点package的语createcreateor cepackagepackagebody的语createcreateor cepackagebody编译包和包体alteralterpackagepkg1alterpackagepkg1compile案例createorre cepackagecreateorre cepackagepkg_chang--packagetypet_recisrecord(m1number,m2varchar2(10));v_rect_rec;procedurefunctionfun1(p_innumber)returnnumber;--创建packagecreateorrecepackagebodypkg_changprocedureproc1--在数据库中的package包functionfun1(p_innumber)returnnumberreturnp_in;----v_rec.m1--调用packagepkg_chang.v_rec.m1:=pkg_chang.fun1(10);--
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2025学年度注册公用设备工程师试题预测试卷含答案详解【黄金题型】
- 2024-2025学年度黑龙江旅游职业技术学院单招《语文》真题带答案详解(满分必刷)
- 2024-2025学年度园林绿化作业人员试卷附参考答案详解【巩固】
- 2024-2025学年度计算机四级全真模拟模拟题含答案详解【预热题】
- 2024-2025学年度环卫垃圾处理工测试卷附参考答案详解(培优B卷)
- 2024-2025学年度“安全生产事故隐患排查”知识竞赛真题【各地真题】附答案详解
- 2024-2025学年度燃气职业技能鉴定模拟试题及参考答案详解(满分必刷)
- 2024-2025学年中级软考检测卷及完整答案详解【夺冠系列】
- 2024-2025学年冶金工业技能鉴定考前冲刺练习题审定版附答案详解
- 2024-2025学年度执法资格经典例题【研优卷】附答案详解
- 学校电梯增设施工方案
- 《口腔设备学》课件-第一章 口腔设备认知与发展
- 露地大樱桃主要病虫害绿色防控技术规程
- 《商务谈判与推销实务(第三版)》课件全套 王军华 项目1-12 商务谈判工作认知 -沟通、洽谈语言技巧
- 某EPC项目技术标投标文件
- 煤矿防灭火细则培训
- 科学技术史课件1
- (中职)中职生创新创业能力提升教课件完整版
- 中班健康课件《我不挑食》
- 正方形复习公开课课件(配相关学案)
- 2024年湖北省中考地理·生物试卷(含答案解析)
评论
0/150
提交评论