Print text in Oracle SQL Developer SQL Worksheet window

前端 未结 8 466
醉梦人生
醉梦人生 2021-01-30 01:47

I am using Oracle SQL (in SQLDeveloper, using the SQL Worksheet). I would like to print a statement before my select, such as

PRINT \'Querying Table1\';
SELECT          


        
相关标签:
8条回答
  • 2021-01-30 02:28

    The main answer left out a step for new installs where one has to open up the dbms output window.

    Then the script I used:

    dbms_output.put_line('Start');
    

    Another script:

    set serveroutput on format wrapped;
    begin
        DBMS_OUTPUT.put_line('jabberwocky');
    end;
    
    0 讨论(0)
  • 2021-01-30 02:31

    enter image description here

    for simple comments:

    set serveroutput on format wrapped;
    begin
        DBMS_OUTPUT.put_line('simple comment');
    end;
    /
    
    -- do something
    
    begin
        DBMS_OUTPUT.put_line('second simple comment');
    end;
    /
    

    you should get:

    anonymous block completed
    simple comment
    
    anonymous block completed
    second simple comment
    

    if you want to print out the results of variables, here's another example:

    set serveroutput on format wrapped;
    declare
    a_comment VARCHAR2(200) :='first comment';
    begin
        DBMS_OUTPUT.put_line(a_comment);
    end;
    
    /
    
    -- do something
    
    
    declare
    a_comment VARCHAR2(200) :='comment';
    begin
        DBMS_OUTPUT.put_line(a_comment || 2);
    end;
    

    your output should be:

    anonymous block completed
    first comment
    
    anonymous block completed
    comment2
    
    0 讨论(0)
  • 2021-01-30 02:33
    PROMPT text to print
    

    Note: must use Run as Script (F5) not Run Statement (Ctl + Enter)

    0 讨论(0)
  • 2021-01-30 02:33

    You could put your text in a select statement such as...

    SELECT 'Querying Table1' FROM dual;
    
    0 讨论(0)
  • 2021-01-30 02:46

    If you don't want all of your SQL statements to be echoed, but you only want to see the easily identifiable results of your script, do it this way:

    set echo on

    REM MyFirstTable

    set echo off

    delete from MyFirstTable;

    set echo on

    REM MySecondTable

    set echo off

    delete from MySecondTable;

    The output from the above example will look something like this:

    -REM MyFirstTable

    13 rows deleted.

    -REM MySecondTable

    27 rows deleted.

    0 讨论(0)
  • 2021-01-30 02:52

    You could set echo to on:

    set echo on
    REM Querying table
    select * from dual;
    

    In SQLDeveloper, hit F5 to run as a script.

    0 讨论(0)
提交回复
热议问题