programing tip

SQL Developer에서 변수 값 인쇄

itbloger 2020. 8. 25. 07:44
반응형

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;

그리고 출력은 anonymous block completed.


dbms_output을 켜야합니다. Oracle SQL Developer에서 :

  1. DBMS 출력 창을 표시합니다 (보기-> DBMS 출력).
  2. Dbms Output 창의 맨 위에있는 "+"단추를 누른 다음 열리는 대화 상자에서 열린 데이터베이스 연결을 선택하십시오.

SQL * Plus에서 :

 SET SERVEROUTPUT ON

SQL Developer는 DBMS_OUTPUT 창 창을 명시 적으로 켰을 때만 DBMS_OUTPUT 텍스트를 출력하는 것 같습니다.

(메뉴)보기-> Dbms_output으로 이동하여 창을 호출합니다.

녹색 더하기 기호를 클릭하여 연결에 대한 출력을 활성화 한 다음 코드를 실행하십시오.

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


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


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).


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...


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


select View-->DBMS Output in menu and


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

참고URL : https://stackoverflow.com/questions/7887413/printing-the-value-of-a-variable-in-sql-developer

반응형