views:

406

answers:

2

I have a stored procedure'test' in Sybase ASA with for example 4 parameters.

par1 INT = 0,
par2 VARCHAR(50) = NULL,
par3 VARCHAR(100) = NULL,
par4 VARCHAR(10) = ''

Now I want to execute this stored procedure with par1 as its default value.

call test(NULL, 'test')

But the actual value of par1 i not 0, but 1!

I also tried

call test(DEFAULT, 'test')

but that doesn't run.

A: 

In your first execution are you sure that par1 in the procedure is 1 - I think it is really NULL the value you passed in.

Default parameters are only used if the poarameter is not passed in not if it has been given a value even if it is NULL.

Thus in you cses par3 and par4 get the default but par1 and par2 get what you pass in.

Mark
+1  A: 

1) The first example did not work because you passed in a NULL value.

2) I'm not quite sure of which syntax you are using for his SP (never heard of "par1"), but using standard syntax, what you need to do is to have named parameters in SP and in the call:

CREATE PROCEDURE test( INOUT var1 INT DEFAULT 0,

                   INOUT var2 VARCHAR(50)  DEFAULT NULL,

                   INOUT var3 VARCHAR(100) DEFAULT NULL,

                   INOUT var3 VARCHAR(10)  DEFAULT '')

and then call

CALL test (var2 = 'test')

DVK
[quote](never heard of "par1")[/quote]That was just an example of a parameter name and its default value.
jwdehaan
Oh. That. I was assuming it is some strange ASA syntax I never encountered (there appears to be more than one)
DVK