使用可变参数时的PLSQL DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE错误

时间:2018-10-24 04:01:36

标签: mysql oracle pass-through

我有一个连接到mysql的dblink,名为times

我有一个表名test_tblOOHA_Master,其中有一条记录(请参见下图)。

enter image description here

我的代码:

DECLARE 
    num_rows INTEGER;
    v_cursor   BINARY_INTEGER;
    nr INTEGER;

    -- BINDING VARIABLES            
    header_id INTEGER; 
    flow_status_code VARCHAR(500); 
    qry VARCHAR(5000) ;

PROCEDURE test 
AS
qry_select VARCHAR2(10000) := 'select
                t1.header_id 
                ,t1.flow_status_code 
            from  test_tblOOHA_Master t1;'; 
BEGIN
    v_cursor := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@times;
    DBMS_HS_PASSTHROUGH.PARSE@times(v_cursor,qry_select);
     WHILE DBMS_HS_PASSTHROUGH.FETCH_ROW@times(v_cursor) > 0
        LOOP 
        DBMS_HS_PASSTHROUGH.GET_VALUE@times(v_cursor,1,header_id); 
        DBMS_HS_PASSTHROUGH.GET_VALUE@times(v_cursor,2,flow_status_code); 

        qry  := 'UPDATE test_tblOOHA_Master  
                set  flow_status_code= "'|| flow_status_code ||'"
                where  header_id = '|| header_id ||' ;  ';

        dbms_output.put_line(qry);      
         /*
        qry variable generated the ff. string

        UPDATE test_tblOOHA_Master  
                set  flow_status_code= "TEST"
                where  header_id = 1603823 ;
       */

       num_rows := DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@times (qry); -- When I stored the string to a variable, It throws and error

       num_rows := DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@times (
                'UPDATE test_tblOOHA_Master  
                set  flow_status_code= "TEST"
                where  header_id = 1603823 ;'); -- But when I run the string directly, it works fine
    END LOOP;
  DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@times(v_cursor);
END test;

BEGIN
 test;
 COMMIT;
END;        
/

运行代码时出现此错误:

enter image description here

这是我出错的地方:

 num_rows := DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@times (qry); -- When I stored the string to a variable, It throws and error

但是直接运行字符串时,它可以正常工作。

num_rows := DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@times (
                'UPDATE test_tblOOHA_Master  
                set  flow_status_code= "TEST"
                where  header_id = 1603823 ;'); -- But when I run the string directly, it works fine

摘要: 使用变量qry时出现错误。但是当使用直接字符串值时,它可以工作。

我的变量出了什么问题?请帮忙。

0 个答案:

没有答案