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



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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

You can enable the output in the connection properties. Source

Solution 5:[5]

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;

Solution 6:[6]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 moscas
Solution 2
Solution 3 Littlefoot
Solution 4 Alex Fischer
Solution 5 Jakob
Solution 6 Paul