在 SQL Developer 中打印变量的值
我想打印匿名块内特定变量的值。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您需要打开 dbms_output。
在 Oracle SQL Developer 中:
在 SQL*Plus 中:
You need to turn on dbms_output.
In Oracle SQL Developer:
In SQL*Plus:
当您显式打开 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.
使服务器输出首先
SET SERVEROUTPUT on
然后转到 DBMS 输出窗口(查看 -> ) DBMS 输出)
然后按 Ctrl+N 进行连接server
Make server output on First of all
SET SERVEROUTPUT on
thenGo to the DBMS Output window (View->DBMS Output)
then Press Ctrl+N for connecting server
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.
有 2 个选项:
或
打开“查看”菜单并单击“dbms 输出”。您应该在工作表底部看到一个 dbms 输出窗口。然后,您需要添加连接(由于某种原因,这不会自动完成)。
There are 2 options:
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).
我已经添加了第二个光标的关闭。它工作并获得输出以及......
I have added Close of second cursor. It working and getting output as well...
在较新版本的 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.
在菜单中选择 View-->DBMS Output 并
select View-->DBMS Output in menu and
转至 DBMS 输出窗口(查看 -> DBMS 输出)。
Go to the DBMS Output window (View->DBMS Output).