如何使用COMPARISON_TYPE returnType和布尔输入调用cx_Oracle中的Function?

时间:2018-10-11 23:08:25

标签: python database oracle plsql cx-oracle

我正在尝试从COMPARE function呼叫DBMS_COMPARISON package

我首先通过

创建我的比较
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.1.4

现在我要调用函数import cx_Oracle host = host service_name = service_name port = port password = password username = username dsn = cx_Oracle.makedsn( host, port, service_name=service_name ) db = cx_Oracle.connect(username, password, dsn ) keyword_parameters = { 'comparison_name':'my_comparison', 'schema_name':'my_schema', 'object_name':'table_name', 'dblink_name':'db_link' } cur.callproc('DBMS_COMPARISON.CREATE_COMPARISON', keywordParameters = keyword_parameters)

DBMS_COMPARISON.COMPARE

我尝试过

DBMS_COMPARISON.COMPARE(
   comparison_name  IN   VARCHAR2,
   scan_info        OUT  COMPARISON_TYPE,
   min_value        IN   VARCHAR2   DEFAULT NULL,
   max_value        IN   VARCHAR2   DEFAULT NULL,
   perform_row_dif  IN   BOOLEAN    DEFAULT FALSE)
RETURN BOOLEAN;

或的某些变体。我在理解如何设置callfunc中指定的cur.callfunc('DBMS_COMPARISON.COMPARE', int, keywordParameters={'comparison_name':'my_comparison', 'scan_info':cur.var(int), 'perform_row_dif':'TRUE'}) 以及如何设置returnType函数调用所需的布尔值方面遇到困难

1 个答案:

答案 0 :(得分:0)

无论如何,这是一个对我有用的简单示例!关键是将“布尔”类型传递给对cursor.callfunc()的调用。

create function IsNumber (a_Value varchar2) return boolean is
    t_Value number;
begin
    begin
        t_Value := to_number(a_Value);
        return true;
    exception
    when others then
        return false;
    end;
end;
/

等效的Python代码如下:

print(cursor.callfunc("IsNumber", bool, ("5",)))
print(cursor.callfunc("IsNumber", bool, ("Fred",)))

这将输出值

真实 错误