PRINT

PRINT in SQL is a statement used to return a message to the user, typically for debugging purposes or providing information during the execution of a stored procedure, function or trigger.

Example

DECLARE @MyVariable VARCHAR(50)
SET @MyVariable = 'Hello, SQL Server!'
PRINT @MyVariable

Output

Hello, SQL Server!

Explanation

In the example, DECLARE is used to declare a variable @MyVariable of type VARCHAR(50). The SET statement is then used to assign the value ‘Hello, SQL Server!’ to this variable. Finally, the PRINT statement is used to display the value of @MyVariable, which results in outputting ‘Hello, SQL Server!’.

Example

BEGIN
DBMS_OUTPUT.PUT_LINE('Hello, Oracle!');
END;

Output

Hello, Oracle!

Explanation

In the example, DBMS_OUTPUT.PUT_LINE is an Oracle procedure for sending a message to the console. The message ‘Hello, Oracle!’ is the string provided as an argument to DBMS_OUTPUT.PUT_LINE. The BEGIN and END keywords are used to mark the start and end of the PL/SQL block containing the procedure call.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.