在 SQL Developer 中打印变量的值

发布于 2024-12-11 12:19:57 字数 1068 浏览 0 评论 0原文

我想打印匿名块内特定变量的值。我正在使用 Oracle SQL Developer。我尝试使用dbms_output.put_line。但它不起作用。我正在使用的代码如下所示。

SET SERVEROUTPUT ON

DECLARE

  CTABLE USER_OBJECTS.OBJECT_NAME%TYPE;
  CCOLUMN ALL_TAB_COLS.COLUMN_NAME%TYPE;
  V_ALL_COLS VARCHAR2(500);

  CURSOR CURSOR_TABLE
    IS
    SELECT OBJECT_NAME 
    FROM USER_OBJECTS 
    WHERE OBJECT_TYPE='TABLE'
    AND OBJECT_NAME LIKE 'tb_prm_%';

  CURSOR CURSOR_COLUMNS (V_TABLE_NAME IN VARCHAR2)
    IS
    SELECT COLUMN_NAME
    FROM ALL_TAB_COLS
    WHERE TABLE_NAME = V_TABLE_NAME;

BEGIN

  OPEN CURSOR_TABLE;

  LOOP
    FETCH CURSOR_TABLE INTO CTABLE;
    EXIT WHEN CURSOR_TABLE%NOTFOUND;

    OPEN CURSOR_COLUMNS (CTABLE);

    V_ALL_COLS := NULL;

    LOOP
      FETCH CURSOR_COLUMNS INTO CCOLUMN;
      V_ALL_COLS := V_ALL_COLS || CCOLUMN;
      IF CURSOR_COLUMNS%FOUND THEN
        V_ALL_COLS := V_ALL_COLS || ', ';
      ELSE
        EXIT;
      END IF;
    END LOOP;

    DBMS_OUTPUT.PUT_LINE(V_ALL_COLS);

  END LOOP;
  CLOSE CURSOR_TABLE;

END;

我仅在匿名块完成时获得输出。

I wanted to print the value of a particular variable which is inside an anonymous block. I am using Oracle SQL Developer. I tried using dbms_output.put_line. But it is not working. The code which I am using is shown below.

SET SERVEROUTPUT ON

DECLARE

  CTABLE USER_OBJECTS.OBJECT_NAME%TYPE;
  CCOLUMN ALL_TAB_COLS.COLUMN_NAME%TYPE;
  V_ALL_COLS VARCHAR2(500);

  CURSOR CURSOR_TABLE
    IS
    SELECT OBJECT_NAME 
    FROM USER_OBJECTS 
    WHERE OBJECT_TYPE='TABLE'
    AND OBJECT_NAME LIKE 'tb_prm_%';

  CURSOR CURSOR_COLUMNS (V_TABLE_NAME IN VARCHAR2)
    IS
    SELECT COLUMN_NAME
    FROM ALL_TAB_COLS
    WHERE TABLE_NAME = V_TABLE_NAME;

BEGIN

  OPEN CURSOR_TABLE;

  LOOP
    FETCH CURSOR_TABLE INTO CTABLE;
    EXIT WHEN CURSOR_TABLE%NOTFOUND;

    OPEN CURSOR_COLUMNS (CTABLE);

    V_ALL_COLS := NULL;

    LOOP
      FETCH CURSOR_COLUMNS INTO CCOLUMN;
      V_ALL_COLS := V_ALL_COLS || CCOLUMN;
      IF CURSOR_COLUMNS%FOUND THEN
        V_ALL_COLS := V_ALL_COLS || ', ';
      ELSE
        EXIT;
      END IF;
    END LOOP;

    DBMS_OUTPUT.PUT_LINE(V_ALL_COLS);

  END LOOP;
  CLOSE CURSOR_TABLE;

END;

And I am getting the output only as anonymous block completed.

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

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

发布评论

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

评论(9

司马昭之心 2024-12-18 12:19:57

您需要打开 dbms_output。
在 Oracle SQL Developer 中:

  1. 显示 DBMS 输出窗口(查看 -> DBMS 输出)。
  2. 按 Dbms Output 窗口顶部的“+”按钮,然后在打开的对话框中选择一个打开的数据库连接。

在 SQL*Plus 中:

 SET SERVEROUTPUT ON

You need to turn on dbms_output.
In Oracle SQL Developer:

  1. Show the DBMS Output window (View->DBMS Output).
  2. Press the "+" button at the top of the Dbms Output window and then select an open database connection in the dialog that opens.

In SQL*Plus:

 SET SERVEROUTPUT ON
红墙和绿瓦 2024-12-18 12:19:57

当您显式打开 DBMS_OUTPUT 窗口窗格时,SQL Developer 似乎仅输出 DBMS_OUTPUT 文本。

转到(菜单)查看 -> Dbms_output 调用窗格。

单击绿色加号以启用连接的输出,然后运行代码。

编辑:不要忘记根据您期望的输出量设置缓冲区大小。

SQL Developer seems to only output the DBMS_OUTPUT text when you have explicitly turned on the DBMS_OUTPUT window pane.

Go to (Menu) VIEW -> Dbms_output to invoke the pane.

Click on the Green Plus sign to enable output for your connection and then run the code.

EDIT: Don't forget to set the buffer size according to the amount of output you are expecting.

故事与诗 2024-12-18 12:19:57

使服务器输出首先

  1. SET SERVEROUTPUT on 然后

  2. 转到 DBMS 输出窗口(查看 -> ) DBMS 输出)

  3. 然后按 Ctrl+N 进行连接server

Make server output on First of all

  1. SET SERVEROUTPUT on then

  2. Go to the DBMS Output window (View->DBMS Output)

  3. then Press Ctrl+N for connecting server

