Running stored procedure with out parameter and saving out value to variable in sqlworkbench/j script - sql-workbench-j

How do I save procedure out parameter value to variable for later reuse in sqlworkbench/j script?

It is possible to run a stored procedure with out parameters using WbCall
However, the result of that can not be used to be stored into a Workbench variable.
That is only possible with "regular" queries (SELECT) that return a result set.

Related

Stored Procedure Activity procedure parameter with int data type in Azure Data Factory

I am working on a stored procedure activity to load data into one of my table. The procedure expects an int parameter to be passed and the value for this comes from the lookup output firstrow field. But when I pass the lookup output value for the parameter the pipeline is not getting executed. I have tried to convert the values as well and even used a variable to store. Any option to process the same?
Regards,
Sandeep
Can you send the detailed error when you try to execute the pipeline?
Thanks,
Pratik

How to assign default property value for IN parameters in teradata stored procedure

Need to develop a stored procedure to insert values into a table. Consider the table has 5 columns, where not all columns values are mandatory for user inputs. The DDL for stored procedure will be like
CREATE OR REPLACE PROCEDURE UPDATE_EMPLOYEE_INFO
(IN EMPLOYEE_NUMBER CHAR(10),
IN EMP_DEPT CHAR(3),
IN PHONE_NUMBER CHAR(4),
IN JOB CHAR(8),
IN ELEVEL SMALLINT)
Begin
--- Insert query here ---
End
This procedure can be execute using commands
CALL UPDATE_EMPLOYEE_INFO(1,'',1234567890,'admin','')
However,columns EMP_DEPT and ELEVEL are not mandatory fields to have values. How can I mention in stored procedure call to take default values like below.
CALL UPDATE_EMPLOYEE_INFO(1,DEFAULT,1234567890,'admin',DEFAULT).
Basically, I want to achieve something kind of this in link using teradata - https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/sqlp/rbafyprocdefaults.htm
There are no optional parameters. All parameters are mandatory. So you would probably have to pass in optional paramters as null and then write some conditional logic into your stored proc based on whether the parameter is null.
For example:
CALL UPDATE_EMPLOYEE_INFO(1,NULL,1234567890,'admin',NULL)
The Teradata documentation says:
Rules For Specifying Input And Output Parameters
Call arguments consisting of input and output parameters must be
submitted with a CALL statement. No default parameter values can be
defined at the time a procedure is created; the CALL returns an error
if the required call arguments are not specified.
https://info.teradata.com/HTMLPubs/DB_TTU_16_00/index.html#page/SQL_Reference/B035-1146-160K/cum1472240816735.html

SSRS: saving variable from a stored procedure

Is it possible to replicate this code from a stored procedure in a SSRS dataset?
exec #dtEffective = dbo.selUpdEnv 'PrevBusDt','=',#cdUser,'N'
What I'm trying to do is save the effective date in a variable and display the date in a textbox.
I tried creating a parameter called dtEffective and use it in the dataset. But it didn't save the value.
Create a new data set with the [dbo.sqlUpdEnv] as the record source. Note that #cdUser will need to be populated first since you're passing it in, so make sure that's above #dtEffective in the parameter list. In your #dtEffective parameter, set the Default Value to the result of the data set.

Passing parameters to stored procedure in OBIEE 12c rpd from OBIEE 12c dashboard

I am trying to create an OBIEE report using stored procedures.
I have created a function in SQL Developer which takes a parameter and returns refCursor as output.
I, then, set the following query as default initialization string in physical layer of rpd:
Select * from table(pipelined_emp(HR_DATA.GETCURSORS(parameter)))
GETCURSORS(parameter) is my function.
For now, in place of parameter, I am passing a constant value.
While, I wish to pass a value from the OBIEE dashboard, similar to a prompt, to this function in the physical layer of rpd.
Thanks!
Yes. Session variables in the RPD being written into by front-end request variables: https://gerardnico.com/wiki/dat/obiee/obis/request_variable

DB2 calling stored Procedure in conditional statement

I need to query a stored procedure and on the basis of result set of that procedure need to make decisions in conditional statement
For instance I have a stored Procedure "Main_SP"
Now if result of "Main_SP" is 'null' then the result should be 'Tweety', but if th result set is not null then result set should be retrieved,
how to do it?
I tried following and some other but none worked.
SELECT
case Main_SP('MyVariable')
when 'null'
then 'Tweety' end
FROM SYSIBM.SYSDUMMY1 WITH UR
SELECT
case Main_SP('MyVariable')
when null
then 'Tweety' end
FROM SYSIBM.SYSDUMMY1 WITH UR
It is failing the condition, In first command when even it is 'null' it is not printing 'Tweety'.
and while using second, Getting error that 'Null' is not valid in the context.
I don't believe you can use a stored procedure that way.
A stored procedure can return data in two ways
As a result set
in an output or input/output parm
You're not using option 2 and I don't think a result set is ever NULL. There might be no records, but the RS itself isn't NULL. In addition, from what I can see in the manuals, processing a RS from a stored proc inside another stored proc in DB2 requires you to declare an allocate result set locators. But I've never done this.
If your procedure returns a single value or null, you'd be better served by defining it as a function with a return value. Then your code would be simply:
SELECT
COALESCE(Main_Fnc('MyVariable'),'Tweety')
FROM
SYSIBM.SYSDUMMY1 WITH UR
You can't call a stored procedure as part of an SQL fullselect; you would need to have the client that calls the stored procedure handle this logic. If you must do it on the server, implement a new stored procedure that calls Main_SP itself and contains your logic to interpret the result.

Resources