4

只是想知道这是否是使用多列和多行执行 EXECUTE IMMEDIATE 并将其分配给变量的正确方法?我尝试查看示例,但不确定我是否正确连接了这些行?

sql_stmt        VARCHAR2(200);

sql_stmt:='INSERT INTO (STORECODE, TILLID, TRANSACTIONNR, TRADINGDATE, TRANSTYPE, ' ||
          'OPERATORCODE TRAININGMODE, VOIDED, VALUEGROSS, VALUENETT, VALUEDUE) ' ||
          ‘VALUES (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10)’;
          EXECUTE IMMEDIATE sql_stmt USING sSTORECODE………………………………………..fGROSS_AMOUNT,
      ‘0’;   
4

2 回答 2

11

Oracle 中的字符串可以是多行的。因此,您可以简单地编写:

sql_stmt := 'INSERT INTO (STORECODE, TILLID, TRANSACTIONNR, TRADINGDATE, 
                          TRANSTYPE, OPERATORCODE TRAININGMODE, VOIDED, 
                          VALUEGROSS, VALUENETT, VALUEDUE) 
                  VALUES (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10)';

EXECUTE IMMEDIATE sql_stmt USING p1, p2... p10;

当然,使用连接 ( ||) 和几个子字符串也可以。

于 2013-01-18T15:47:14.393 回答
2
set serveroutput on size unlimited;

declare
str_   varchar(1000 char);
date_ date;


begin
  --str_ := 'select sysdate' || chr(10);
  --str_ := str_ || 'from dual';
  str_ := 'select sysdate /* ''comment'' */
           from dual';

  execute immediate str_
  into date_;

  dbms_output.put_line(date_);


end;
于 2013-04-02T21:42:35.793 回答