4

just want to get an idea if this is the correct way to do an EXECUTE IMMEDIATE with multiple columns and lines and assigning it to a variable? I tried looking at examples but am not sure if I am concatenating the lines correctly?

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 に答える