Stored Procedure In Oracle 11g database - stored-procedures

I want to do insert,update,delete and select statement in one stored procedure
using oracle 11 g database.If any one know this ,please help me to do this.

STORED PROCEDURE EXAMPLE for AGENT
CREATE OR REPLACE PROCEDURE GET_AGENT
(V_CUR IN OUT SYS_REFCURSOR)
AS
BEGIN
OPEN V_CUR FOR SELECT * FROM AGENT;
END GET_EMPLOYEES;
INSERT INTO AGENT VALUES(:AGENTID,:AGENTNAME)
DELETE FROM AGENT WHERE AGENTID=:AGENTID
UPDATE AGENT SET AGENTNAME=:AGENTNAME WHERE AGENTID=:AGENTID
UPDATE AGENT SET AGENTNAME=:AGENTNAME,..... WHERE ROWID=:RECORD_ROWID
DELETE FROM AGENT WHERE ROWID=:RECORD_ROWID

Related

Unable to create a Stored procedure in Redshift Aginity and aginity pro

Trying to create the stored procedure in redshift aginity workbench but it through an error like 'unterminated dollar-quoted string at or near "$$
'
In amazon, they already gave the solution for this
https://docs.aws.amazon.com/redshift/latest/dg/stored-procedure-create.html
particular client tool only supported to create the stored procedure.
I want to conform aginity don't have the option to create this?
and
Which is the best tool to create stored-procedure?
CREATE OR REPLACE PROCEDURE staging.test_sp1(f1 int, f2 varchar)
AS $$
BEGIN
RAISE INFO 'f1 = %, f2 = %', f1, f2;
END;
$$ LANGUAGE plpgsql;
You can create RedShift stored procedures in Aginity Pro by using Run Batch. Full support will be in the 9/16 release.
Aginity need to update their tool to pass the dollar quoted procedure body to Redshift correctly. I note that Aginity is able to execute the procedure with CALL staging.test_sp1().
Some other tools have already been updated to allow creation and you can always use psql to create the procedure.

Unable to retrieve multiple rows using cursor from database table using stored procedure DB2

I am trying to retrieve multiple rows from table using stored procedure and it doesn't work for me. My stored procedure is as follows,
CREATE OR REPLACE PROCEDURE E_Enquiry
(IN SourceQueue1 VARCHAR(30) ) LANGUAGE SQL
BEGIN
DECLARE C1 CURSOR FOR
select CreationTime
from ms.Exception_Message
where SourceQueue = SourceQueue1;
open c1;
END;
I am trying to call the stored procedure from Mule Anypoint Studio using the Database connector and have seen the result as null when I print the payload with a logger. If I try to modify the query as it returns a single row it works (without using cursor).
Please help to resolve this. Thanks.
What platform and version of DB2?
Try the adding
DYNAMIC RESULT SETS 1
WITH RETURN TO CLIENT
Like so:
CREATE OR REPLACE PROCEDURE E_Enquiry
(IN SourceQueue1 VARCHAR(30) )
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C1 CURSOR WITH RETURN TO CLIENT FOR
select CreationTime
from ms.Exception_Message
where SourceQueue = SourceQueue1;
open c1;
END;

Calling Oracle Stored Procedures from iReport 5.6 and JasperStudio 6.1

I have an Oracle stored procedure within the package and I'm successfully run this stored procedure from Oracle SQL DEVELOPER and TOAD.
When I do call in iReport and Jasper Studio - no errors at all but report is blank, no records.
Is any idea?
Here is what I'm doing:
Query Language Executor is PLSQL;
{call DA.PLZ0018_UNION_PR_PKG.UNION_PR_REPORT($P{ORACLE_REF_CURSOR}, $P{P_COMP_CODE}, $P{P_PAY_DATE})}
Stor proc in Oracle screen is attached:
Screen shot is attached
Simply reference the cursor fields by name. For example, to get your first field, 'COMPANY_CODE', create a report field by the same name, then add it to your report. I'm not sure if case matters.
As simple as this sounds, I had to work backwards from a simple test. Try this if you are stuck:
Create a procedure in your existing package:
1) PROCEDURE get_test (p_refcur OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_refcur FOR
SELECT 'Testing' as test from dual;
END;
2) Create a field named 'test'.
3) Add field to detail pane.

db2 from procedure run file

using IBM DB2 i would like to create a procedure that in case a table does not exist goes to file and start with create and insert statements written in that file. I cannot put all statements inside a procedure because there is just too many of them
my semi-pseudo code so far is
CREATE PROCEDURE KLEMENTEST.create_table
()
LANGUAGE SQL
begin atomic
if (not exists(select 'A' from syscat.tables where tabschema = 'TESTSCHEMA' and tabname='TESTTABLE')) then
--- run queries from file located in "c:\path\to\file.txt"
end if
end ;
any suggestions ??
thank you
There are several options:
1) Create an external stored procedure in Java or C that will execute the command that you want. For example
db2 -tf file.sql
Remember to execute DB2 with a profile (. db2profile). You will call this stored procedure after having test that the table does not exist.
2) Create the stored procedure, and read the content of the file that contains the ddl, then with the content, you create a dynamic SQL. You can read files via UTL_FILE module. However, this module is not available in Express-C edition. http://publib.boulder.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.apdv.sqlpl.doc/doc/r0053689.html
The general problem of this approach is the location of the file to "execute" in the file system, and also the stored procedure becomes platform dependent.

Calling an oracle stored procedure form COGNOS

In this link IBM they explain how to use an Oracle stored procedure with COGNOS.
They are doing :
create or replace package body project_pk as
procedure project_sp (tproj IN numeric, result1 in out project_type1) is
begin
open result1 for
select projects.projectid, projects.projecttype
from projects
where projects.projecttype=tproj;
end;
end;
/
With open result1 for they are opening the cursor explicitly. But, they do not seem to close it. Why is this?
You must return resuly set to Cognos. If you close the cursor then there are nor reuslts, right?
It's Cognos responsibility to close the cursor, once it finishes to pull the data from the SP.
In order to make you 100% sure that this is the case look at this link (totaly unrelated to Cognos):
Returning result Sets from SQL Server and Oracle
However, the sample you gave in your link, looks quite complex. Here is what I am using:
CREATE OR REPLACE PROCEDURE "COGNOS_SP" (
case_id in numeric,
po_refcur out sys_refcursor) is
BEGIN
open po_refcur for
select * FROM CASES WHERE CASE_ID = case_id;
END COGNOS_SP;

Resources