Call a stored procedure with OUT parameter within another stored procedure in SAP HANA - sql

I am currently trying to send an Email from a stored procedure I have created using the native sys.staticserver_sendemail_dev function.
But both the procedures have OUT parameters declared when I try to invoke the email procedure in my I get an error stating the parameters are not declared.
I wanted to know how to call a stored procedure without parameters inside another stored procedure.

I understood from your question, that you have two stored procedures, where one calls the other and both have out parameters. This is a valid constellation. Please find a minimum example, which works on SAP HANA Cloud:
CREATE OR REPLACE PROCEDURE TEST_INNER (OUT i INTEGER)
AS
BEGIN
SELECT COUNT(*) INTO i FROM DUMMY;
END;
CREATE OR REPLACE PROCEDURE TEST_OUTER (OUT another_i INTEGER)
AS
BEGIN
DECLARE outparam INTEGER;
CALL TEST_INNER(:outparam);
another_i = :outparam;
END;
CALL TEST_OUTER(?);
If this does not solve your issue, you need to provide more details as well as minimal code snippet similar to the one above to reproduce the issue.

Related

Oracle trigger to call Stored Procedure

I have an SP that needs to be called by an "after update" trigger. This Sp writes out a document to the mounted oracle directory for the host application to pick up. The SP has the following parameters :
CREATE OR REPLACE test_sp_mbinfo
(out_status OUT VARCHAR2,
out_dir OUT VARCHAR2,
in_contract IN VARCHAR2)
The in_contract parameter would be sent in by the triggering event. The trigger code i have so far that i have a hard time compiling is :
CREATE OR REPLACE TRIGGER mbinfo_trig
AFTER UPDATE OF tsta_cncontst ON kndtsta
FOR EACH ROW
BEGIN
IF (:new.tsta_cncontst IN ('02','06'))
THEN
test_sp_mbinfo(:new.tsta_cncclipu);
END IF;
END
;
How do i pass in the 2 out parameters to make the process work?
Thank you!
You could declare two local variables in the trigger and pass those for the OUT parameter. The question then becomes whether you care about the returned values, and if so what to do with them.

Can you call a Netezza stored procedure more than once in Select?

I created a simple stored procedure for testing purposes in Netezza that returns a string. When I call it from a select statement, it works fine, unless I call it more than once on multiple columns. I get the error:
ERROR [HY000] ERROR: Can't use a stored procedure in this context.
Is this not allowed?
Stored procedure:
CREATE OR REPLACE PROCEDURE SP_TEST_PROC(VARCHAR(ANY))
RETURNS VARCHAR(32)
EXECUTE AS OWNER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
TEST_PAR ALIAS FOR $1;
BEGIN
RETURN 'A' || TEST_PAR;
END;
END_PROC;
How I call it:
SELECT SP_TEST_PROC('abc') as test1, sp_test_proc('def') as test2
You cannot call more than one stored procedure in a SELECT. There are a couple of ways that you can call a Netezza stored procedure:
CALL SP_TEST_PROC('abc');
EXEC SP_TEST_PROC('abc');
SELECT SP_TEST_PROC('abc');
However, the you cannot have a FROM clause when using SELECT. The SELECT form is just a synonym for one of the other forms, and is not really a SELECT as we would normally think of one.
You can find the documentation on calling a stored procedure here.
If you are looking for a scalar function, then you are probably better served by writing a UDF. However, UDFs in Netezza do not support NZPLSQL as a language. You would have to write it in one of the supported UDF languages (e.g C++ or Lua).
To execute a stored procedure you must run this command:
EXECUTE SP_TEST_PROC('abc')
EXECUTE SP_TEST_PROC('def')
and not as you've written:
SELECT SP_TEST_PROC('abc') as test1, sp_test_proc('def') as test2
You can go here for an example

Using a PL/SQL stored procedure in Crystal Report command object

I'd like to call a stored procedure from a crystal report command object using an Oracle direct connection. The stored procedure takes a refcursor and some parameters that can be passed from the report, but I'm not sure what the syntax should look like.
For simplicity, feel free to pretend that the stored procedure only takes a refcursor and nothing else. What should the syntax look like? I assume I need to declare the refcursor, call the SP, and then return the cursor.
I'm pretty unfamiliar with this stuff though, and I'm not actually sure how to return the cursor. I figure the first bit would look like:
VARIABLE Cursor refcursor
declare
begin
MYSTOREDPROCEDURE(:Cursor);
end;
/
I'm not sure how to then return the cursor for Crystal Reports to use (2008/2011). I hope this was enough information.
You can't call a stored procedure from a command. You need to add it to the report in the same manner as you add a table (in the database expert). Moreover, the SP needs to be built a certain way to work with CR; specifically, it needs to return a REF CURSOR.
Example.

how to excecute a simple oracle procedure with out parameter

I am new to oracle procedures so I'm having a bit of trouble with this. I have an oracle procedure defined like
PROCEDURE USERPROGRESS (
queryType IN varchar2,
o_Cursor OUT cur_Cursor) IS ...
Notice how it has the out cur_Cursor. At the end of the procedure the procedure does
OPEN o_Cursor FOR sql_string;
How exactly do I can I call this procedure? I'm having trouble finding any helpful examples. Thanks.
Check this link..
http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
Depending on how you declared cur_Cursor, you can define a variable in your procedure and then fetch and display the results as needed.

Informix: procedure with output parameters?

I searched a lot, but couldn't find anything.. I just want to ask if there's any way to create and call a procedure (Informix) with out parameters. I know how to return one or more values (for procedures and for functions), but this is not what I want. It would be really strange, if Informix does not allow output parameters..
Thanks in advance!
EDIT: Yes, I saw it's possible, but I still can't execute such procedure. For example:
CREATE PROCEDURE mytest(batch INT,OUT p_out INT)
DEFINE inc INTEGER;
LET inc = 1;
LET p_out = 5;
END PROCEDURE;
and what I receive is:
The routine mytest can not be resolved
and this happens only on executing functions with output parameters..
Why do you need 'out' parameters? Informix procedures can return multiple values from a single call (or, in this case, a single value):
CREATE PROCEDURE mytest(batch INT) RETURNING INT AS p_out;
DEFINE inc INTEGER;
DEFINE p_out INTEGER;
LET inc = 1;
LET p_out = batch + inc;
RETURN p_out;
END PROCEDURE;
There are only a limited number of places where you can use an OUT parameter. One is in a query - there is a name SLV (statement local variable) that turns up in some error messages. I believe there's a way to get to OUT parameters via Java (JDBC) too. AFAIK, other APIs do not allow it.
Code written for Informix assumes that it won't need output parameters. Code migrated to Informix from other (impoverished?) systems that do not provide multiple output values from a single procedure need to be rethought to work sensibly with Informix.