在 SQL Developer 中打印变量的值

2021-12-05 00:00:00 oracle plsql oracle-sqldeveloper

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

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.

推荐答案

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

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

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

在 SQL*Plus 中:

In SQL*Plus:

 SET SERVEROUTPUT ON

相关文章