I have searched and not found any answers that address this directly. I just want to display that I have successfully completed script blocks while executing an implementation script that does multiple things.
PRINT 'Start script'
PRINT 'Insert A'
INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');
PRINT 'Update B'
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
PRINT 'End script'
So, when done, the output should look something like:
Start script
Insert A
4 rows inserted
Update B
1 row updated
End script
Although both systems use a version of Structured Query Language, or SQL, MS SQL Server uses Transact SQL, or T-SQL, which is an extension of SQL originally developed by Sybase and used by Microsoft. Oracle, meanwhile, uses PL/SQL, or Procedural Language/SQL.
Usually, we use the SQL PRINT statement to print corresponding messages or track the variable values while query progress. We also use interactions or multiple loops in a query with a while or for a loop. We can also use the SQL PRINT statement to track the iteration.
To do this we use a procedure called dbms_output. put_line to place the results in a buffer that SQL*Plus will retrieve and display. SQL*Plus must be told to retrieve data from this buffer in order to display the results. The SQL*Plus command 'set serveroutput on' causes SQL*Plus to retrieve and display the buffer.
Oracle has a database output buffer called DBMS Output
, which has a PUT_LINE()
function. However, most Oracle tools (SQL*Plus
and SQL Developer
) do not have the output buffer enabled, by default, in a session.
To turn on this output buffer in SQL Developer
, do the following:
View
| DBMS Output
to enable the DBMS Output windowTo turn on this output buffer on in SQL*Plus!
, you need to set the SERVEROUTPUT
value via the command prompt, like this:
SET SERVEROUTPUT ON [SIZE N|UNLIMITED]
Example:
SET SERVEROUTPUT ON 50000
Note: The
50000
is a length limit, in bytes.
Now you can use the PUT_LINE()
function to actually write status messages, like this:
DBMS_OUTPUT.PUT_LINE('Status message goes here.');
Here is the documentation for SET SERVEROUTPUT PL-SQL command.
Here is the documentation for DBMS_OUTPUT.PUT_LINE() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With