oracle包怎么写 oracle怎么创建包

如何建立oracle包,如何调用包的过程或是函数包用于在逻辑上组合过程和函数oracle包怎么写,它由包规范和包体两部分组成
1.创建包
--创建一个包sp_package
create package sp_package is
--声明该包有一个过程和函数oracle包怎么写,(没有实现)
procedure update_sal(name varchar2,newsal number);
function annual_nicome(name varchar2) return number;
end;
--创建包体(用于实现已经声明oracle包怎么写的函数和过程)
create package body sp_package is
procedure update_sal(name varchar2,newsal number)
is
BEGIN
UPDATE emp
SETsal = newsal
WHEREename = name;
END;
function annual_income(name varchar2)
return number is
annual_salary number;
BEGIN
SELECT sal * 12Nvl(comm,0)
INTOannual_salary
FROMemp
WHEREename = name;
RETURN annual_salary;
END;
end;
--调用包中oracle包怎么写的内容
exec sp_package.update_sal('name',number);
请问我用oracle写了一个包,里面有函数和存储过程,我要怎么样能够知道我写的这个包是正确的呢?验证下不就知道了 。
如果你的过程和函数都没有语法错误就是对的 。
包:包含表头和BODY信息 。
将你的函数和过程头部信息放到包中定义 。调用就可以直接调用包里面的定义 。
比如:
包:你的包名a.spc
CREATE OR REPLACE PACKAGE a
IS
PROCEDURECREATE_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_idcosgx.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_noINVARCHAR2,--当前登录用户
v_to_emp_noINVARCHAR2,--代理人工号
v_to_emp_nameINVARCHAR2,--代理人姓名
v_proxy_date1INVARCHAR2,--代理开始时间: yyyy/mm/dd
v_proxy_date2INVARCHAR2,--代理结束时间: yyyy/mm/dd
v_from_emp_noINVARCHAR2,--被代理人工号
v_from_emp_nameINVARCHAR2,--被代理人姓名
p_cursorOUTcursortype
);
END pkg_proxy;
--创建包头
CREATE OR REPLACE PACKAGE BODY ELS.pkg_proxy
AS
-- 得到交接确认代理人数据
PROCEDURE get_proxy_info (
v_emp_noINVARCHAR2,--当前登录用户
v_to_emp_noINVARCHAR2,--代理人工号
v_to_emp_nameINVARCHAR2,--代理人姓名
v_proxy_date1INVARCHAR2,--代理开始时间: yyyy/mm/dd
v_proxy_date2INVARCHAR2,--代理结束时间: yyyy/mm/dd
v_from_emp_noINVARCHAR2,--被代理人工号
v_from_emp_nameINVARCHAR2,--被代理人姓名
p_cursorOUTcursortype
)
AS
BEGIN
OPEN p_cursor FOR
WITH v AS
(
--查找当前登录人是否为管理员
SELECT *
FROM employee
WHERE dept_id IN (
SELECTID
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
【oracle包怎么写 oracle怎么创建包】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,
(SELECTe.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包怎么写的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于oracle怎么创建包、oracle包怎么写的信息别忘了在本站进行查找喔 。

    推荐阅读