Stored Proc's/Packages Help
Ok all, again, being new to Oracle and trying to do a humble favor for a friend, I've come up with a problem that I'll need help on. Running these steps individually gets me pretty much the result that I'm looking for, minus some basic retooling with TSQL. However, I've tried to format this in the form of either a package/procedure and I just don't believe I'm doing it right. I've been reading the PL-SQL for Dummies, in addition to the latest Oracle 10G PDFs, but as much as I try, I just can't format the package right, even using v_ types and declaring. Below is the code, and even though I've listed tables, this has to be done dynamically and/or processed in memory. I know this may seem simple at best to those of you who understand Oracle, but to me, it's like a square peg in a round hole.
Would appreciate any and all comments and assistance. Thank you kindly for your perusal of this post (code below):
--STEP 1:
create table tbl1 as
SELECT ps.id1
,ps.id2
,ps.tdate
,NVL(ps.udate, SYSDATE + 1 )
,ps.tcode
,decode (y.nmtext,
'name1', 'nm1',
'name2', 'nm2',
'name3','nm3',
'name4','nm4',
'name5','nm5',
'name6','nm6',
'name7','nm7',
'name8','nm8')
,(SELECT COUNT(ps2.id1)
FROM tblhere ps2
WHERE ps2.id1 = ps.id1
AND ps2.id2 = ps.id2
AND ps2.tdate <= TO_DATE('03/01/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
AND NVL(ps2.udate, SYSDATE + 1) >= TO_DATE('02/01/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
GROUP BY ps2.id2) AS o_cnt
,(SELECT COUNT(ps3.id1)
FROM tblhere ps3
WHERE ps3.id1 = ps.id1
AND ps3.tcode = ps.tcode
AND ps3.tdate <= TO_DATE('03/01/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
AND NVL(ps3.udate, SYSDATE + 1) >= TO_DATE('02/01/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
GROUP BY ps3.tcode) AS a_cnt
,y.ntype as ntype
FROM tblhere ps
INNER JOIN tblz y
ON ps.id2 = y.thisid
WHERE ps.tdate <= TO_DATE('03/01/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
AND NVL(ps.udate, SYSDATE + 1 ) >= TO_DATE('02/01/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
AND tcode = 'placedhere'
AND y.ntype='testing'
order by id1, tdate
--STEP 2:
create table overages (
Mynum number,
MyID number)
--STEP 3:
insert into overages
select count(*) as Mynum, id1
from tbl1
group by id1
having count(id1) > 1
order by id1 desc
--STEP 4:
create table tbl2 (
nums number,
cid number,
ogid number,
adate date,
rdate date,
timer number,
mymode varchar2(10 Byte),
place varchar2(50 Byte),
og_cnt number,
mymode_cnt number,
namer varchar2(1 Byte))
--STEP 5:
insert into tbl2
select b.mynum, a.id1, a.id2,
a.tdate, NVL(a.udate, SYSDATE + 1),
a.tcode, a.nmtext, a.o_cnt,
a.a_cnt, a.ntype
from tbl1 a
inner join overages b
on a.id1 = b.myid
order by cid, adate
--STEP 6:
merge into tbl2 a
using (select rwd,
cid,
ogid,
min(rwd) over (partition by cid, adate, rdate) rwd_min,
adate,
rdate,
mymode, place,
from (select cid, rowid rwd,
last_value(d1 ignore nulls) over (partition by cid order by rdate range between unbounded preceding and current row) as adate,
first_value(d2 ignore nulls) over (partition by cid order by rdate range between current row and unbounded following) as rdate
from (select cid,
adate,
rdate,
case when abs(adate-lag(rdate) over (partition by cid order by rdate))<=1
then null else adate end d1,
case when abs(rdate-lead(adate) over (partition by cid order by rdate))<=1
then null else rdate end d2
from tbl2))) b
on (a.rowid=b.rwd)
when matched then update set a.adate=b.adate, a.rdate=b.rdate
delete where b.rwd!=b.rwd_min;
In general you should create the empty tables first as an installation step. Then in your PL/SQL code you would just do inserts, updates etc.
Also, a package is defined in two parts:
CREATE OR REPLACE PACKAGE whatever
AS
PROCEDURE p
( p_someparam INTEGER );
FUNCTION q
RETURN BOOLEAN;
END whatever;
CREATE OR REPLACE PACKAGE BODY whatever
AS
PROCEDURE p
( p_someparam INTEGER )
IS
BEGIN
dbms_output.put_line('Hello, World');
END p;
FUNCTION q
RETURN BOOLEAN
IS
BEGIN
RETURN dbms_random.value(0,10) < 5;
END q;
END whatever;
/
Similar Messages
-
Hi Guys ,
To Execute Packages deployed in Catalog , I have created a wrapper SP which internally calls catalog SP ( below is the code )
ALTER PROCEDURE [Publish].[usp_ExecutePackages]
@PackageName NVARCHAR(255)
, @ProjectFolder NVARCHAR(255)
, @ProjectName NVARCHAR(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Execution_id BIGINT ;
EXEC [SSISDB].[catalog].[create_execution] @package_name
= @PackageName
, @execution_id
= @Execution_id OUTPUT
, @folder_name
= @ProjectFolder
, @project_name
= @ProjectName
, @use32bitruntime=
True;
EXEC [SSISDB].[catalog].[set_execution_parameter_value]
@execution_id,
@object_type=50,
@parameter_name=N'SYNCHRONIZED',
@parameter_value=1
EXEC [SSISDB].[catalog].[start_execution] @Execution_id
Since i have multiple Packages , I am looping through list of PackageName and trying to pass package names to this SP by ExecureSQLTask inside ForLoop Container . But it errors out saying
"Cannot access the package or the package does not exist. Verify that the package exists and that the user has permissions to it.
BUt same Execute SQL task , if i keep it outside the ForLoop Container it works perfectly fine .
I am clueless , Please Please HELP me ASAP :(
Question :
How is that possible to execute same SP with same parameter outside Container , But not in SEQUENCE or FORLOOP or FOREACH Container ?
Also
How to make a master package to execute SSIS deployed packages via TSQL using catalog stored proc ?
Please help me out .
Thanks
Prasanna SelvarajuHi ,
After debugging i am getting parameter values as
{Extract - ARTL.dtsx\r\n} Unable to evaluate the expression.
Why do i get \r\n which i dont want in parameters .
Actually i pick the values of package name from a custom table . I check it there are no spaces in the cell.
Any IDEA WHY ? Please help
Finally it worked to call Wrapper Class for EXEC [SSISDB].[catalog].[create_execution]
stored procedure .
Basically , ERROR MESSAGE is culprit
"Cannot access the package or the package does
not exist. Verify that the package exists and that the user has permissions to it.
Above Message : causing us to think
its an Access issue , But actually when you pass parameter incorrectly even a " " space or "\n" extra to value, you will get that error .
Nothing related to access problem .
Actually , In the parameter which i was passing :
{Extract - ARTL.dtsx\r\n} --> String with Enter / Carriage Return and Break line was there
I have removed the Enter in that variable value .
Now its WORKING FINE ! Hurry :D :) -
Parse XML in a java stored proc
I am trying to parse an xml document in a java stored procedure. Just following my nose, I have developed a stored proc that works fine in development (outside the database using JRE 1.4.1) using the Xerces 2.5 parser. But, after having transferred the xerces xercesImpl.jar, xmlapis.jar, and my implementation class into oracle using loadjava when I call my stored proc the code throws an exception trying to build the document with an error like:
NoClassDef exception org.apache.xerces.jaxp.DocumentFactoryBuilderImpl
My Code looks like this:
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
InputStream is = getXMLAsInputStream(xml);
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( is );
... parse the document ....
catch (FactoryConfigurationError e) {
// unable to get a document builder factory
The exception caught is a FactoryConfigurtionError.
I'm not particularly attached to xerces, I'm really just looking for a way to parse XML inside my java stored proc, so any help to solve my problem, or an alternative suggestion will be greatly appreciated.
thanks
DaleI looked again and sure enough the xerces implementation classes were missing. I had run a .cmd file containing these two lines, but it looks like only the first one ran...
loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xml-apis.jar
loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xercesImpl.jar
Now I've got everything working fine with Xerces!
Dale -
BPC5.1 - Data manager package to Stored proc with custom return codes
Hi all,
Does anyone have experience passing the return codes from a stored procedure back into the eData "view status" package progress or event log details?
When my stored procedure throws errors, the offending SQL code shows up in the pacakge details, which is helpful. But what I'd really like is to structure my stored proc with return codes
0 = everything's wonderful
1 = invalid category / time combination
2 = unauthorized
3 = no data to process
And then handle these codes as either "completed" "warning" or "error" in the package progress.
And ideally, I'd like to put some meaningful message about the warnings & errors, directly into the log details, so the user can fix the problem themselves rather than ask the IT guy to trouble-shoot.
Any tips? I've started playing with using the on-complete, on-success, on-failure routing of different tasks within the DTSX package (SQL 2005), but I'm just working on a trial-and-error basis right now. (With # of errors = # of trials.)
Thanks,
TimIn case anyone's interested, I've solved this by tracking my return codes as a package variable.
Within the package, I have conditional logic moving from task to task, evaluating the return code to check for various conditions, and selecting which tasks to perform accordingly.
In the last task, I run a final stored procedure which posts some data (completion time & status) to a custom transaction log table, and then if the return code is not zero, I script and execute some SQL which I know will throw a "fake" error. The SQL statement itself includes the key information I want the end user to see. For example
Select InvalidEntitySelection [USEast1],TransactionID [12340] from ThisTableDoesntExist
Select UnauthorizedUser [Tim], TransactionID [12345] from ThisTableDoesntExist
Select WorkStatusIsLocked [USEast1 Actual 2008], TransactionID [12345] from ThisTableDoesntExist
It's not exactly elegant, but it gets the message across, which is all that I need. In this way, the end user sees that the package failed with an error, and when they look at the package details, they can see the problem. They can pass on the transaction ID to an administrator to look into the details, if they can't figure it out on their own.
Sorin, I never managed to figure out how to use a VB task to send the information back to the user, plus force the package to end in an error. I'm sure there's a way to do so, but this seems to work for my requirement.
I'm not entirely happy with the "fake error" approach, but I don't know if BPC has any support for "intentional" programming of errors in the DTS scripting toolset.
Thanks,
Tim -
Help with Stored Procs.
Hello All,
Orcl Version:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production"
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
I have a scenario, where I've to run the procedures from a package multiple times with different input parameter(key) primary key of one of the tables used inside the proc.
For ex,
pkg1
proc1(Key);
proc2(Key);
proc3(Key);
proc30(Key);
Engine(Main code) runs these procs multiple times with different params. Sometimes a proc runs more than 4000 times with different param value(key). I have 2 questions.
1. A proc when run for the first time, it is compiled and for the next time it will be in compiled form. I'm not sure how it works for the second run. Is the query in the proc cached and helps improve the performance?
2. Are there any ways to improve the performance?
Like, I'm hitting the base tables everytime a proc is run. Is there any advantage of creating MV's or something like that?
Thanks
Shank.Hi, Shank,
SamFisher wrote:
Orcl Version:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production ...
Thanks for including that!
I have a scenario, where I've to run the procedures from a package multiple times with different input parameter(key) primary key of one of the tables used inside the proc.
For ex,
pkg1
proc1(Key);
proc2(Key);
proc3(Key);
proc30(Key);
Engine(Main code) runs these procs multiple times with different params. Sometimes a proc runs more than 4000 times with different param value(key). I have 2 questions.
1. A proc when run for the first time, it is compiled and for the next time it will be in compiled form. Not usually. A stored procedure is compiled when it is created, that is, when you run the CREATE OR REPLACE PROCEDURE (or CREATE OR REPLACE PACKAGE) command.
It may be automatically re-compiled when you call it the first time. For example, if procedure A calls some other procedure B, and B has been re-compiled since A was created, then A will be re-compiled when you run it the first time.
I'm not sure how it works for the second run. Is the query in the proc cached and helps improve the performance? Performance may be a little faster after the first call, because the procedure, and the objects it references (such as table blocks) may already be cached in memory.
2. Are there any ways to improve the performance?
Like, I'm hitting the base tables everytime a proc is run. Is there any advantage of creating MV's or something like that? If the package body contains a BEGIN section, then that section is run the first time the package is used , but not again in the same session. You can use that section to initialize package variables (or SYS_CONTEXT variables, or global temporary tables) so you don't have to re-compute them every time you call the package.
For example, I have a package called pk_mail. The package body looks like this:
CREATE OR REPLACE PACKAGE BODY pk_mail
AS
mail_host_name VARCHAR2 (30);
PROCEDURE add_recipient -- First procedure
END send_to_all; -- Last procedure
-- The following is run the first time the package is used in a given session:
BEGIN
SELECT txt
INTO mail_host_name
FROM constant_tbl
WHERE ent_name = 'MAIL_HOST_NAME'
AND status_txt = 'ACTIVE'
AND ROWNUM = 1;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
mail_host_name := 'itd-smtp-out.foo.bar.com; -- Default value
END pk_mail;
/The package variable mail_host_name, which is used in various procedures in the package, is set the first time the package is used. After the first call, the code that gives it a value is not run again.
Edited by: Frank Kulash on Jul 6, 2012 1:21 PM
Added pk_mail example. -
Help....on stored procedure (or package)
Hi,
I have any problem to create stored procedure in Oracle, Can you help me?
I have to create a stored procedure (or package) in order to reserve the free rooms to the students in the period comprised between the DATE_START and DATE_END.
Table of the present rooms in building BL1 (RM): SEX 1 = M - SEX 2 = F SEX = 0 (ROOM WITHOUT SEX)
BL_ID.....FL_ID.......RM_ID.........SEX......RM_STD.....RM_CAT
BL1.........1..........101..............1........S........ROOM
BL1.........1..........102..............0........D........ROOM
BL1.........1..........103..............2........T........ROOM
BL1.........2..........201..............2........S........ROOM
BL1.........2..........202..............1........D........ROOM
BL1.........2..........203..............1........T........ROOM
BL1.........3..........301..............2........S........APARTMENT
BL1.........3..........302..............2........D........APARTMENT
BL1.........3..........303..............1........T........APARTMENT
BL1.........3..........304..............1........D........APARTMENT
BL1.........3..........305..............0........D........APARTMENT
Table of the students (EM):
EM_ID...........BL_ID.......FL_ID........RM_ID........COD_STUD
SABRINA..........BL1..........1............102.........524505
TAKEM............BL1..........1............103.........569673
SERAFINO.........BL1..........1............103.........589920
STELLA...........BL1..........1............102.........574659
CHIARA...........BL1..........1............101.........587845
VIDAL............BL1..........1............102.........602877
ROSARIA..........BL1..........2............202.........517070
LUCA.............BL1..........2............201.........602743
DANIELA..........BL1..........2............203.........602865
ANNAMARIA........BL1..........3............305.........588721
LUIGI............BL1..........3............304.........546517
Type of rooms (RM_STD):
RM_STD.......STD_EM........DESCRIPTION
D.............4..............DOUBLE
T.............6..............TRIPLE
S.............2..............SINGLE
Tables of the reservations carried out from the students (RMPCT):
EM_ID......BL_ID........FL_ID......RM_ID......DATE_START.......DATE_END.......COD_STUD
CHIARA......BL1.........1..........101.......11/02/2004.......12/02/2004.......587845
CHIARA......BL1.........1..........101.......03/02/2005.......16/02/2005.......587845
SERAFINO....BL1.........1..........102.......12/02/2004.......19/02/2004.......589920
VIDAL.......BL1.........1..........102.......16/02/2004.......01/03/2004.......602877
SERAFINO....BL1.........1..........103.......01/02/2004.......15/02/2004.......589920
TAKEM.......BL1.........1..........103.......04/02/2005.......10/02/2005.......569673
LUCA........BL1.........2..........201.......03/02/2005.......23/02/2005.......602743
ROSARIA.....BL1.........2..........202.......03/02/2005.......16/02/2005.......517070
DANIELA.....BL1.........2..........203.......03/02/2005.......04/02/2005.......602865
LUIGI.......BL1.........3..........301.......03/02/2005.......23/02/2005.......546517
VALERIA.....BL1.........3..........302.......12/02/2004.......16/02/2004.......515348
CHIARA......BL1.........3..........302.......05/02/2004.......15/02/2004.......587845
CHIARA......BL1.........3..........304.......10/02/2004.......12/02/2004.......587845
CHIARA......BL1.........3..........305.......20/01/2004.......04/02/2004.......587845
ANNAMARIA...BL1.........3..........305.......03/02/2005.......16/02/2005.......588721
INPUT PARAMETERS:
CREATE OR REPLACE Procedure RESERVE_ROOMS (stud_name varchar2,
cod_stud varchar2,
bl_in varchar2,
fl_in varchar2,
rm_in in varchar2,
sex_in varchar2,
date_start_in varchar2,
date_end_in varchar2)
CONDITIONS:
verify if there are students in table EM:
select count (1)
into v_appo
from em
where em_id = stud_name
and cod_stud = cod_stud;
if v_appo = 0 then
insert new student:
insert into em (em_id,cod_sud,sex)
values (stud_name,cod_stud,sex_in);
Now I must verify the free rooms in the period comprised between the DATE_START_IN and DATE_END_IN.
I tried this query: (seem correct...have you any idea?)
select bl_id,fl_id,rm_id,RM_STD
from rm
where (bl_id,fl_id,rm_id,RM_STD) not in (select a.bl_id,a.fl_id,a.rm_id,A.RM_STD
from rm a, rmpct b
where a.bl_id=b.bl_id
and a.fl_id=b.fl_id
and a.rm_id=b.rm_id
AND((b.date_start <= TO_DATE(date_start_in, 'dd-mm-YYYY')
AND b.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))
OR ( b.date_end <= TO_DATE(date_end_in, 'dd-mm-YYYY'))
AND b.date_end >= TO_DATE(date_start_in, 'dd-mm-YYYY')
OR ( b.date_start >= TO_DATE(date_start_in, 'dd-mm-YYYY')
and b.date_start <= TO_DATE(date_end_in, 'dd-mm-YYYY')
AND b.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))))
with this query I get all free rooms in period date_start_in - date_end_in, but I must,also,verify if there are double or triple rooms (reserved) with minus of 2 (double) or minus of 3 (triple) students. If there are I can reserved these rooms.
I tried to verify with these steps:
CREATE OR REPLACE VIEW COUNT_EM ( BL_ID,
FL_ID, RM_ID, NUMBER_EM ) AS
(SELECT rm.bl_id, rm.fl_id, rm.rm_id, COUNT(*) as numero_em
FROM em, rm
WHERE em.bl_id(+) = rm.bl_id
AND em.fl_id(+) = rm.fl_id
AND em.rm_id(+) = rm.rm_id
and rm.rm_std in ('S', 'D', 'T')
group by rm.bl_id, rm.fl_id, rm.rm_id)
CREATE OR REPLACE VIEW COUNT_RMPCT ( BL_ID,
FL_ID, RM_ID, STD_EM, NUMBER_RMPCT
) AS
SELECT rm.bl_id, rm.fl_id, rm.rm_id, rmstd.std_em, COUNT(*) as numero_rmpct
FROM rm, rmpct,rmstd
WHERE rmpct.bl_id(+) = rm.bl_id
AND rmpct.fl_id(+) = rm.fl_id
AND rmpct.rm_id(+) = rm.rm_id
and rm.rm_std=rmstd.rm_std
and rm.rm_std in ('S', 'D', 'T')
AND((rmpct.date_start <= TO_DATE(date_start_in', 'dd-mm-YYYY')
AND rmpct.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))
OR ( rmpct.date_end <= TO_DATE(date_end_in, 'dd-mm-YYYY'))
AND rmpct.date_end >= TO_DATE(date_start_in, 'dd-mm-YYYY')
OR ( rmpct.date_start >= TO_DATE(date_start_in, 'dd-mm-YYYY')
and rmpct.date_start <= TO_DATE(date_end_in, 'dd-mm-YYYY')
AND rmpct.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY')))
group by rm.bl_id, rm.fl_id, rm.rm_id, rmstd.std_em
AND FINALLY:
select a.bl_id, a.fl_id, a.rm_id, a.NUMBER_RMPCT, B.NUMBER_EM, a.std_em, (a.std_em - (a.NUMBER_RMPCT+B.NUMBER_EM)) RM_FREE
from COUNT_RMPCT a, COUNT_EM b
where a.bl_id=b.bl_id
and a.fl_id=b.fl_id
and a.rm_id=b.rm_id
if RM_FREE > 0 THEN there are free rooms (D or T) between those occupied in that period.
Now If the room (bl_in,fl_in,rm_in) is free I can reserve inserting it in the table RMPCT:
INSERT INTO rmpct (bl_id, fl_id, rm_id,em_id,cod_stud,date_start, date_end)
values(bl_in,fl_in,rm_in,stud_name,cod_stud,date_start_in,date_end_in);
If I haven't rm_in (can be null) I must reserve the first free room (random).
after these controls: I update table of the students:
UPDATE em
Set bl_id = BL_IN,fl_id= FL_IN,rm_id=rm_in
where em_id=stud_name
and cod_stud=cod_stud;
Finally I must make a control on the sex of the room, because there are rooms that have sex=0
if RM.SEX <> 0 then
null
else
if rm_cat = 'ROOM' then
UPDATE rm
set sex = sex_in
where bl_id = in
and fl_id = in
and rm_id = in;
if rm_cat = 'APARTMENT' then (update on all rooms)
UPDATE rm
set sex = sex_in
where bl_id = in
and fl_id = in;
IF v_appo > 0 then
Same controls except: insert into em (em_id,cod_sud,sex)
values (stud_name,cod_stud,sex_in);
How I can insert in one stored procedure (or package) all these instructions and controls?
Thanks in advance!In the following demonstation, I have changed the names of some of your variables, in order to standardize them. I have prefaced input parameters with p_ and local variables with v_ and followed them with the name of the column that they are associated with when appropriate. This avoids conflicts with any column names and makes the code easier to read and follow. I have also used table_name.column_name%type to specify the data type associated with the variables instead of using varchar2. That way, if the data type of the columns changes, the code does not have to be updated. This is standard practice.
In your first insert statement, you have attempted to insert sex into the em table, but there is no sex column in the em table data that you displayed, so I removed the sex.
Instead of using a complicated mess of views and such to check whether there is a room available and then assign it, I have used just one select statement to select an available room and used an exception clause that handles a no_data_found exception to deal with when there is no room available.
I have greatly simplified your checking of dates within that select statement.
You were on the right track with the outer joins and grouping and checking for single, double, or triple rooms. Instead of count, I have used sum and nvl2, so that only the occupied rooms are counted and the rows generated by the outer join are zeroes.
I have used the nvl function to allow for null values in the input parameters, so that any room can be selected. I used dbms_random.random to ensure that the rows are ordered randomly, but you can leave that out if it is really not that critical that the result be truly random and any row will do. I have used rownum=1 in an outer query to select just one row.
When you select from a table in pl/sql, you have to select into something. You cannot just issue a select statement, then use an if statement to compare some value in the select statement. For example, you cannot use "if rm.sex ..." you have to select rm.sex into a variable, like v_sex, then use "if v_sex ...". So, I have selected the result of the select statement into local variables, then used those variables for comparisons. I have also used those variables for inserting and updating the appropriate tables, rather than just using the original input parameters, since some of them may have been null.
In the example below, I have demonstrated how the procedure rejects an unavailable room, accepts a specific available room, and randomly assigns a room.
-- procedure:
scott@ORA92> CREATE OR REPLACE PROCEDURE reserve_rooms
2 -- input parameters:
3 (p_em_id IN em.em_id%TYPE,
4 p_cod_stud IN em.cod_stud%TYPE,
5 p_bl_id IN rm.bl_id%TYPE,
6 p_fl_id IN rm.fl_id%TYPE,
7 p_rm_id IN rm.rm_id%TYPE,
8 p_sex IN rm.sex%TYPE,
9 p_date_start IN VARCHAR2,
10 p_date_end IN VARCHAR2)
11 AS
12 -- local variables:
13 v_appo INTEGER;
14 v_bl_id rm.bl_id%TYPE;
15 v_fl_id rm.fl_id%TYPE;
16 v_rm_id rm.rm_id%TYPE;
17 v_rm_cat rm.rm_cat%TYPE;
18 v_sex rm.sex%TYPE;
19 BEGIN
20 -- verify if the student is in table em:
21 SELECT COUNT (*)
22 INTO v_appo
23 FROM em
24 WHERE em_id = p_em_id
25 AND cod_stud = p_cod_stud;
26 -- if the student is not in table em, then insert new student:
27 IF v_appo = 0 THEN
28 INSERT INTO em (em_id, cod_stud)
29 VALUES (p_em_id, p_cod_stud);
30 END IF;
31 BEGIN
32 -- find available room:
33 SELECT bl_id, fl_id, rm_id, sex, rm_cat
34 INTO v_bl_id, v_fl_id, v_rm_id, v_sex, v_rm_cat
35 FROM (SELECT rm.bl_id, rm.fl_id, rm.rm_id, rm.sex, rm.rm_cat
36 FROM rmpct, rm
37 WHERE rm.bl_id = rmpct.bl_id (+)
38 AND rm.fl_id = rmpct.fl_id (+)
39 AND rm.rm_id = rmpct.rm_id (+)
40 AND rm.bl_id = NVL (p_bl_id, rm.bl_id)
41 AND rm.fl_id = NVL (p_fl_id, rm.fl_id)
42 AND rm.rm_id = NVL (p_rm_id, rm.rm_id)
43 AND (rm.sex = p_sex OR rm.sex = 0)
44 AND rmpct.date_start (+) <= TO_DATE (p_date_end, 'DD-MM-YYYY')
45 AND rmpct.date_end (+) >= TO_DATE (p_date_start, 'DD-MM-YYYY')
46 GROUP BY rm.bl_id, rm.fl_id, rm.rm_id, rm.sex, rm.rm_cat, rm.rm_std
47 HAVING SUM (NVL2 (rmpct.rm_id (+), 1, 0))
48 < DECODE (rm_std, 'S', 1, 'D', 2, 'T', 3)
49 ORDER BY DBMS_RANDOM.RANDOM)
50 WHERE ROWNUM = 1;
51 -- reserve room:
52 INSERT INTO rmpct (bl_id, fl_id, rm_id, em_id, cod_stud, date_start, date_end)
53 VALUES (v_bl_id, v_fl_id, v_rm_id, p_em_id, p_cod_stud,
54 TO_DATE (p_date_start, 'DD-MM-YYYY'),
55 TO_DATE (p_date_end, 'DD-MM-YYYY'));
56 -- update students:
57 UPDATE em
58 SET bl_id = v_bl_id, fl_id = v_fl_id, rm_id = v_rm_id
59 WHERE em_id = p_em_id
60 AND cod_stud = p_cod_stud;
61 -- update sex of room or apartment floor:
62 IF v_sex = 0 THEN
63 IF v_rm_cat = 'ROOM' THEN
64 UPDATE rm
65 SET sex = p_sex
66 WHERE bl_id = v_bl_id
67 AND fl_id = v_fl_id
68 AND rm_id = v_rm_id;
69 ELSIF v_rm_cat = 'APARTMENT' THEN
70 UPDATE rm
71 SET sex = p_sex
72 WHERE bl_id = v_bl_id
73 AND fl_id = v_fl_id;
74 END IF;
75 END IF;
76 EXCEPTION
77 -- if no room is available:
78 WHEN NO_DATA_FOUND THEN
79 RAISE_APPLICATION_ERROR (-20001, 'Sorry, there is no such room available.');
80 END;
81 END reserve_rooms;
82 /
Procedure created.
scott@ORA92> SHOW ERRORS
No errors.
-- rejects unavailable room of wrong sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, 'BL1', 1, 101, 2, '04-02-2005', '10-02-2005')
BEGIN reserve_rooms ('BARBARA', 654321, 'BL1', 1, 101, 2, '04-02-2005', '10-02-2005'); END;
ERROR at line 1:
ORA-20001: Sorry, there is no such room available.
ORA-06512: at "SCOTT.RESERVE_ROOMS", line 79
ORA-06512: at line 1
-- accepts available room of same sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, 'BL1', 1, 103, 2, '04-02-2005', '10-02-2005')
PL/SQL procedure successfully completed.
-- assigns random available room of same or no sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, NULL, NULL, NULL, 2, '11-02-2005', '23-02-2005')
PL/SQL procedure successfully completed.
-- results:
scott@ORA92> -- one and only one row added to em table:
scott@ORA92> SELECT * FROM em WHERE em_id = 'BARBARA'
2 /
EM_ID BL_I FL_ID RM_ID COD_STUD
BARBARA BL1 1 102 654321
scott@ORA92> -- rooms reserved and other people who have reserved same room
scott@ORA92> -- (there are 3 who reserved a double room, but only 2 at a time):
scott@ORA92> SELECT *
2 FROM rmpct
3 WHERE (bl_id, fl_id, rm_id) IN
4 (SELECT bl_id, fl_id, rm_id
5 FROM rmpct
6 where em_id = 'BARBARA')
7 /
EM_ID BL_ FL_ID RM_ID DATE_STAR DATE_END COD_STUD
BARBARA BL1 1 102 11-FEB-05 23-FEB-05 654321
SERAFINO BL1 1 102 12-FEB-04 19-FEB-04 589920
VIDAL BL1 1 102 16-FEB-04 01-MAR-04 602877
SERAFINO BL1 1 103 01-FEB-04 15-FEB-04 589920
TAKEM BL1 1 103 04-FEB-05 10-FEB-05 569673
BARBARA BL1 1 103 04-FEB-05 10-FEB-05 654321
6 rows selected.
scott@ORA92> -- rooms reserved are all correct sex
scott@ORA92> -- (note that room 102 was updated from 0 to 2):
scott@ORA92> SELECT *
2 FROM rm
3 WHERE (bl_id, fl_id, rm_id) IN
4 (SELECT bl_id, fl_id, rm_id
5 FROM rmpct
6 where em_id = 'BARBARA')
7 /
BL_ FL_ID RM_ID SEX R RM_CAT
BL1 1 102 2 D ROOM
BL1 1 103 2 T ROOM
scott@ORA92> -
Oracle Packages/Stored Proc and VB
Hello,
I have a new assignment that I have to start at the client site ASAP. The client wants all the Sql in Oracle Stored Procs/Packages and VB being the front end. I am used to embedding my sql statements in my VB apps and connecting through ADO's but the client does not want embedded sql statements. My question is this, when I make a connection, in accessing the cursor, do I have to loop through the cursor and store the data in an ADO recordset or do I have to connect to the cursor and manipulate the data directly? Please give example.
The DB is Oracle 9i
ThanksYou are doing the right thing, there are examples of how to process result sets from stored procedures, including ASP/ADO at Asktom here
-
Java stored proc from proxy Java classes generated from a web service?
Hi gurus,
I have searched "Java Stored Procedure" on this forum but could not find what I am looking for, so I have to post again.
I need to use a web service and my client app is written in PowerBuilder 11 (Sybase), which claims that it will create a datawindow from a web service. Well, it turned out that PB can only handle simple stuff (it works with a very simple wsdl from the internet) but can't handle more complex ones that we need to use. So I am thinking about using Oracle JDeveloper(JDev) to create the web service proxy for the web service and then load it into Oracle as a Java stored procedure so that PowerBuilder can call the procedure. JDev succsfully generated the proxy and a few Java classes. My question is, do I need to load all the classes into the database? If yes, will the reference to the package work? For example, in a JDev generated class (the soap client class), it has package MyJdev.proxy; at the top. Or, will it work if I load all the classes included in package /MyJdev/proxy into the database?
Thank you very much for any help.
BenFor the java stored proc called from pl/sql, the example above that uses dynamic sql should word :
CREATE OR REPLACE PACKAGE MyPackage AS
TYPE Ref_Cursor_t IS REF CURSOR;
FUNCTION get_good_ids RETURN VARCHAR2 ;
FUNCTION get_plsql_table_A RETURN Ref_Cursor_t;
END MyPackage;
CREATE OR REPLACE PACKAGE BODY MyPackage AS
FUNCTION get_good_ids RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'MyServer.getGoodIds() return java.lang.String';
FUNCTION get_plsql_table_A RETURN Ref_Cursor_t
IS table_cursor Ref_Cursor_t;
good_ids VARCHAR2(100);
BEGIN
good_ids := get_good_ids();
OPEN table_cursor FOR 'SELECT id, name FROM TableA WHERE id IN ( ' | | good_ids | | ')';
RETURN table_cursor;
END;
END MyPackage;
public class MyServer{
public static String getGoodIds() throws SQLException {
return "1, 3, 6 ";
null -
I have a stored proc that is defined as
CREATE or REPLACE
PROCEDURE ABC
(linkid IN CHAR,
Year_in IN DATE,
Method_in IN CHAR,
Date_out OUT DATE,
average_out OUT NUMBER)
is
begin
end;
another partially completed stored proc that returns a ref
cursor defined as follows:
create or replace package zzz
as
type cursorType is ref cursor;
end;
create or replace function test return zzz.cursortype
as
date_OUT date;
Average_OUT number;
l_cursor zzz.cursorType;
CURSOR temp_cur is
SELECT l.linkid, L.routenumber, ABC(l.linkid,
to_date('01/01/2000', 'mm/dd/yyyy'),
'2',
date_OUT,
average_OUT)
FROM LINK l
WHERE l.LINKID <= '010999';
begin
open temp_cur;
end;
inside test (which I need help completing), how can I refer to
the date_out and the average_out params returned by ABC() so
that these values are in turn passed to the cursortype defined
in package zzz?
Thanks in advance.Try rewriting your abc proceudre as two functions, abc1 and
abc2, and rewriting your test function as a test procedure. See
if you can fill in the blanks prefaced by hyphens -- in the
following code:
CREATE OR REPLACE FUNCTION abc1
(linkid IN CHAR,
year_in IN DATE,
method_in IN CHAR)
RETURN DATE
IS
date_out DATE;
BEGIN
SELECT --
INTO date_out
FROM --
WHERE --;
--or
date_out := --;
RETURN date_out;
END abc1;
CREATE OR REPLACE FUNCTION abc2
(linkid IN CHAR,
year_in IN DATE,
method_in IN CHAR)
RETURN NUMBER
IS
average_out NUMBER;
BEGIN
SELECT AVG (--)
INTO average_out
FROM --
WHERE --
GROUP BY --;
--or
average_out := --;
RETURN average_out;
END abc2;
CREATE OR REPLACE PACKAGE zzz
AS
TYPE cursortype IS REF CURSOR;
PROCEDURE test
(temp_cur OUT cursortype);
END zzz;
CREATE OR REPLACE PACKAGE BODY zzz
AS
PROCEDURE test
(temp_cur OUT cursortype)
IS
BEGIN
OPEN temp_cur
FOR
SELECT l.linkid,
l.routenumber,
abc1 (l.linkid,
TO_DATE ('01/01/2000', 'mm/dd/yyyy'),
'2'),
abc2 (l.linkid,
TO_DATE ('01/01/2000', 'mm/dd/yyyy'),
'2')
FROM link l
WHERE l.linkid <= '010999';
END test;
END zzz;
SQL> VARIABLE g_ref REFCURSOR;
SQL> EXEC zzz.test (:g_ref);
SQL> PRINT g_ref -
Calling stored proc from java using ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc �
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is �
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Calling stored proc from java to return ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc ?
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is ?
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Stored proc returns zero result
Hello, please help me. I am quite new to oracle stored
procedures. I have a proc that returns data to cfm but it keeps
giving zero results. But if i don't use stored proc, the same query
gives me something. please help. my stored proc and cfm goes
something like below:
************************************ stored procedures
CREATE OR REPLACE PACKAGE PACK_REFCURSOR_NHM_TRANSACTION AS
TYPE TRANS_TableRows IS REF CURSOR;
PROCEDURE REFCUR_NHM_TRANSACTION (
IN_sTMPACC IN varchar2,
IN_sITEM_TYPES IN varchar2,
OUT_TRANS OUT TRANS_TableRows);
END PACK_REFCURSOR_NHM_TRANSACTION ;
CREATE OR REPLACE PACKAGE BODY PACK_REFCURSOR_NHM_TRANSACTION
AS
PROCEDURE REFCUR_NHM_TRANSACTION (
IN_sTMPACC IN varchar2,
IN_sITEM_TYPES varchar2,
OUT_TRANS OUT TRANS_TableRows)
IS
BEGIN
OPEN OUT_TRANS FOR
SELECT T.TRANSACTION_ID, T.TRANSACTION_TYPE,
T.TRANSACTION_DATE, T.TRANSACTION_TIME,
T.ITEM_CODE, 0 OE_DETAIL_ID,
T.QUANTITY, T.LIST_PRICE, T.DISCOUNT, T.SALE_PRICE,
T.GST_AMOUNT, 'I' INSURER_TYPE
FROM NHM_TRANSACTION T
WHERE DISPENSED_FLG = 'Y'
AND T.ACCOUNT_ID = IN_sTMPACC
AND T.TRANSACTION_TYPE IN ('01','02', '09')
AND NVL(T.STATUS,'F') != 'C'
AND T.BILLED_FLG = 'N'
AND T.ITEM_TYPE IN (IN_sITEM_TYPES)
AND T.BILL_ITEM_FLG = 'Y'
UNION ALL
SELECT T.OE_TRANSACTION_ID TRANSACTION_ID, TRANSACTION_TYPE,
T.TRANSACTION_DATE,
T.TRANSACTION_TIME, NVL(T.ITEM_CODE,T.PACKAGE_CODE)
ITEM_CODE, T.OE_DETAIL_ID,
T.QUANTITY, T.LIST_PRICE, T.DISCOUNT, T.SALE_PRICE,
T.GST_AMOUNT, 'S' INSURER_TYPE
FROM NHC_OE_TRANSACTION T, NHC_MASTER_ITEM M, NHM_PACKAGE P
WHERE T.ACCOUNT_ID = IN_sTMPACC
AND T.ITEM_CODE = M.ITEM_CODE(+)
AND T.PACKAGE_CODE = P.PACKAGE_CODE(+)
AND (DECODE(T.ITEM_CODE,NULL,P.BILL_OPTION,M.BILL_OPTION) in
('P','O','F'))
AND NVL(T.STATUS,'F') != 'C'
AND T.BILLED_FLG = 'N'
AND ((T.TRANSACTION_TYPE = '09' AND STATUS IN ('P','R'))
OR T.TRANSACTION_TYPE IN ('01','02','11','12', '10'))
AND T.BILL_ITEM_FLG = 'Y'
AND T.ITEM_TYPE IN (IN_sITEM_TYPES) ;
END REFCUR_NHM_TRANSACTION ;
END PACK_REFCURSOR_NHM_TRANSACTION ;
*************** the cfm code (note: i am using coldfusion
MX************
<cfstoredproc datasource="#application.datasource#"
procedure="NSCOCT.PACK_REFCURSOR_NHM_TRANSACTION.REFCUR_NHM_TRANSACTION">
<cfprocparam type="IN" cfsqltype="CF_SQL_VARCHAR"
value="#TMPACC#" dbvarname="IN_sTMPACC">
<cfprocparam type="IN" cfsqltype="CF_SQL_VARCHAR"
value="#QRYLOCITEM.ITEM_TYPE#" dbvarname="IN_sITEM_TYPES">
<cfprocresult name="getPrescItems">
</cfstoredproc>
***** i dumped getPrescItems and returns no data. it's
suppose to return something . Any help is much appreciated. Thank
you. *********just an update. i found out that it has something to do with
the condition "IN". the values there is supposed to be a list (e.g.
a,b,c,d,e,f,g). What I suspect is that when in stored proc, it
interprets in the query as "IN('a,b,c,d,e,f,g')" instead of
"IN('a','b','c','d','e','f','g')" which is what I actually want.
I have also tried the quotedvaluelist in cfm but still no
result, so i suspect again, using quotedvaluelist, that it
interprets in the proc as "IN(''a','b','c','d','e','f','g'')".
Can anybody help me whit this so i can have the proc
interpret my IN condition as "IN('a','b','c','d','e','f','g')"?
Thanks. -
HI, I have created a stored proc in oracle similar below:
CREATE OR REPLACE PACKAGE PACK_REFCURSOR_NHM_TRANSACTION AS
TYPE TRANS_TableRows IS REF CURSOR
RETURN NHM_TRANSACTION%ROWTYPE;
PROCEDURE REFCUR_NHM_TRANSACTION (
IN_sTMPACC IN string,
IN_sITEM_TYPES IN string,
OUT_TRANS OUT TRANS_TableRows);
END PACK_REFCURSOR_NHM_TRANSACTION ;
-- the above works fine
--but this one below has the error when
CREATE OR REPLACE PACKAGE BODY PACK_REFCURSOR_NHM_TRANSACTION
AS
PROCEDURE REFCUR_NHM_TRANSACTION (
IN_sTMPACC IN string,
IN_sITEM_TYPES IN string,
OUT_TRANS OUT TRANS_TableRows) IS
BEGIN
OPEN OUT_TRANS FOR
SELECT T.TRANSACTION_ID, T.TRANSACTION_TYPE,
T.TRANSACTION_DATE, T.TRANSACTION_TIME,
T.ITEM_CODE, 0 OE_DETAIL_ID,
T.QUANTITY, T.LIST_PRICE, T.DISCOUNT, T.SALE_PRICE,
T.GST_AMOUNT, 'I'INSURER_TYPE
FROM NHM_TRANSACTION T
WHERE DISPENSED_FLG = 'Y'
AND T.ACCOUNT_ID = IN_sTMPACC
AND T.TRANSACTION_TYPE IN ('01','02', '09')
AND NVL(T.STATUS,'F') != 'C'
AND T.BILLED_FLG = 'N'
AND T.ITEM_TYPE IN (IN_sITEM_TYPES)
AND T.BILL_ITEM_FLG = 'Y'
UNION ALL
SELECT T.OE_TRANSACTION_ID TRANSACTION_ID, TRANSACTION_TYPE,
T.TRANSACTION_DATE,
T.TRANSACTION_TIME, NVL(T.ITEM_CODE,T.PACKAGE_CODE)
ITEM_CODE, T.OE_DETAIL_ID,
T.QUANTITY, T.LIST_PRICE, T.DISCOUNT, T.SALE_PRICE,
T.GST_AMOUNT, 'S' INSURER_TYPE
FROM NHC_OE_TRANSACTION T, NHC_MASTER_ITEM M, NHM_PACKAGE P
WHERE T.ACCOUNT_ID = IN_sTMPACC
AND T.ITEM_CODE = M.ITEM_CODE(+)
AND T.PACKAGE_CODE = P.PACKAGE_CODE(+)
AND (DECODE(T.ITEM_CODE,NULL,P.BILL_OPTION,M.BILL_OPTION) in
('P','O','F'))
AND NVL(T.STATUS,'F') != 'C'
AND T.BILLED_FLG = 'N'
AND ((T.TRANSACTION_TYPE = '09' AND STATUS IN ('P','R'))
OR T.TRANSACTION_TYPE IN ('01','02','11','12', '10'))
AND T.BILL_ITEM_FLG = 'Y'
AND T.ITEM_TYPE IN (IN_sITEM_TYPES) ;
END REFCUR_NHM_TRANSACTION ;
END PACK_REFCURSOR_NHM_TRANSACTION ;
--this gives error: PLS-00382: expression is of wrong type
but when i tried to change the query similar to this:
OPEN OUT_TRANS FOR
SELECT T.*
FROM NHM_TRANSACTION T
WHERE DISPENSED_FLG = 'Y'
AND T.ACCOUNT_ID = IN_sTMPACC
AND T.TRANSACTION_TYPE IN ('01','02', '09')
AND NVL(T.STATUS,'F') != 'C'
AND T.BILLED_FLG = 'N'
AND T.ITEM_TYPE IN (IN_sITEM_TYPES)
AND T.BILL_ITEM_FLG = 'Y' ;
--that worked fine. what i found out is the proc doesn't seem
to work with complicated queries. instead it works only in
something similar to SELECT T.*? and not when individual fields are
extracted? I can't understand why? can anyone help me with this>
thanks.I think what is hapenning is that you are declaring the
reference cursor in your package spec as a "strong" type as a
rowtype of table NHM_TRANSACTION. However, in your OPEN FOR SELECT
statement, you are selecting columns that do not exist in the the
NHM_TRANSACTION table, such as 0 OE_DETAIL_ID, 'I'INSURER_TYPE,
etc.
You would be much better off to declare your reference cursor
as a "weak" type so that your OPEN FOR SELECT statement actually
defines the return structure:
TYPE TRANS_TableRows
IS REF CURSOR;
In other words, leave off the RETURN NHM_TRANSACTION%ROWTYPE
in your ref cursor declaration, and you would probably be OK
(assuming, of course, that all of the columns selected in your
UNION statements are like data types).
Phil -
Calling stored proc via services
I would be grateful if you could help me in resolving a technical issue in CMS(stellent).
We have a requirement that we need to call a stored procedure through services .The stored proc takes an input argument and returns a result set and has a defination that starts like
create or replace
PACKAGE BODY GETPROJECTPCKG IS
PROCEDURE PROC_RPU (rpu_list_count IN number, temp_project_cursor OUT project_ref_cursor) IS.
I've defined a service call like
<tr>
<td>GET_RPU_INFO</td>
<td>DocService
33
RECENTPROJECTUPDATE
null
null<br>
null</td>
<td>5:QgetRpuNames:temp_project_cursor::null</td>
</tr>
And below is how I've called the procedure
<tr>
<td>QgetRpuNames</td>
<td>{call GETPROJECTPCKG.PROC_RPU(?)}</td>
<td>rpu_list_count int</td>
</tr>
i tried calling procedure as below also ..
<tr>
<td>QgetRpuNames</td>
<td>{call GETPROJECTPCKG.PROC_RPU(?,?)}</td>
<td>rpu_list_count int
temp_project_cursor out:resultset</td>
</tr>
As per my understanding the temp_project_cursor which is the resultset that would be returned from procedure should be available on the template specified.
But while executing the service I am getting an error :
Unable to create result set for query 'QgetRpuNames({call GETPROJECTPCKG.PROC_RPU(10)})'. ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PROC_RPU'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored)
Can you please assist.Hey
if this is still an issue please refert "Call Stored Procedure from Oracle Fusion ECM (Stellent) " at http://www.corecontentonly.com/index.php/downloads/. Jason has shared a component that you can make use of.
cheers,
sapan -
Hi ,
I am trying to use a simple java stored procedure.
This is my .class file containing the stored proc
package Flight;
import java.awt.*;
import java.sql.*;
public class Frame1 {
public static String hello()
{ return "Hello "; }
public static String get_ID(int i) throws SQLException
String str = new String();
System.out.println(i);
try {
// Load the Oracle JDBC driver
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the
connection URL.
Connection conn =
DriverManager.getConnection
("jdbc:oracle:oci8:@BIS.NE.TELECOM.FEDEX.COM", "scott",
"tiger");
PreparedStatement pstmt = conn.prepareCall(" Select name
from t_tab where id = 12 " );
// pstmt.setInt(1,12);
ResultSet rst = pstmt.executeQuery();
str = rst.getString(1);
catch(Exception ex)
{ System.out.println("Error in connection " +
ex.getMessage() ); }
return str;
The following is the .sqlj file
import sqlj.runtime.*;
import sqlj.runtime.ref.*;
import sqlj.runtime.ref.DefaultContext;
import oracle.sqlj.runtime.Oracle;
import java.sql.*;
#sql iterator MyIter (String nam);
public class FlightHello
public static void main(String args[]) throws SQLException
ResultSet str ;
try
dbconnect();
String str1 = new String();
#sql { select TravelLogic.Hello() into :str1 from dual
System.out.println(str1);
catch(Exception e)
{ System.err.println("Error in dbconnect : " +
e.getMessage()); }
try {
String str2 = new String();
MyIter val;
int i= 12;
#sql { select TravelLogic.get_ID(12) into :str2
from t_tab } ;
System.out.println(str2);
catch(Exception a)
{System.err.println("Error in travelLogic: " +
a.getMessage()); }
public static void dbconnect() throws Exception
try {
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
catch (SQLException e)
{ System.out.println("error in sqlj" + e.getMessage()); }
String url = "jdbc:oracle:oci8:@BIS.NE.TELECOM.FEDEX.COM";
String user = "scott"; String pwd = "tiger";
DefaultContext.setDefaultContext(
new DefaultContext(url,user,pwd,false));
when i run the program i get the following error
Hello
Error in travelLogic: no rows found for select into statement
But actually there is data in the table t_tab, an object table
with attributes id number, name vc(50)
please help with this problem. I have been trying to fix this for
the last two days but i am not able to.
with regards
jaya
nullWell, one problem is that you are trying to use the OCIdriver in
a java stored procedure. You should be using the kprb driver,
which is called like:
Connection conn = new OracleDriver().defaultConnection();
Refer to the Java Stored Procedures manual that is part of the
server docs for more details.
null
Maybe you are looking for
-
Ken Burns, De-Interlacing, FCE, iMovie and Adobe Premiere
I've read countless articles, bought lynda training with Larry Jordan, pre-edited photos in Photoshop, done all kinds of experiments with filters and tried other movie editor packages. FCE with the Ken Burns effect is just very tricky and time consum
-
Partial wakelock in Adobe Air for Android
I'm developing Adobe Air (for Android) application which is intended to be constantly on. App has event based operations. However, when phone enters to sleep mode app is able to perform only one or few events in a second which is not good enough. AIR
-
I just got a ipod mini (i shouldve stuck w/ dell)
after a lot of aggravation, my laptop (dell inspiron 9200, xp) found the ipod. the icon came up ONCE tonight, that it was found.. now i have itunes set up, but theres no ipod connected.. meanwhile its plugged in charging. im very p'ed off. and i shou
-
Change width of all textfields?
Hi, Let's say that I have 10 textfields on my SubForm. How can I change with javasctipt on initialisation of SubForm(s2) ALL textfields.w = "3in"; s2.w = "3in"; s2.Tekstveld2.w = "3in"; tnx.
-
I have a whole bunch of pages in the recently worked on window that have been moved .I can't see the whole path for them so when I go to open one it points me to the folder that was moved and I can't open it.It's kind of a pain accidentally picking t