Skip to content
Advertisement

Stored procedure output variable being stored as input/output type

I’m attempting to get the metadata for a stored procedure in Microsoft SQL Server using the Java SQL API.

This is the structure of the stored procedure:

CREATE PROCEDURE [dbo].[testproc] 
    (@rolloverType AS integer,
     @retval nvarchar(50) output)
AS
BEGIN
    SET NOCOUNT ON;

    SELECT @retval = [col1]
    FROM [dbo].[Table_1]
    WHERE col3 = @rolloverType;
END
GO

However, the Java SQL API is saying that @retval is an INOUT type, and Microsoft SQL Server Management Studio also shows this parameter as an Input/Output type. How can I construct this stored procedure so that @retval is only of type Output?

Advertisement

Answer

As @GSerg commented, you can’t.

In SQL, an OUTPUT parameter acts as both INPUT and OUTPUT, see this answer

You’re obtaining an INOUT value because of the mapping used to refer ORACLE procedure parameter types, which are IN, OUT and INOUT.

From dba-oracle.com:

A variable passed as mode IN is always read-only. A variable using IN mode can be read and used by the procedure/function but can not be changed and it cannot be the receiver of an assignment operation.

A variable passed in OUT mode is used to pass information back from the procedure to the calling program. It is a write-only variable and has no value until the block assigns it a value.

A variable passed in INOUT mode has characteristics of both the IN and the OUT mode. The variable value is passed in and can be read by the procedure. The procedure can also change the value and it will be copied back to the passed variable when the procedure completes.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement