oracle的包怎么写,oracle创建包和包体
oracle创建包?和存储过程
--创建包头
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比郏县网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式郏县网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖郏县地区。费用合理售后完善,10多年实体公司更值得信赖。
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写了一个包,里面有函数和存储过程,我要怎么样能够知道我写的这个包是正确的呢?
验证下不就知道了。
如果你的过程和函数都没有语法错误就是对的。
包:包含表头和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的包怎么写,oracle创建包和包体
本文URL:http://ybzwz.com/article/dscdooh.html