Cezar Cobuz
Cezar Cobuz

Reputation: 1207

Use dbms_output.put_line in Datagrip for .sql files

I started to use Datagrip for my PL/SQL (school) projects that need the use of DBMS_OUTPUT.PUT_LINE. Before this I was using Oracle SQL developer and I was able to use DBMS_OUTPUT by adding the following:

SET serveroutput ON;

There is a related question that shows how to enable or disable showing the contents of the DBMS_OUTPUT buffer but this only works for the Database Console tool window. How can I apply this to any .sql file? Currently, I am copying the content of my .sql files and run it in the Console tool window but there must be a better way.

Upvotes: 27

Views: 21828

Answers (8)

Jack
Jack

Reputation: 3057

Using Rider 2023 I found the option in the Data Sources panel:

enter image description here

Upvotes: 0

I.Yuldoshev
I.Yuldoshev

Reputation: 256

Press shift+shift and then search for DBMS_OUTPUT and then you can enable/disable

I tried it with new UI

enter image description here

Upvotes: 7

Paul
Paul

Reputation: 131

Finaly found it! The previous answer didn't read the question and answer for intelij instead of datagrip which have completely different interface.

For 2021.1 right click on the console list in the service window and there should be a enable DBMS_OUTPUT when you right click.

Upvotes: 11

Alex Fischer
Alex Fischer

Reputation: 241

For all that are reading this for version(s) > 2021.1

You can enable the output in the connection properties. Source

Upvotes: 4

Vyoam
Vyoam

Reputation: 186

I second the comment from Prometheos II. Jakob also seems to say the same.

As you might know, the .sql scratch files HAVE to be associated with a console. You need to toggle the Enable SYS.DBMS_OUTPUT option icon in the associated console and you do see the effect when executing from the associated .sql file.

Steps:

  1. Open your .sql file
  2. Associate it with a console
  3. Open the console and enable Enable SYS.DBMS_OUTPUT option
  4. Go back to the .sql file and run your code. You'll be able to get the DBMS_OUTPUT in the console output.

Suboptimal design by JetBrains, but it works.

My IDE version: IntelliJ 2018.3 Ultimate (DataGrip uses the same code, I think)

enter image description here

Couldn't comment to existing sections due to low rep. Hence, added a new answer.

Upvotes: 16

Jakob
Jakob

Reputation: 143

This also works for sql files in DataGrip. Like moscas writes you need to activate the output console toggle button 'Enable SYS.DBMS_OUTPUT'.

Also you need to wrap it with begin end:

begin
  dbms_output.put_line('test');
end;

Upvotes: 1

moscas
moscas

Reputation: 10345

Turn on this setting in the Output pane: enter image description here

Upvotes: 28

Littlefoot
Littlefoot

Reputation: 142713

When everything else fails, read the documentation: Showing DBMS_OUTPUT for Oracle:

For Oracle, you can enable or disable showing the contents of the DBMS_OUTPUT buffer in the output pane. To do that, use the apropriate icon (note by LF; can't reference that image) on the toolbar of the Database Console tool window (Ctrl+F8).

Upvotes: 5

Related Questions