Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 我想把动态查询从update语句写到merge语句_Oracle_Plsql_Dynamic Sql - Fatal编程技术网

Oracle 我想把动态查询从update语句写到merge语句

Oracle 我想把动态查询从update语句写到merge语句,oracle,plsql,dynamic-sql,Oracle,Plsql,Dynamic Sql,我想把动态查询从update语句写到merge语句 'UPDATE ' || T1_TABLENAME || ' t1 ' || 'SET ( ' || v_t1_fields || ' ) = (SELECT ' || v_t2_fields || ' FROM ' || T2_TEMPTABLE_NAME || ' tmp WHERE ' || v_con || ' ) ' || ' WHERE EXIS

我想把动态查询从update语句写到merge语句

    'UPDATE ' || T1_TABLENAME || ' t1 ' || 'SET ( ' ||
             v_t1_fields || ' ) =  (SELECT ' || v_t2_fields || ' FROM ' ||
             T2_TEMPTABLE_NAME || ' tmp WHERE ' || v_con || ' ) ' ||
             ' WHERE EXISTS ( SELECT 1 FROM ' ||  T2_TEMPTABLE_NAME ||
             ' tmp WHERE ' || v_con || ' )';

           --  HERE v_con = t1.D=t2.D,
               v_t1_fields-it can store dynamically-A,B,C
               v_t2_fields-it can store dynamically-A,B,C

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

    MERGE INTO TABLE1 t1
USING TABLE2 t2 
ON(t1.D=t2.D)
WHEN MATCHED THEN
  UPDATE 
   SET 
   t1.A=t2.A,
   t1.B=t2.B,  //update set (t1.A,t1.B,t1.C =t2.A,t2.B,t2.C) not work 
   t1.C=t2.C;


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

    'MERGE INTO ' TABLE1 || ' t1 ' ||
' USING ' TABLE2 || ' t2 ' ||
' ON ( '  || v_cons || ' )   
 when matched then update set ('
  || v_t1_fields || ') = '( || v_t2_fields || ' );'  // Its not work--ORA-01747: invalid user.table.column, table.column, or column specification
然后我使用reg_exp分割列

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

    v_Sql :=  'MERGE INTO ' TABLE1 || ' t1 ' ||
' USING ' TABLE2 || ' t2 ' ||
' ON ( '  || v_cons || ' )   
 when matched then update set ('
                ( ' || regexp_substr(v_t1_fields, '[^,]+', 1, 1) || ' ) = ( ' || regexp_substr(v_t2_fields, '[^,]+', 1, 1) || ' )
                ( ' || regexp_substr(v_t1_fields, '[^,]+', 1, 2) || ' ) = ( ' || regexp_substr(v_t2_fields, '[^,]+', 1, 2) || ' )
                ( ' || regexp_substr(v_t1_fields, '[^,]+', 1,3)  || ' ) = ( ' || regexp_substr(v_t2_fields, '[^,]+', 1,3) || ' ) ';
这一个也不起作用——ORA-01747:无效的user.table.column、table.column或column规范 动态更新到动态合并 在使用update语句更改merge时
不起作用

在连接和使用
MERGE
语句时几乎没有错误

尝试以下动态查询:

     'MERGE INTO '
     || TABLE1
     || ' t1 '
     || ' USING '
     || TABLE2
     || ' t2 '
     || ' ON ( '
     || V_CONS
     || ' ) when matched then update set '
     || REGEXP_SUBSTR(V_T1_FIELDS, '[^,]+', 1, 1)
     || ' = '
     || REGEXP_SUBSTR(V_T2_FIELDS, '[^,]+', 1, 1)
     || ', '
     || REGEXP_SUBSTR(V_T1_FIELDS, '[^,]+', 1, 2)
     || ' = '
     || REGEXP_SUBSTR(V_T2_FIELDS, '[^,]+', 1, 2)
     || ', '
     || REGEXP_SUBSTR(V_T1_FIELDS, '[^,]+', 1, 3)
     || ' = '
     || REGEXP_SUBSTR(V_T2_FIELDS, '[^,]+', 1, 3);
我假设

  • TABLE1
    TABLE2
    是有效的表名
  • V_CONS
    是表上的有效条件
  • V_T1_字段
    V_T2_字段
    包含表的有效列名

干杯

似乎是concatation语法中的一个错误-不应该将“MERGE-INTO”TABLE1 | |“t1”改为“MERGE-INTO”TABLE1 | | |“t1”-在TABLE1之前添加一个concat运算符,为什么要这样做?听起来像是一个糟糕的应用程序设计方法。为了提高性能,更新10万条记录需要10分钟。所以我尝试使用merge