电脑技术学习

Oracle概念:过程、函数、程序包

dn001

  在规范中声明游标的时候,必须存在与游标关联的return 子句,表示从游标获取的数据元素类型。

  并且游标的select 子句只出现在主体中,不出现在规范中。

  Create or replace package cur_pack is

  Cursor ord_cur return order_master%rowtype;

  Procedure ord_pro (orno varchar2);

  End;

  /

  Create or replace package body cur_pack is

  Cursor ord_cur return order_master%rowtype is

  Select * from order_master;

  Procedure ord_pro (orno varchar2) is

  Or_rec order_master%rowtype;

  Begin

  Open ord_cur;

  Loop

  Fetch ord_cur into or_rec;

  Exit when ord_cur%notfound;

  Dbms_output.put_line(‘Return ’|| or_rec.orderno);

  End loop;

  End ord_pro;

  End cur_pack;

  /

  PRAGMA RESTRICT REFERENCES

  P206

  限定函数的纯度级别

  P197

  WNDS: write no data status

  RNDS: read no data status

  WNPS: write no package status

  RNPS: read no package status

  Create or replace package pack_me is

  Procedure order_proc(orno varchar2);

  Function order_fun (ornos varchar2) return varchar2;

  Pragma restrict_references(order_fun, WNDS,RNDS);

  END;

  /

  数据字典:

  select object_name, object_type

  from user_objects

  where object_type in (‘PROCEDURE’,’FUNCTION’,’PACKAGE’,’PACKAGE BODY’);

  查看用户代码:

  desc user_source

  select text from user_source where name=’INSERT_INTO_T’ order by line;

  desc employee_pkg

  包装工具:

  将utilities包的主体部分保存在utilities.sql文件中,通过wrap工具加密,只生成oracle认识的格式,保护智力成果

  wrap iname=utilities.sql

  生成utilities.plb

  规范部分:

  create or replace package utilities as

  procedure swap(p1 in out number, p2 in out number);

  procedure swap(p1 in out varchar2,p2 in out varchar2);

  procedure swap(p1 in out date,p2 in out date);

  end utilities;

  /

  select text from user_source where name='UTILITIES';
;

标签: 函数