沐歌 2024-12-18 12:19:57

1 ) 进入查看菜单。
2)选择DBMS_OUTPUT菜单项。
3 ) 按 Ctrl + N 并选择连接编辑器。
4 ) 执行 SET SERVEROUTPUT ON 命令。
5 ) 然后执行您的 PL/SQL 脚本。

输入图像描述这里
输入图像描述这里

1 ) Go to view menu.
2 ) Select the DBMS_OUTPUT menu item.
3 ) Press Ctrl + N and select connection editor.
4 ) Execute the SET SERVEROUTPUT ON Command.
5 ) Then execute your PL/SQL Script.

enter image description here
enter image description here

╄→承喏 2024-12-18 12:19:57

有 2 个选项:

set serveroutput on format wrapped;

打开“查看”菜单并单击“dbms 输出”。您应该在工作表底部看到一个 dbms 输出窗口。然后,您需要添加连接(由于某种原因,这不会自动完成)。

There are 2 options:

set serveroutput on format wrapped;

or

Open the 'view' menu and click on 'dbms output'. You should get a dbms output window at the bottom of the worksheet. You then need to add the connection (for some reason this is not done automatically).

栖竹 2024-12-18 12:19:57
DECLARE

  CTABLE USER_OBJECTS.OBJECT_NAME%TYPE;
  CCOLUMN ALL_TAB_COLS.COLUMN_NAME%TYPE;
  V_ALL_COLS VARCHAR2(5000);

  CURSOR CURSOR_TABLE
    IS
    SELECT OBJECT_NAME 
    FROM USER_OBJECTS 
    WHERE OBJECT_TYPE='TABLE'
    AND OBJECT_NAME LIKE 'STG%';

  CURSOR CURSOR_COLUMNS (V_TABLE_NAME IN VARCHAR2)
    IS
    SELECT COLUMN_NAME
    FROM ALL_TAB_COLS
    WHERE TABLE_NAME = V_TABLE_NAME;

BEGIN

  OPEN CURSOR_TABLE;
  LOOP
    FETCH CURSOR_TABLE INTO CTABLE;

    OPEN CURSOR_COLUMNS (CTABLE);
    V_ALL_COLS := NULL;
    LOOP

      FETCH CURSOR_COLUMNS INTO CCOLUMN;
      V_ALL_COLS := V_ALL_COLS || CCOLUMN;
      IF CURSOR_COLUMNS%FOUND THEN
        V_ALL_COLS := V_ALL_COLS || ', ';
      ELSE
        EXIT;
      END IF;
    END LOOP;
   close CURSOR_COLUMNS ;
    DBMS_OUTPUT.PUT_LINE(V_ALL_COLS);
    EXIT WHEN CURSOR_TABLE%NOTFOUND;
  END LOOP;`enter code here`
  CLOSE CURSOR_TABLE;

END;

我已经添加了第二个光标的关闭。它工作并获得输出以及......

DECLARE

  CTABLE USER_OBJECTS.OBJECT_NAME%TYPE;
  CCOLUMN ALL_TAB_COLS.COLUMN_NAME%TYPE;
  V_ALL_COLS VARCHAR2(5000);

  CURSOR CURSOR_TABLE
    IS
    SELECT OBJECT_NAME 
    FROM USER_OBJECTS 
    WHERE OBJECT_TYPE='TABLE'
    AND OBJECT_NAME LIKE 'STG%';

  CURSOR CURSOR_COLUMNS (V_TABLE_NAME IN VARCHAR2)
    IS
    SELECT COLUMN_NAME
    FROM ALL_TAB_COLS
    WHERE TABLE_NAME = V_TABLE_NAME;

BEGIN

  OPEN CURSOR_TABLE;
  LOOP
    FETCH CURSOR_TABLE INTO CTABLE;

    OPEN CURSOR_COLUMNS (CTABLE);
    V_ALL_COLS := NULL;
    LOOP

      FETCH CURSOR_COLUMNS INTO CCOLUMN;
      V_ALL_COLS := V_ALL_COLS || CCOLUMN;
      IF CURSOR_COLUMNS%FOUND THEN
        V_ALL_COLS := V_ALL_COLS || ', ';
      ELSE
        EXIT;
      END IF;
    END LOOP;
   close CURSOR_COLUMNS ;
    DBMS_OUTPUT.PUT_LINE(V_ALL_COLS);
    EXIT WHEN CURSOR_TABLE%NOTFOUND;
  END LOOP;`enter code here`
  CLOSE CURSOR_TABLE;

END;

I have added Close of second cursor. It working and getting output as well...

离鸿 2024-12-18 12:19:57

在较新版本的 SQL Developer 中,不再需要显示单独的输出视图,而是始终以选项卡的形式存在。在选项卡列表(SQL 开发人员称之为“窗口”,例如两个 SQL 输入区域)下方,还有另一个选项卡列表,称为“SQL”、“输出”和“统计”。输出不会自动打开,您需要单击选项卡。

In newer versions of SQL developer, there is no more separate output view that you need to show, instead it's always there, as a tab. Below your list of tabs (which SQL developer calls "windows", so for example two SQL input areas), there is another list of tabs, called "SQL", "Output" and "Statistics". The output will not open automatically, you need to click on the tab.

做个少女永远怀春 2024-12-18 12:19:57

在菜单中选择 View-->DBMS Output 并

select View-->DBMS Output in menu and

甜嗑 2024-12-18 12:19:57

转至 DBMS 输出窗口(查看 -> DBMS 输出)。

Go to the DBMS Output window (View->DBMS Output).

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