OUT
OUT in SQL is used in a stored procedure to specify an output parameter. This type of parameter is used to return a value from the procedure back to the user. The value of an OUT parameter can be modified by the stored procedure and the resulting value can be used in the calling program.
Example
Output
Explanation
The SQL procedure GetTotalOrders
is created to get the total number of orders from the table orders
. The OUT
parameter total
is used to store the result. After the procedure is called with a user-defined variable @total
, it extracts the total order count and stores it in @total
. A SELECT
statement is then used to display the total count of the orders.
Example
Output
Explanation
The provided SQL code defines a stored function using PL/pgSQL to calculate the factorial of a number. IN parameter ‘n’ is the input value for which we calculate the factorial. The function uses a FOR loop to calculate the factorial of ‘n’ and returns the result. We then call this function with the number ‘5’ and it returns ‘120’, which is the factorial of ‘5’.
Example
Output
Explanation
The example is a simple PL/SQL anonymous block where a variable p_name
is declared and initialized with a value ‘John Doe’. The dbms_output.put_line()
procedure is then used to print the value of p_name
.
Example
Output
Explanation
In the above example, an output parameter ‘@UserCount’ is used in the stored procedure ‘GetUserCount’ to store the count of users from the ‘Users’ table. Further, this output parameter is used to fetch the count value, which is displayed in the SELECT statement. The output displays the total count of users.