insert 语句内的 select 语句

发布于 2024-11-27 18:02:09 字数 242 浏览 3 评论 0原文

我尝试了下面的sql查询

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

当java程序从test.ACT_QUERY表运行这个select语句并假脱机到输出文件时,它给出了“D”,123。我只想要D,123。不知道为什么会出现报价。我需要在 select 语句中替换什么才能获得输出 D,123

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一瞬间的火花 2024-12-04 18:02:09

很难想象你的问题。当然,原则上您所做的事情没有任何问题,并且它可以在 PL/SQL 中工作。

这是您的测试数据,稍作调整以在我的数据库中运行:

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>

让我们开始吧!

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>

因此,您需要通过实际输出的剪切和粘贴来更详细地解释您的情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文