调用存储的proc,其中输入是用户定义的数据类型 - 使用python

发布于 2025-02-06 03:06:37 字数 699 浏览 1 评论 0原文

这是Oracle PLSQL代码:

create or replace TYPE EMP_TYP IS OBJECT (
  EMP_ID VARCHAR2(36), EMP_NAM  VARCHAR2(50)
)
--
create or replace TYPE EMP_TAB IS TABLE OF EMP_TYP
--
create or replace PACKAGE BODY EMP_NEW_PKG
IS PROCEDURE EMP_INSERT_PROC (new_record     EMP_TAB) IS
BEGIN
INSERT INTO EMPLOYEE_MAIN_TABLE ( EMP_ID, EMP_NAM ) 
SELECT EMP_ID, EMP_NAM FROM TABLE ( new_record ) ;
COMMIT;
END;

如何使用Python调用此存储的Proc?

我尝试了Python代码,

args = [ '12345' , 'Rajan']
cursor.callproc('EMP_NEW_PKG.EMP_INSERT_PROC', args)

Getting Error as :
PLS-00306 : wrong number or types of argument in call EMP_NEW_PKG.EMP_INSERT_PROC.

请帮助代码段 /相关参考。

This is Oracle PLSQL Code :

create or replace TYPE EMP_TYP IS OBJECT (
  EMP_ID VARCHAR2(36), EMP_NAM  VARCHAR2(50)
)
--
create or replace TYPE EMP_TAB IS TABLE OF EMP_TYP
--
create or replace PACKAGE BODY EMP_NEW_PKG
IS PROCEDURE EMP_INSERT_PROC (new_record     EMP_TAB) IS
BEGIN
INSERT INTO EMPLOYEE_MAIN_TABLE ( EMP_ID, EMP_NAM ) 
SELECT EMP_ID, EMP_NAM FROM TABLE ( new_record ) ;
COMMIT;
END;

How can I call this Stored Proc using Python ?

I tried Python Code,

args = [ '12345' , 'Rajan']
cursor.callproc('EMP_NEW_PKG.EMP_INSERT_PROC', args)

Getting Error as :
PLS-00306 : wrong number or types of argument in call EMP_NEW_PKG.EMP_INSERT_PROC.

Please help with code snippet / relevent reference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐籹人 2025-02-13 03:06:39

您必须创建一个数据库对象并将其传递到存储过程。这样的东西(未经测试):

emp_type_obj = connection.gettype("EMP_TYP")
emp_obj = emp_type_obj.newobject()
emp_obj.EMP_ID = "12345"
emp_obj.EMP_NAM = "Rajan"

emp_tab_type_obj = connection.gettype("EMP_TAB")
emp_tab_obj = emp_tab_type_obj.newobject()
emp_tab_obj.append(emp_obj)

cursor.callproc("EMP_NEW_PKG.EMP_INSERT_PROC", [emp_tab_obj])

You have to create a database object and pass that through to the stored procedure. Something like this (untested):

emp_type_obj = connection.gettype("EMP_TYP")
emp_obj = emp_type_obj.newobject()
emp_obj.EMP_ID = "12345"
emp_obj.EMP_NAM = "Rajan"

emp_tab_type_obj = connection.gettype("EMP_TAB")
emp_tab_obj = emp_tab_type_obj.newobject()
emp_tab_obj.append(emp_obj)

cursor.callproc("EMP_NEW_PKG.EMP_INSERT_PROC", [emp_tab_obj])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文