oracle包怎么写 oracle包的作用
写出oracle中表、存储过程、触发器、包、包体、函数、视图的关键字。
表:table
创新互联是专业的通州网站建设公司,通州接单;提供网站设计制作、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行通州网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
存储过程:procedure
触发器:trigger
包:package
包体:packagebody
函数:function
视图:view
oracle中创建一个包含过程和函数的包
--表create table my_toys( id varchar2(5), name varchar2(20), price number);--插入测试数据insert into my_toys values('G001','电热毯',145);insert into my_toys values('G002','自行车',327);insert into my_toys values('G003','牙膏',14.5);insert into my_toys values('G004','棉被',105);insert into my_toys values('G005','热水瓶',65);insert into my_toys values('G006','拖鞋',22.5); --包规范create or replace package toyspackas procedure UpdateToyPrice; function AvgToyPrice return number;end toyspack; --包主体create or replace package body toyspackas procedure UpdateToyPrice as avgPrice number := AvgToyPrice; begin while (avgPrice = 400) loop --循环更新 update my_toys set price= case when price*1.1500 then price*1.1 else price end; avgPrice := AvgToyPrice; commit; end loop; end UpdateToyPrice; function AvgToyPrice return number as v_avg number; begin select avg(price) into v_avg from my_toys; return v_avg; end AvgToyPrice;end toyspack; --调用execute toyspack.UpdateToyPrice;select toyspack.AvgToyPrice from dual;
请问我用oracle写了一个包,里面有函数和存储过程,我要怎么样能够知道我写的这个包是正确的呢?
验证下不就知道了。
如果你的过程和函数都没有语法错误就是对的。
包:包含表头和BODY信息。
将你的函数和过程头部信息放到包中定义。调用就可以直接调用包里面的定义。
比如:
包:你的包名a.spc
CREATE OR REPLACE PACKAGE a
IS
PROCEDURE CREATE_AE_OUT_FILE (p_gr_hdr_id IN varchar) ;
END;
body:
CREATE OR REPLACE PACKAGE BODY a
IS
PROCEDURE CREATE_AE_OUT_FILE(p_gr_hdr_id IN varchar)
IS
v_gr_hdr_id cosgx.cos_gr_hdr.gr_hdr_id%type;
vfile varchar2(200);
BEGIN
--你的实现逻辑
END;
END;
函数也是一样的。都需要在包里面定义
用SQLPLUS就可以自动生成的
oracle创建包?和存储过程
--创建包头
CREATE OR REPLACE PACKAGE ELS.pkg_proxy
AS
TYPE cursortype IS REF CURSOR;
-- 得到交接确认代理人数据
PROCEDURE get_proxy_info (
v_emp_no IN VARCHAR2, --当前登录用户
v_to_emp_no IN VARCHAR2, --代理人工号
v_to_emp_name IN VARCHAR2, --代理人姓名
v_proxy_date1 IN VARCHAR2, --代理开始时间: yyyy/mm/dd
v_proxy_date2 IN VARCHAR2, --代理结束时间: yyyy/mm/dd
v_from_emp_no IN VARCHAR2, --被代理人工号
v_from_emp_name IN VARCHAR2, --被代理人姓名
p_cursor OUT cursortype
);
END pkg_proxy;
--创建包头
CREATE OR REPLACE PACKAGE BODY ELS.pkg_proxy
AS
-- 得到交接确认代理人数据
PROCEDURE get_proxy_info (
v_emp_no IN VARCHAR2, --当前登录用户
v_to_emp_no IN VARCHAR2, --代理人工号
v_to_emp_name IN VARCHAR2, --代理人姓名
v_proxy_date1 IN VARCHAR2, --代理开始时间: yyyy/mm/dd
v_proxy_date2 IN VARCHAR2, --代理结束时间: yyyy/mm/dd
v_from_emp_no IN VARCHAR2, --被代理人工号
v_from_emp_name IN VARCHAR2, --被代理人姓名
p_cursor OUT cursortype
)
AS
BEGIN
OPEN p_cursor FOR
WITH v AS
(
--查找当前登录人是否为管理员
SELECT *
FROM employee
WHERE dept_id IN (
SELECT ID
FROM department
START WITH ID =
(SELECT dept_id
FROM employee
WHERE emp_no = v_emp_no
AND is_admin IN (
SELECT r_value
FROM role_conditions
WHERE r_key =
'ProxySearch')
UNION
SELECT dept_id
FROM employee_add
WHERE emp_no = v_emp_no
AND is_admin IN (
SELECT r_value
FROM role_conditions
WHERE r_key =
'ProxySearch'))
CONNECT BY PRIOR ID = parent_id)
UNION
SELECT *
FROM employee
WHERE emp_no = v_emp_no)
SELECT DISTINCT *
FROM (SELECT a.currentuser, a.toagrentuser,
DECODE (a.agent_type,
'A', '当前交接确认代理',
'B', '将来离职签核代理',
'C', '当前离职签核代理',
'D', '将来交接确认代理',
''
) agent_type,
a.from_date, a.TO_DATE,
DECODE
(a.to_date1,
'', '无',
TO_CHAR (a.TO_DATE,
'yyyy/mm/dd am hh:mi:ss'
)
) to_date1,
a.flowinfo, b.emp_cname AS currentusername,
b1.emp_cname AS toagrentusername, workitem
FROM (
--当前交接确认代理
SELECT SUBSTR
(x.currentuser,
1,
INSTR (x.currentuser, '(') - 1
) AS currentuser,
SUBSTR
(x.toagrentuser,
1,
INSTR (x.toagrentuser, '(') - 1
) AS toagrentuser,
'A' AS agent_type,
x.create_date AS from_date,
x.create_date AS TO_DATE,
NULL AS to_date1, x.workid,
NULL AS formid, y.NAME workitem,
(SELECT e.emp_no
|| '('
|| e.emp_cname
|| ')'
FROM employee e
WHERE e.emp_no = y.emp_no)
AS flowinfo
FROM currentworkagrent x,
worktransferitem_m y
WHERE x.workid = y.ID
UNION ALL
--将来交接确认代理
SELECT SUBSTR
(currentuser,
1,
INSTR (currentuser, '(') - 1
) AS currentuser,
SUBSTR
(toagrent,
1,
INSTR (toagrent, '(') - 1
) AS toagrent,
'D' AS agent_type, starttime,
endtime, endtime AS to_date1, NULL,
NULL, NULL, NULL
FROM futureagrent) a,
employee b,
employee b1
WHERE a.currentuser = b.emp_no(+)
AND a.toagrentuser = b1.emp_no(+)) a
WHERE currentuser IN (SELECT emp_no
FROM v)
AND (currentuser = v_from_emp_no OR v_from_emp_no IS NULL
)
AND ( currentusername = v_from_emp_name
OR v_from_emp_name IS NULL
)
AND (toagrentuser = v_to_emp_no OR v_to_emp_no IS NULL)
AND ( toagrentusername = v_to_emp_name
OR v_to_emp_name IS NULL
)
AND from_date =
TO_DATE (NVL (v_proxy_date2, '2099/12/31'),
'yyyy/mm/dd'
)
AND TO_DATE =
TO_DATE (NVL (v_proxy_date1, '1000/12/31'),
'yyyy/mm/dd'
)
ORDER BY a.agent_type, a.from_date DESC;
END;
END pkg_proxy;
如何建立oracle包,如何调用包的过程或是函数
包用于在逻辑上组合过程和函数,它由包规范和包体两部分组成
1.创建包
--创建一个包sp_package
create package sp_package is
--声明该包有一个过程和函数,(没有实现)
procedure update_sal(name varchar2,newsal number);
function annual_nicome(name varchar2) return number;
end;
--创建包体(用于实现已经声明的函数和过程)
create package body sp_package is
procedure update_sal(name varchar2,newsal number)
is
BEGIN
UPDATE emp
SET sal = newsal
WHERE ename = name;
END;
function annual_income(name varchar2)
return number is
annual_salary number;
BEGIN
SELECT sal * 12 + Nvl(comm,0)
INTO annual_salary
FROM emp
WHERE ename = name;
RETURN annual_salary;
END;
end;
--调用包中的内容
exec sp_package.update_sal('name',number);
关于oracle的包
调用方法:包名.F_insert_user。
个人认为这个包意义不大,不能提高数据库性能,反而增加了编程时的代码量。
网站名称:oracle包怎么写 oracle包的作用
文章起源:http://pwwzsj.com/article/hpjose.html