how to excecute a simple oracle procedure with out parameter - sql

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.

Related

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

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.

Can I have the same stored procedure with two different name?

Bellow, I have a stored procedure named usp_customer
CREATE PROCEDURE usp_customer
AS
BEGIN
SELECT * FROM CUSTOMER
END
I want to give the same exact stored procedure a second name usp_cust1
Note: I am not looking to rename or to create a new stored procedure, I want both names to work
In the end, I could use either EXEC usp_customer or EXEC usp_cust1
Thanks
edit: changed sp_ to usp_
One stored procedure can call another:
CREATE PROCEDURE usp_cust1
AS
BEGIN
EXEC usp_customer;
END;
Note that in SQL Server, you should not use the "sp_" prefix for stored procedures. That is best reserved only for system stored procedures.

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

Stored Procedures for IBM DB2

I am new to stored procedures. Need to pick up some stored procedures for DB2(which I am also new to). The code I wrote is not working:
CREATE PROCEDURE sp_test
(
id NUMBER
)
BEGIN
IF NUMBER < 0 THEN
RAISE VALUE ERROR;
END IF;
SELECT * FROM student_tb
WHERE taskid = 'NUMBER';
END;
/
and this is the script (another file) which calls the stored procedure:
BEGIN
sp_test('15');
END;
I am not sure what is wrong. Hope someone can advise. Thank you.
I'm not an expert in DB2, but I'm pretty sure you have to CALL stored procs in DB2.
call sp_test('15');
or
execute (call sp_test('15'));
The syntax might be a little different for stored procedures that return a result set. Docs for DB2 on your target platform should explain the difference.

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.