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

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.

Related

How should I select or display the out variable from a stored procedure call?

I'm writing a pretty basic stored procedure that just takes values from the sample DB2 database and computes the standard deviation. I wrote the procedure itself just fine, and I can call it without error. But I can't figure out how to actually display my result or select it in a statement. Everything I try results in a syntax error and I haven't been able to find anyone doing this specific task in my google searches.
This is the gist of my code (snipped for brevity):
CREATE PROCEDURE SAL_STD_DEV
(OUT std_dev real)
LANGUAGE SQL
BEGIN
--do stuff
SET std_dev = 10; --changed for simplicity
END#
CALL SAL_STD_DEV(?)#
All this runs, but just CALL doesn't create any output. What's the syntax to SELECT the out variable? I can't put a DECLARE before the CALL because it's not in a stored procedure, and PRINT doesn't work either.
(# is my terminal character because I'm using ; in the stored procedure)
Edit: Both the create procedure and call statements are made in the same SQL file, the database is connect to through localhost and I'm using DB2 11.1.0.1527 and developing in IBM Data Studio 4.1.2.
From wherever the CALL is being made, that feature might present a Result Set, despite apparently not presenting the result of an OUT parameter. If so, then the stored procedure perhaps could be revised to return the OUT value [instead, or additionally] as a result set, so that the interface that accepts the CALL statement as input, might present that result-set. Regardless:
In a statement processor [e.g. that is not a GUI, but] for which SELECT query output is presented, the following scripted requests should likely suffice:
create variable my_real real
;
call SAL_STD_DEV(my_real)
;
select my_real from sysibm.sysdummy1
;

Oracle SQL Stored Procedures Call vs. Execute

Problem
I'm trying to understand the difference between Oracle SQL commands CALL and EXECUTE.
I've been using CALL to kick off stored procedures but in talking with another developer I found that he almost exclusively uses EXECUTE. I did some research online to see if I was doing something incorrectly but I'm not seeing the clear distinction between the two commands and people seem to use them interchangeably.
Based on the documentation, they seem remarkably similar (at least in terms of interacting with stored procedures).
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4008.htm
http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12022.htm
http://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_app_dbms_aw026.htm
It does look like CALL is a universal SQL command while EXECUTE seems to be proprietary so I would be inclined to use CALL over EXECUTE but then again I don't know what that means in regards to performance.
Questions
Is one preferable over the other in terms of kicking off a stored procedure? Does it matter?
If it does matter, what is a situation where either is appropriate?
Are there any performance differences between the two? What's best practice?
Both EXEC[ute] SP() and CALL SP() could be used in SQL*Plus to execute an SP. BTW, you can also use BEGIN SP(); END;
But there are some differences.
CALL is Oracle SQL and should work everywhere. Other DB clients that can talk to Oracle may or may not support SQL*Plus EXEC. Many do (for example, Oracle SQL Developer, SQLWorkbench/J), but some don't (Liquibase).
The data types of the parameters passed by the CALL statement must be SQL data types. They cannot be PL/SQL-only data types such as BOOLEAN.
EXEC could be used to execute not only an SP, but an arbitrary statement.
If an SP does not have parameters, you can use EXEC SP; syntax, but CALL requires empty parentheses: CALL SP();
If you are calling a proc that returns a sys_refcursor using Toad, there is a difference between CALL and EXEC.
create procedure foo(i in number,o out sys_refcursor)
as
begin
open o for
select i from dual;
end;
exec foo(1,:r); -- outputs 1 row
call foo(1,:r); -- outputs 0 rows
-- Note: when you prefix a parameter with a colon, Toad will prompt you for the type (which in this case is a cursor).

Executing Stored Proc in Pervasive Control Center

I am relatively new to Pervasive Control Center and I was wondering if I wanted to test a stored Procedure to see its results, how would I simply select that stored proc? I have:
Select SP_test_getMeasure06
I am sure I am missing something because I know this is legal my syntax must be off slightly.
Thanks in advance!
You can execute a stored procedure using either Call or Exec. For example:
exec SP_test_getMeasure06
You'll need to make sure your stored procedure uses the RETURNS clause to get data back. For more information check out the Stored Procedure docs.

how to execute oracle procedure in ssis sql execute task? [duplicate]

I'm working with SSIS 2008 and am having a problem calling an Oracle stored procedure that has an output parameter.
I call the stored procedure in SqlPlus like this:
var vresult number;
exec my_stored_procedure(:vresult);
print vresult;
The statements work and I get the output I need. I am trying to do something similar in SSIS, yet I need to do this repeatedly, maybe in a ForEach or a script to update a temporary result set with the result of calling the stored procedure (the stored procedure generates a number, and I need to add that number to each row in a result set which just holds some state information).
I have tried a lot of different approaches and always end up with 'invalid statement' or similar errors.
I have also tried the following approaches:
How to resolve SQL query parameters mapping issues while using Oracle OLE DB provider?
Update a row in oracle using OLEDB command(SSIS)
Oracle variables
The crux of the problem seems to be the stored procedure's output parameter.
I have tried using the the Oracle Provider for OLE DB. Any ideas?
If you are trying to invoke The stored Procedure in Oracle PLSQL this Link is very brief.
http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
If you are Working in Java then. The Statement Object
java.sql.CallableStatement ps;
ps.registerOutParameter(parameterIndex, sqlType);
Similarly .Net or Any Other Platform must will have the same Convictions. Hope so.:)
I came up with a solution that works:
Use the 'declare' and 'end' construct
Combine with 'execute immediate'
Add the 'using' statement to the end of the exec immediate to inject variable
So a script that implements this might look something like this:
declare
myVar number;
myStatement varchar2(50);
begin
myStatement:='exec myProc(:1)';
execute immediate myStatement using output myVar;
end;
Paste this script into an Execute SQL task, set the task's properties and it works!
I'm new to Oracle but it looks like the :1 notation is a place-holder for the variable. You can test this using sqlplus too - just save the code in a file and start sqlplus using the # option on the command line.
The only problem: I can't get value of the variable for use in SSIS, but that's another problem.
check tis post: Run an Oracle package from SQL Server Integration Services
http://www.mssqltips.com/sqlservertip/2724/run-an-oracle-package-from-sql-server-integration-services/
regards
You are almost there. In order to retrieve the value of the output parameter from the Oracle stored procedure in SSIS, here is what worked for me
In the Execute SQL task, paste this in the SQL statement box
declare
vresult number;
begin
my_stored_procedure(vresult);
?:=vresult;
end;
In the Parameter Mapping, ensure to map your SSIS variable to this output of your stored procedure by setting the direction to "Output" and parameter name as "0" (if it is the first parameter)
PS: ensure the Oracle output variable datatypes match your SSIS variables
Thanks
Mezue

How to convert a big set of SQL queries into a single stored procedure that uses a variable?

I am trying to convert a big list of SQL statements into a PostgreSQL stored procedure that uses a variable, one that should be populated from the result of one SELECT.
If you want to see what has to be run, you can check it here
As far as I know PostgreSQL does not allow use to use variables inside stored procedures that are using SQL language, so I'm looking for solutions that would require a minimal number of changes.
It's much easier after you find the right syntax:
Here is the procedure definition for plpgsql language:
DECLARE myvar integer;
BEGIN
SELECT INTO myvar FROM ...;
-- use myvar
END;
The code seems to be pretty repetitive. Will EXECUTE be of any help? (manual about execute) (example and more information) It allows you to run predefined queries and create new ones on the fly.