oracle 在 SQL Developer 中打印变量的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7887413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Printing the value of a variable in SQL Developer
提问by 988875
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.
我想打印匿名块内特定变量的值。我正在使用 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;
And I am getting the output only as anonymous block completed
.
我得到的输出仅作为anonymous block completed
.
回答by Klas Lindb?ck
You need to turn on dbms_output. In Oracle SQL Developer:
您需要打开 dbms_output。在 Oracle SQL Developer 中:
- Show the DBMS Output window (View->DBMS Output).
- Press the "+" button at the top of the Dbms Output window and then select an open database connection in the dialog that opens.
- 显示 DBMS 输出窗口(视图->DBMS 输出)。
- 按 Dbms 输出窗口顶部的“+”按钮,然后在打开的对话框中选择一个打开的数据库连接。
In SQL*Plus:
在 SQL*Plus 中:
SET SERVEROUTPUT ON
回答by Ollie
SQL Developer seems to only output the DBMS_OUTPUT text when you have explicitly turned on the DBMS_OUTPUT window pane.
当您显式打开 DBMS_OUTPUT 窗口窗格时,SQL Developer 似乎只输出 DBMS_OUTPUT 文本。
Go to (Menu) VIEW -> Dbms_output to invoke the pane.
转到(菜单)VIEW -> Dbms_output 以调用窗格。
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.
编辑:不要忘记根据您期望的输出量设置缓冲区大小。
回答by user2497268
Make server output on First of all
首先使服务器输出
SET SERVEROUTPUT on
thenGo to the DBMS Output window (View->DBMS Output)
then Press Ctrl+Nfor connecting server
SET SERVEROUTPUT on
然后转到 DBMS 输出窗口(查看->DBMS 输出)
然后按Ctrl+N连接服务器
回答by devosJava
There are 2 options:
有2个选项:
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).
打开“查看”菜单并单击“dbms 输出”。您应该在工作表底部看到一个 dbms 输出窗口。然后您需要添加连接(出于某种原因,这不会自动完成)。
回答by Lova Chittumuri
回答by user3098484
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...
我添加了第二个光标的关闭。它也能工作并获得输出......
回答by Bhadra
select View-->DBMS Output in menu and
在菜单中选择 View-->DBMS Output 并
回答by user2001117
Go to the DBMS Output window (View->DBMS Output).
转到 DBMS 输出窗口(查看->DBMS 输出)。