可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
.
回答1:
You need to turn on dbms_output. In 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.
In SQL*Plus:
SET SERVEROUTPUT ON
回答2:
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.
回答3:
Make server output on First of all
SET SERVEROUTPUT on
then
Go to the DBMS Output window (View->DBMS Output)
then Press Ctrl+N for connecting server
回答4:
There is another option :
set serveroutput on format wraped;
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 automaticallly).
回答5:
select View-->DBMS Output in menu and
回答6:
Go to the DBMS Output window (View->DBMS Output).
回答7:
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...