oracle斑竹KingSunSha(弱水三千)的经典存储过程,如何在ASP中调用?

原文中的例子如下:

测试过程:
1、建立测试表
CREATE TABLE student
(
id NUMBER,
name VARCHAR2(30),
sex VARCHAR2(10),
address VARCHAR2(100),
postcode VARCHAR2(10),
birthday DATE,
photo LONG RAW
)
/

2、建立带ref cursor定义的包和包体及函数:
CREATE OR REPLACE
package pkg_test as
/* 定义ref cursor类型
不加return类型,为弱类型,允许动态sql查询,
否则为强类型,无法使用动态sql查询;
*/
type myrctype is ref cursor;

--函数申明
function get(intID number) return myrctype;
end pkg_test;
/

CREATE OR REPLACE
package body pkg_test as
--函数体
function get(intID number) return myrctype is
rc myrctype; --定义ref cursor变量
sqlstr varchar2(500);
begin
if intID=0 then
--静态测试,直接用select语句直接返回结果
open rc for select id,name,sex,address,postcode,birthday from student;
else
--动态sql赋值,用:w_id来申明该变量从外部获得
sqlstr := 'select id,name,sex,address,postcode,birthday from student where id=:w_id';
--动态测试,用sqlstr字符串返回结果,用using关键词传递参数
open rc for sqlstr using intid;
end if;

return rc;
end get;

end pkg_test;
/

---------------------------------------------------------------

'procedure sz_test_standy(p_A IN VARCHAR2,p_OUT OUT VARCHAR2 )
'ASP Server 通过Oracle Client连接DB哦

 1   
 2Set conn = Server.CreateObject("ADODB.Connection")   
 3conn.Open "Provider=MSDAORA.1;User ID=uid;Data Source=TEST;Persist Security Info=False;PASSWORD=psw"   
 4Set cmdTemp=Server.CreateObject("ADODB.Command")   
 5cmdTemp.CommandText="SZ_TEST_STANDY"   
 6cmdTemp.CommandType=4   
 7Set cmdTemp.ActiveConnection=conn   
 8cmdTemp.Parameters("P_A")="TEMP"   
 9cmdTemp.Execute   
10RESPONSE.Write cmdTemp.Parameters("P_OUT")   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus