开发者

select statement inside a insert statement

开发者 https://www.devze.com 2023-03-25 15:19 出处:网络
I tried the below sql query INSERT INTO test.ACT_QUERY values(2139,2,\'SELECT \'\'D\'\',ORDER_ID from dual\');

I tried the below sql query

INSERT INTO test.ACT_QUERY values(2139,2,'SELECT ''D'',ORDER_ID from dual');

When a java program run this select statement from test.ACT_QUERY table and spools to a output file it gives开发者_如何学编程 a "D", 123. I just want D,123. Not sure why the quotes are coming up. What i need to replace in the select statement to get the output as D,123


It is difficult to visualize your problem. Certainly there is nothing wrong in principle with what you're doing, and it works in PL/SQL.

Here is your test data, slightly tweaked to run in my DB:

SQL> INSERT INTO ACT_QUERY values(2139,2,'SELECT ''D'', DUMMY from dual');

1 row created.

SQL> select * from act_query
  2  /

        ID       BLAH
---------- ----------
QRY_TXT
--------------------------------------------------------------------------------
      2139          2
SELECT 'D', DUMMY from dual


SQL>

Let's roll!

SQL> begin
  2      for r in (select * from
  3
  4  .
SQL> declare
  2      v1 char(1);
  3      v2 char(1);
  4  begin
  5      for r in (select * from act_query)
  6      loop
  7          execute immediate r.qry_txt into v1, v2;
  8          dbms_output.put_line(r.qry_txt);
  9          dbms_output.put_line('v1='||v1||'::v2='||v2);
 10      end loop;
 11  end;
 12  /
SELECT 'D'as D, DUMMY from dual
v1=D::v2=X

PL/SQL procedure successfully completed.

SQL>

So, you need to explain your situation in a bit more detail, with cut'n'paste of actual output.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号