plsql dbms\u hs\u passthrough.execute\u使用变量参数时立即出错

p3rjfoxz  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(225)

我有一个连接到mysql的dblink叫做 times .
我有一个表名 test_tblOOHA_Master 只有一条记录(见下图)。

我的代码:

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;        
/

当我运行代码时,出现以下错误:

这部分是我得到错误的地方:

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 ,我出错了。但是当使用直接字符串值时,它是有效的。
我的变量怎么了?请帮忙。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题