OCI 22303 exception - Pass object to type Record in oracle procedure
Recently i had my first encounter with ODP.NET and Oracle. I'm developing a a datalayer that can access a stored procedure on an Oracle database.
The problem i'm having is the following:
I'm using this method to pass my parameters to the procedure: http://www.codeproject.com/KB/cs/CustomObject_Oracle.aspx
I have also attempted this approach:
http://developergeeks.com/article/48/3-steps-to-implement-oracle-udt-in-odpnet
I always get the message (litteraly):
Oracle.DataAccess.Client.OracleException: OCI-22303: type "e;PAC$WEBSHOP_PROCS"."CUSTOMER_IN_RECTYPE" not found.
It sounds weird to me, but what are the "es doing here in the error message I see?
Some code i use:
OracleParameter objParam = new OracleParameter
OracleDbType = OracleDbType.Object,
Direction = ParameterDirection.Input,
ParameterName = "PAC$WEBSHOP_PROCS.P_CUSTOMER_IN",
UdtTypeName = "PAC$WEBSHOP_PROCS.WEBSHOP_PROCS.CUSTOMER_IN_RECTYPE",
Value = card
The information i have about the Oracle procedure:
CREATE OR REPLACE PACKAGE PAC$WEBSHOP_PROCS IS
TYPE CUSTOMER_IN_RECTYPE IS RECORD
(CUS_STO_IDENTIFIER NUMBER(2)
,CUS_IDENTIFIER NUMBER(6)
,CH_IDENTIFIER NUMBER(2)
,CH_CARD_VERSION NUMBER(1)
PROCEDURE PRC$WS_VALIDATE_CARD
(P_CUSTOMER_IN IN PAC$WEBSHOP_PROCS.CUSTOMER_IN_RECTYPE
,P_RETURN_CODE IN OUT NUMBER
Any help to cover my problem would be greatly appreciated.
Thx
Edited by: 836497 on 14-feb-2011 4:36
The only way to call it as is would be via an anonymous plsql block, where you create the record type inside the block. Interacting with the block via ODP would be limited to scalar values.
Here's a PLSQL example just to demonstrate. Here, v1 and v2 are bind variables of scalar type, which you'd setup/bind via ODP instead of the SQL prompt as I did, but I thought this might keep things simpler for the example.
The other choice would be to write a wrapper procedure that takes type OBJECT that you can call from ODP, and inside that procedure convert them to/from RECORD and call the original procedure.
Hope it helps,
Greg
SQL> drop package somepack;
Package dropped.
SQL> create package somepack as
2 type somerectype is record(n1 number);
3 function somefunc (v1 somerectype) return somerectype;
4 end;
5 /
Package created.
SQL>
SQL> create package body somepack as
2 function somefunc (v1 somerectype) return somerectype is
3 begin
4 return v1;
5 end;
6 end;
7 /
Package body created.
SQL>
SQL>
SQL> var v1 number;
SQL> exec :v1 := 5;
PL/SQL procedure successfully completed.
SQL> var v2 number;
SQL>
SQL>
SQL> declare
2 localvar1 somepack.somerectype;
3 localvar2 somepack.somerectype;
4 begin
5 localvar1.n1 := :v1;
6 localvar2 := somepack.somefunc(localvar1);
7 :v2 := localvar2.n1;
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> print v2;
V2
5
SQL>
Similar Messages
-
How to pass a multidimensional array to an Oracle procedure?
How can I pass a multidimensional array to oracle array?
Thanx in anticipation,Look in to passing user defined type back and forth to Oracle. Any type that oracle supports, you can constract on the java side and send it across. Look into the SQLData class.
-
How to pass the arguments dynamically to a Oracle procedure.
Hi all..
How to pass the arguments dynamically to a procedure.
Thanks in Advance.I have a concurremt program which has 5 parameters right now. The user can add more parameters from front end as per their requirement.
So that time.. the 6th parameter has to add to my procedure dynamically.
Thanks. -
OCI-22303: type ""."DISCREPTABTYP"
OCI-22303: type ""."DISCREPTABTYP" not found:BEGIN
timeKeeper_package.discrepancy2(:unit, :startdate, :enddate, :unknown_tb, :belongWork_tb, :floatIn_tb, :floatOut_tb);
END;
I am getting the above error when I am running at OCI program through a web application. This did work on another server 2 years ago. Project got put on hold and now that DB on that server can be restarted, I need to install in on a new server and db. I created this type for a user and granted permissions to public. I think it is either some sort of permission problem or patch problem. When I orginally worked on project it was in oracle 9i and one of last things I did was upgrade db to 11g. I don't know if I had to make some sort of change when I did that upgrade. But I need to get it working again on a 9i database (9.2.0.3.0)
Below I have include 3 parts that I think make up the the problem
1) The oci code that is giving error message
2) The sql that creates the type
3) The package that the OCI program is trying to run ( i had to remove comments for max length in oracle forums)
So I am looking for help on what I might be missing or re createing this application. I kind of think I may have had to do something different with creating the type. For all of the .sql I just ran them as same user that owns all of my other tables.
1) Below is line from OCI program that is failing
if (ociCheckError("timeDiscrepancy.c(8008)", OCITypeByName(hba.envhp, hba.errhp, hba.svchp,
(text *) 0, (ub4) 0, (text *) "DISCREPTABTYP", (ub4) strlen((const char *) "DISCREPTABTYP"),
(CONST text *) 0, (ub4) 0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER,
&discreptab_tdo), TRUE, &hba) == -1) {
callMessage(&hba);
deconstructHba(&hba);
return (0);
2) Below is sql that crated type
drop type discrepTabTyp;
Create or Replace Type discrepancyType as object(
empcd varchar2(12),
skilltpe varchar2(9),
hprdcode varchar2(6),
wprdcode varchar2(6),
strtdate date,
enddate date,
empupdate date,
empfnme varchar2(12),
empmint varchar2(2),
emplnme varchar2(20),
prodcode varchar2(6),
startscan date,
endscan date,
origstart date,
reason varchar2(23),
timeupdate date)
GRANT EXECUTE ON DISCREPANCYTYPE TO public;
CREATE PUBLIC SYNONYM DISCREPANCYTYPE FOR DISCREPANCYTYPE;
Create or Replace type discrepTabTyp is table of discrepancyType
GRANT EXECUTE ON DISCREPTABTYP TO public;
CREATE PUBLIC SYNONYM DISCREPTABTYP FOR DISCREPTABTYP;
3) Below is the package that the OCI program is trying to run
create or replace package timeKeeper_package as
Type empschdRec IS RECORD (
hprdcode empschd.hprdcode%type,
empcd empschd.empcode%type,
skilltpe empschd.skilltpe%type,
wprdcode empschd.wprdcode%type,
strtdate date,
enddate date,
lastupdate date,
match pls_integer);
Type timeRec IS RECORD (
prodcode time_keeper.prodcode%type,
empcd time_keeper.empcode%type,
origstart date,
startscan date,
endscan date,
lastupdate date,
match pls_integer);
Type discrepancyRec IS RECORD (
empcd empschd.empcode%type DEFAULT '',
skilltpe empschd.skilltpe%type DEFAULT'',
hprdcode empschd.hprdcode%type DEFAULT '',
wprdcode empschd.wprdcode%type DEFAULT '',
strtdate date DEFAULT NULL,
enddate date DEFAULT NULL,
empupdate date DEFAULT NULL,
empfnme empcode.empfnme%type DEFAULT ' ',
empmint empcode.empmint%type DEFAULT ' ',
emplnme empcode.emplnme%type DEFAULT ' ',
prodcode time_keeper.prodcode%type DEFAULT '',
startscan date DEFAULT NULL,
endscan date DEFAULT NULL,
origstart date DEFAULT NULL,
timeupdate date DEFAULT NULL,
reason varchar2(23) DEFAULT '');
type empArray is table of empschdRec index by pls_integer;
type timeArray is table of timeRec index by pls_integer;
type discrepancyArray is table of discrepancyRec index by pls_integer;
procedure discrepancy (unit in prodcode.prodcode%type, start_date date, end_date date,
unknown_tb in out discrepancyArray, belongWork_tb in out discrepancyArray,
floatIn_tb in out discrepancyArray, floatOut_tb in out discrepancyArray);
procedure discrepancy2 (unit in prodcode.prodcode%type,
start_date date, end_date date,
unknown_tab out discrepTabTyp, belongWork_tab out discrepTabTyp,
floatIn_tab out discrepTabTyp, floatOut_tab out discrepTabTyp);
procedure match (unit in prodcode.prodcode%type, start_date date, end_date date,
empschd_tb out empArray, time_keeper_tb out timeArray);
end timeKeeper_package;
create or replace package body timeKeeper_package as
Type empcodeRec IS RECORD (
prodcode empcode.prodcode%type,
empcd empcode.empcode%type,
bskiltpe empcode.bskiltpe%type,
empfnme empcode.empfnme%type,
empmint empcode.empmint%type,
emplnme empcode.emplnme%type,
swipe empcode.swipe%type,
home_swipe empcode.home_swipe%type);
type empcodeArray is table of empcodeRec index by pls_integer;
function empcode_find (empcd empcode.empcode%type, emcdTable empcodeArray,
maxIndex int) return int;
procedure add_discrepancy (unit in prodcode.prodcode%type,
unknown_tb in out discrepancyArray,
belongWork_tb in out discrepancyArray,floatIn_tb in out discrepancyArray,
floatOut_tb in out discrepancyArray,
empcode_tb empcodeArray, empcdIndex pls_integer,
empschd_tb empArray,schdIndex pls_integer,
time_keeper_tb timeArray, timeIndex pls_integer, reason varchar2);
procedure match (unit in prodcode.prodcode%type, start_date date, end_date date,
empschd_tb out empArray, time_keeper_tb out timeArray) as
CURSOR schd_cursor is
select empschd.hprdcode,empschd.empcode,empschd.skilltpe,empschd.wprdcode,
empschd.strtdate,empschd.enddate, empschd.lastupdate, 0
from empschd,empcode
where (empschd.hprdcode = unit or empschd.wprdcode = unit) and
(empschd.strtdate between start_date and end_date or
empschd.enddate between start_date and end_date)
and empschd.openclsd = 'OPEN' and empcode.empcode = empschd.empcode and
empcode.swipe = 'Y' and empcode.termcode is null
order by empschd.empcode,empschd.strtdate,empschd.enddate;
CURSOR time_cursor is
select time_keeper.prodcode, time_keeper.empcode, time_keeper.origstart,
time_keeper.startscan, time_keeper.endscan, time_keeper.lastupdate, 0
from time_keeper, prodcode
where (time_keeper.empcode in (select empcode from empcode where prodcode = unit)
or time_keeper.prodcode = unit) and
(time_keeper.startscan between (start_date - (prodcode.scan_reset/24))
and (end_date + (prodcode.scan_reset/24)) or
time_keeper.endscan between (start_date - (prodcode.scan_reset/24))
and (end_date + (prodcode.scan_reset/24))) and
time_keeper.active = 'Y' and prodcode.prodcode = unit
order by time_keeper.empcode, time_keeper.startscan, time_keeper.endscan;
timeIndex integer; -- current index in time_keeper_tb
diffCurrent float; -- difference between current empschd and time keeper start dates
diffNext float; -- difference between current empschd and next time keeper start dates
diffEmp2 float; -- difference between next empschd 7 current time keeper start dates
BEGIN
open schd_cursor;
fetch schd_cursor bulk collect into empschd_tb;
close schd_cursor;
open time_cursor;
fetch time_cursor bulk collect into time_keeper_tb;
close time_cursor;
if (empschd_tb.FIRST is not NULL and time_keeper_tb.FIRST is not NULL) then
timeIndex := 1;
for i in empschd_tb.FIRST .. empschd_tb.LAST
loop
while (timeIndex <= time_keeper_tb.LAST and (time_keeper_tb(timeIndex).match != 0 or
time_keeper_tb(timeIndex).empcd != empschd_tb(i).empcd))
loop
timeIndex := timeIndex + 1;
end loop;
if (timeIndex > time_keeper_tb.LAST) then
timeIndex := 1;
else
diffCurrent := abs (empschd_tb(i).strtdate - time_keeper_tb(timeIndex).startscan);
while (timeIndex < time_keeper_tb.LAST and
time_keeper_tb(timeIndex).empcd = empschd_tb(i).empcd)
loop
if (timeIndex+1 <= time_keeper_tb.LAST and
empschd_tb(i).empcd = time_keeper_tb(timeIndex+1).empcd) then
diffNext := abs (empschd_tb(i).strtdate - time_keeper_tb(timeIndex+1).startscan);
else
diffNext := diffCurrent;
end if;
exit when diffCurrent <= diffNext;
timeIndex := timeIndex + 1;
diffCurrent := diffNext;
end loop; -- end while finding closesest empschd
if (i+1 <= empschd_tb.LAST and
empschd_tb(i+1).empcd = time_keeper_tb(timeIndex).empcd) then
diffEmp2 := abs (empschd_tb(i+1).strtdate - time_keeper_tb(timeIndex).startscan);
else
diffEmp2 := diffCurrent;
end if;
-- decide which time keeper record to match to current empschd record
if (diffCurrent <= diffEmp2) then
empschd_tb(i).match := timeIndex;
time_keeper_tb(timeIndex).match := i;
timeIndex := timeIndex+1;
else
-- if previous time_keeper record is unmatched,
-- then match it to current empschd else it remains unmatched
if (timeIndex > 1 and time_keeper_tb(timeIndex-1).match = 0 and
empschd_tb(i).empcd = time_keeper_tb(timeIndex-1).empcd) then
empschd_tb(i).match := timeIndex-1;
time_keeper_tb(timeIndex-1).match := i;
end if;
end if; -- end else next empschd was closer
end if;
end loop; -- end for each empschd
end if;
-- utl_file.fclose (fip);
END match;
procedure discrepancy (unit in prodcode.prodcode%type,
start_date date, end_date date,
unknown_tb in out discrepancyArray, belongWork_tb in out discrepancyArray,
floatIn_tb in out discrepancyArray, floatOut_tb in out discrepancyArray) as
-- read in all non terminated employee records
CURSOR emp_cursor is
select prodcode, empcode, bskiltpe, empfnme, nvl(empmint,' '), emplnme,
swipe, home_swipe
from empcode
where termcode is null
order by empcode;
empcode_tb empcodeArray; -- holds non terminated employee array
employee_index pls_integer; -- current employee in empcode_tb
timeKeeper_indx pls_integer; -- current time keeper record
empschd_tb empArray; -- holds employee schedule data
time_keeper_tb timeArray; -- holds time keeper data
unitgrace number (38,34); -- unit's grace time
found boolean; -- indicates if discrepancy found
reason varchar2(23); -- the reason of discrepancy
fip utl_file.file_type;
begin
-- this places record in all_directories table which seems to be used by fopen
fip := utl_file.fopen ('TIME_KEEP_DIR','discrepancy.pr','w',500);
-- read and convert grace time for unit from minutes to fraction
-- of 1 day for date comparisons
select (grace_time / 60)/24
into unitgrace
from prodcode where prodcode = unit;
-- get the employee records to validate employee codes scanned
open emp_cursor;
fetch emp_cursor bulk collect into empcode_tb;
close emp_cursor;
utl_file.put_line(fip, 'match start '|| to_char (start_date, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (end_date, 'MM/DD/YYYY HH:MI:SS AM'), TRUE);
-- given a unit, start time and end time, read in and match employee schedule
-- and time keeper records to each other.
timeKeeper_package.match (unit, start_date, end_date, empschd_tb, time_keeper_tb);
-- print out employee schedule records
utl_file.new_line(fip,1);
utl_file.put_line (fip, 'EMPLOYEE SCHEDULE RECORDS');
utl_file.new_line(fip,1);
if (empschd_tb.FIRST is not NULL) then
for j in empschd_tb.FIRST ..empschd_tb.LAST
loop
utl_file.put_line(fip, 'index: '||j||' match: '||empschd_tb(j).match||' empcode: '||
empschd_tb(j).empcd ||' '|| ' skill: '|| empschd_tb(j).skilltpe ||
' Home: ' || empschd_tb(j).hprdcode || ' Work: ' || empschd_tb(j).wprdcode ||
' Start: '|| to_char (empschd_tb(j).strtdate, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (empschd_tb(j).enddate, 'MM/DD/YYYY HH:MI:SS AM'), TRUE);
end loop;
end if;
-- print the time keeper scan data
utl_file.new_line(fip,1);
utl_file.put_line (fip, 'TIME KEEPER RECORDS');
utl_file.new_line(fip,1);
if (time_keeper_tb.FIRST is not NULL) then
for i in time_keeper_tb.FIRST ..time_keeper_tb.LAST
loop
utl_file.put_line(fip,'Index: '||i||' match: '|| time_keeper_tb(i).match||
' empcode: ' || time_keeper_tb(i).empcd ||
' Start: '|| to_char (time_keeper_tb(i).startscan, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (time_keeper_tb(i).endscan, 'MM/DD/YYYY HH:MI:SS AM'),TRUE);
end loop;
end if;
-- perform discrepancy logic between empschd and time keeper records
timeKeeper_indx := 1;
-- go through all empschd records
if (empschd_tb.FIRST is not NULL) then
for i in empschd_tb.FIRST ..empschd_tb.LAST loop
-- find the next time keeper record that has same empcode as current empschd
while (time_keeper_tb(timeKeeper_indx).empcd <= empschd_tb(i).empcd) loop
if (time_keeper_tb(timeKeeper_indx).match = 0) then
-- check if time keeper record is with in start and end date range if not
-- skip record else have a descrepancy which need to figured out. It can
-- only be 1 of 2 possiblities since there is no matching empshcd record.
if NOT((time_keeper_tb(timeKeeper_indx).startscan < start_date and
time_keeper_tb(timeKeeper_indx).endscan < start_date) or
(time_keeper_tb(timeKeeper_indx).startscan > end_date and
time_keeper_tb(timeKeeper_indx).endscan > end_date)) then
employee_index := empcode_find (time_keeper_tb(timeKeeper_indx).empcd,
empcode_tb, empcode_tb.LAST);
found := false;
-- figure out reason of descrepancy
if (employee_index < 0) then
found := true;
reason := 'Unknown Employee-Swipe';
else
found := true;
reason := 'Not Scheduled, Swipe-in';
end if;
if (found = true) then
add_discrepancy (unit,unknown_tb, belongWork_tb, floatIn_tb, floatOut_tb,
empcode_tb, employee_index,
empschd_tb, -1, time_keeper_tb, timeKeeper_indx, reason);
end if;
end if;
end if; -- end if time keeper match = 0
timeKeeper_indx := timeKeeper_indx + 1;
end loop; -- end while time keeper empcode <= empschd empcode
employee_index := empcode_find (empschd_tb(i).empcd, empcode_tb, empcode_tb.LAST);
found := false;
-- if current empschd has no match then check for descrepancy
if (empschd_tb(i).match = 0) then
if (employee_index < 0) then
found := true;
reason := 'Unknown Employee-Sched';
elsif ((empschd_tb(i).strtdate + unitgrace) < sysdate) then
found := true;
reason := 'Scheduled, no swipe-in';
end if;
if (found = true) then
add_discrepancy (unit,unknown_tb, belongWork_tb, floatIn_tb, floatOut_tb,
empcode_tb, employee_index,
empschd_tb, i, time_keeper_tb, -1, reason);
end if;
else
-- empschd has a match, check for descrepancies
case
when time_keeper_tb(empschd_tb(i).match).prodcode != empschd_tb(i).wprdcode and
empcode_tb(employee_index).home_swipe = 'N' then
found := true;
reason := 'Swiped into wrong unit';
when time_keeper_tb(empschd_tb(i).match).endscan is NULL and
(empschd_tb(i).enddate + unitgrace) < sysdate then
found := true;
reason := 'Swipe-in, no Swipe-out';
when (time_keeper_tb(empschd_tb(i).match).startscan + unitgrace) <
empschd_tb(i).strtdate then
found := true;
reason := 'Swipe-in early';
when (time_keeper_tb(empschd_tb(i).match).startscan - unitgrace) >
empschd_tb(i).strtdate then
found := true;
reason := 'Swipe-in late';
when (time_keeper_tb(empschd_tb(i).match).endscan + unitgrace) <
empschd_tb(i).enddate then
found := true;
reason := 'Swipe-out early';
when (time_keeper_tb(empschd_tb(i).match).endscan - unitgrace) >
empschd_tb(i).enddate then
found := true;
reason := 'Swipe-out late';
else
found := false;
end case;
if (found = true) then
add_discrepancy (unit,unknown_tb, belongWork_tb, floatIn_tb, floatOut_tb,
empcode_tb, employee_index,
empschd_tb, i, time_keeper_tb, empschd_tb(i).match, reason);
end if;
end if;
end loop; -- end for each empschd
-- process all unproccesed time_keeper records with match value of 0
while (timeKeeper_indx <= time_keeper_tb.LAST) loop
if (time_keeper_tb(timeKeeper_indx).match = 0) then
-- check if time keeper record is with in start and end date range if not
-- skip record else have a descrepancy which need to figured out. It can
-- only be 1 of 2 possiblities since there is no matching empshcd record.
if NOT((time_keeper_tb(timeKeeper_indx).startscan < start_date and
time_keeper_tb(timeKeeper_indx).endscan < start_date) or
(time_keeper_tb(timeKeeper_indx).startscan > end_date and
time_keeper_tb(timeKeeper_indx).endscan > end_date)) then
employee_index := empcode_find (time_keeper_tb(timeKeeper_indx).empcd,
empcode_tb, empcode_tb.LAST);
found := false;
-- figure out reason of descrepancy
if (employee_index < 0) then
found := true;
reason := 'Unknown Employee-Swipe';
else
found := true;
reason := 'Not Scheduled, Swipe-in';
end if;
if (found = true) then
add_discrepancy (unit,unknown_tb, belongWork_tb, floatIn_tb, floatOut_tb,
empcode_tb, employee_index,
empschd_tb, -1, time_keeper_tb, timeKeeper_indx, reason);
end if;
end if;
end if; -- end if time keeper match = 0
timeKeeper_indx := timeKeeper_indx + 1;
end loop; -- end while time keeper records unproccesed
else
utl_file.put_line (fip, 'In check time_keeper because empschd is NULL');
if (time_keeper_tb.FIRST is not NULL) then
utl_file.put_line (fip, 'In time keeper not null');
for i in time_keeper_tb.FIRST ..time_keeper_tb.LAST
loop
if NOT((time_keeper_tb(i).startscan < start_date and
time_keeper_tb(i).endscan < start_date) or
(time_keeper_tb(i).startscan > end_date and
time_keeper_tb(i).endscan > end_date)) then
employee_index := empcode_find (time_keeper_tb(i).empcd,
empcode_tb, empcode_tb.LAST);
found := false;
-- figure out reason of descrepancy
if (employee_index < 0) then
found := true;
reason := 'Unknown Employee-Swipe';
else
found := true;
reason := 'Not Scheduled, Swipe-in';
end if;
utl_file.put_line (fip, 'before if found true');
if (found = true) then
add_discrepancy (unit,unknown_tb, belongWork_tb, floatIn_tb, floatOut_tb,
empcode_tb, employee_index,
empschd_tb, -1, time_keeper_tb, timeKeeper_indx, reason);
utl_file.put_line (fip, 'after add discrepancy');
end if;
end if;
end loop;
end if;
end if;
-- print out discrepancy data
utl_file.put_line (fip, 'Unknown Employees');
if (unknown_tb.FIRST is not NULL) then
for j in unknown_tb.FIRST ..unknown_tb.LAST
loop
utl_file.put_line(fip, 'index: '||j|| ' empcode: '||unknown_tb(j).empcd ||
' skill: '||unknown_tb(j).skilltpe ||
' Home: '|| unknown_tb(j).hprdcode || ' Work: '||
unknown_tb(j).wprdcode||' Start: '||
to_char (unknown_tb(j).strtdate, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (unknown_tb(j).enddate, 'MM/DD/YYYY HH:MI:SS AM') ||
' Name: '|| unknown_tb(j).empfnme ||
' '||unknown_tb(j).empmint||' '|| unknown_tb(j).emplnme, TRUE);
utl_file.put_line(fip,'time prod: '||unknown_tb(j).prodcode||' scan start '||
to_char (unknown_tb(j).startscan, 'MM/DD/YYYY HH:MI:SS AM')||' scan end '||
to_char (unknown_tb(j).endscan, 'MM/DD/YYYY HH:MI:SS AM')||' Original start '||
to_char (unknown_tb(j).origstart, 'MM/DD/YYYY HH:MI:SS AM'), TRUE);
utl_file.put_line(fip, 'Reason: '|| unknown_tb(j).reason,TRUE);
utl_file.new_line(fip,1);
end loop;
end if;
utl_file.put_line (fip, 'Employees Belong and Work in Unit');
if (belongWork_tb.FIRST is not NULL) then
for j in belongWork_tb.FIRST ..belongWork_tb.LAST
loop
utl_file.put_line(fip, 'index: '||j|| ' empcode: '||belongWork_tb(j).empcd ||
' skill: '||belongWork_tb(j).skilltpe ||
' Home: '|| belongWork_tb(j).hprdcode ||
' Work: '|| belongWork_tb(j).wprdcode||' Start: '||
to_char (belongWork_tb(j).strtdate, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (belongWork_tb(j).enddate, 'MM/DD/YYYY HH:MI:SS AM') || ' Name: '||
belongWork_tb(j).empfnme ||
' '||belongWork_tb(j).empmint||' '|| belongWork_tb(j).emplnme, TRUE);
utl_file.put_line(fip,'time prod: '||belongWork_tb(j).prodcode||' scan start '||
to_char (belongWork_tb(j).startscan, 'MM/DD/YYYY HH:MI:SS AM')||' scan end '||
to_char (belongWork_tb(j).endscan, 'MM/DD/YYYY HH:MI:SS AM')||' Original start '||
to_char (belongWork_tb(j).origstart, 'MM/DD/YYYY HH:MI:SS AM'), TRUE);
utl_file.put_line(fip, 'Reason: '|| belongWork_tb(j).reason,TRUE);
utl_file.new_line(fip,1);
end loop;
end if;
utl_file.put_line (fip, 'Employees Floated into Unit');
if (floatIn_tb.FIRST is not NULL) then
for j in floatIn_tb.FIRST ..floatIn_tb.LAST
loop
utl_file.put_line(fip, 'index: '||j|| ' empcode: '||floatIn_tb(j).empcd ||
' skill: '|| floatIn_tb(j).skilltpe ||
' Home: '|| floatIn_tb(j).hprdcode ||
' Work: '|| floatIn_tb(j).wprdcode||' Start: '||
to_char (floatIn_tb(j).strtdate, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (floatIn_tb(j).enddate, 'MM/DD/YYYY HH:MI:SS AM') || ' Name: '||
floatIn_tb(j).empfnme ||
' '||floatIn_tb(j).empmint||' '|| floatIn_tb(j).emplnme, TRUE);
utl_file.put_line(fip,'time prod: '||floatIn_tb(j).prodcode||' scan start '||
to_char (floatIn_tb(j).startscan, 'MM/DD/YYYY HH:MI:SS AM')||' scan end '||
to_char (floatIn_tb(j).endscan, 'MM/DD/YYYY HH:MI:SS AM')||' Original start '||
to_char (floatIn_tb(j).origstart, 'MM/DD/YYYY HH:MI:SS AM'), TRUE);
utl_file.put_line(fip, 'Reason: '|| floatIn_tb(j).reason,TRUE);
utl_file.new_line(fip,1);
end loop;
end if;
utl_file.put_line (fip, 'Employees Floated out of unit');
if (floatOut_tb.FIRST is not NULL) then
for j in floatOut_tb.FIRST ..floatOut_tb.LAST
loop
utl_file.put_line(fip, 'index: '||j|| ' empcode: '||floatOut_tb(j).empcd ||
' skill: '||floatOut_tb(j).skilltpe ||
' Home: '|| floatOut_tb(j).hprdcode ||
' Work: '|| floatOut_tb(j).wprdcode||' Start: '||
to_char (floatOut_tb(j).strtdate, 'MM/DD/YYYY HH:MI:SS AM') ||
' End: ' || to_char (floatOut_tb(j).enddate, 'MM/DD/YYYY HH:MI:SS AM') || ' Name: '||
floatOut_tb(j).empfnme ||
' '||floatOut_tb(j).empmint||' '|| floatOut_tb(j).emplnme, TRUE);
utl_file.put_line(fip,'time prod: '||floatOut_tb(j).prodcode||' scan start '||
to_char (floatOut_tb(j).startscan, 'MM/DD/YYYY HH:MI:SS AM')||' scan end '||
to_char (floatOut_tb(j).endscan, 'MM/DD/YYYY HH:MI:SS AM')||' Original start '||
to_char (floatOut_tb(j).origstart, 'MM/DD/YYYY HH:MI:SS AM'), TRUE);
utl_file.put_line(fip, 'Reason: '|| floatOut_tb(j).reason,TRUE);
utl_file.new_line(fip,1);
end loop;
end if;
utl_file.fclose (fip);
end discrepancy;
procedure add_discrepancy (unit in prodcode.prodcode%type,
unknown_tb in out discrepancyArray,
belongWork_tb in out discrepancyArray,floatIn_tb in out discrepancyArray,
floatOut_tb in out discrepancyArray,
empcode_tb empcodeArray, empcdIndex pls_integer,
empschd_tb empArray,schdIndex pls_integer,
time_keeper_tb timeArray, timeIndex pls_integer, reason varchar2) as
array_tb discrepancyArray; -- current array to add discrepancy to
indx pls_integer; -- index of new record in current array
selector pls_integer; -- flag indicates which array record will
-- be added to. These are HBA Hard coded values
-- 1 - The unknown array
-- 2 - The belong and work in unit array
-- 3 - The floated into this unit array
-- 4 - The floated out of this unit array
begin
-- check if you have a valid employee, if not data goes into unknown_tb array
if (empcdIndex <= 0) then
array_tb := unknown_tb;
selector := 1;
-- if have no empschd record but do have time keeper, determine
-- which array data goes into
elsif (schdIndex <= 0 and timeIndex > 0) then
if (unit = time_keeper_tb(timeIndex).prodcode and
empcode_tb(empcdIndex).prodcode = unit) then
array_tb := belongWork_tb;
selector := 2;
elsif (unit = time_keeper_tb(timeIndex).prodcode and
empcode_tb(empcdIndex).prodcode != unit) then
array_tb := floatIn_tb;
selector := 3;
else
array_tb := floatOut_tb;
selector := 4;
end if;
-- if have employee schedule record, determine which array data
-- goes into. You should never be able to get past this point
elsif (schdIndex > 0) then
if (unit = empschd_tb(schdIndex).wprdcode and
empschd_tb(schdIndex).hprdcode = unit) then
array_tb := belongWork_tb;
selector := 2;
elsif (unit = empschd_tb(schdIndex).wprdcode and
empschd_tb(schdIndex).hprdcode != unit) then
array_tb := floatIn_tb;
selector := 3;
else
array_tb := floatOut_tb;
selector := 4;
end if;
end if;
-- create and add new record to the correct array
if (schdIndex > 0 or timeIndex > 0) then
-- determine index for the new record being created.
if (array_tb.LAST is NULL) then
indx := 1;
else
indx := array_tb.LAST + 1;
end if;
if (schdIndex > 0) then
array_tb(indx).empcd := empschd_tb(schdIndex).empcd;
array_tb(indx).skilltpe := empschd_tb(schdIndex).skilltpe;
array_tb(indx).hprdcode := empschd_tb(schdIndex).hprdcode;
array_tb(indx).wprdcode := empschd_tb(schdIndex).wprdcode;
array_tb(indx).strtdate := empschd_tb(schdIndex).strtdate;
array_tb(indx).enddate := empschd_tb(schdIndex).enddate;
array_tb(indx).empupdate := empschd_tb(schdIndex).lastupdate;
else
array_tb(indx).empcd := time_keeper_tb(timeIndex).empcd;
if (empcdIndex > 0) then
array_tb(indx).skilltpe := empcode_tb(empcdIndex).bskiltpe;
array_tb(indx).hprdcode := empcode_tb(empcdIndex).prodcode;
end if;
end if;
if (empcdIndex > 0) then
array_tb(indx).empfnme := empcode_tb(empcdIndex).empfnme;
array_tb(indx).empmint := empcode_tb(empcdIndex).empmint;
array_tb(indx).emplnme := empcode_tb(empcdIndex).emplnme;
end if;
if (timeIndex > 0) then
array_tb(indx).prodcode := time_keeper_tb(timeIndex).prodcode;
array_tb(indx).startscan := time_keeper_tb(timeIndex).startscan;
array_tb(indx).endscan := time_keeper_tb(timeIndex).endscan;
array_tb(indx).origstart := time_keeper_tb(timeIndex).origstart;
array_tb(indx).timeupdate := time_keeper_tb(timeIndex).lastupdate;
end if;
array_tb(indx).Reason := reason;
-- after new record created then reassign array to correct output variable
if (selector = 1) then
unknown_tb := array_tb;
elsif (selector = 2) then
belongWork_tb := array_tb;
elsif (selector = 3) then
floatIn_tb := array_tb;
elsif (selector = 4) then
floatOut_tb := array_tb;
end if;
end if;
end;
function empcode_find (empcd empcode.empcode%type, emcdTable empcodeArray,
maxIndex int) return int as
low int; -- Array index of low side of current search
high int; -- Array index of high side of current search
mid int; -- Array index of current record being checked
begin
low := 1; -- Initialize to first index in array
high := maxIndex; -- Initialize to last index in array
while ( low <= high) loop
mid := (low + high) / 2;
if (empcd < emcdTable(mid).empcd) then
high := mid - 1;
elsif (empcd > emcdTable(mid).empcd) then
low := mid + 1;
else
return mid;
end if;
end loop;
return -1;
end empcode_find;
procedure discrepancy2 (unit in prodcode.prodcode%type,
start_date date, end_date date,
unknown_tab out discrepTabTyp, belongWork_tab out discrepTabTyp,
floatIn_tab out discrepTabTyp, floatOut_tab out discrepTabTyp) as
unknown_tb discrepancyArray;
belongWork_tb discrepancyArray;
floatIn_tb discrepancyArray;
floatOut_tb discrepancyArray;
begin
timeKeeper_package.discrepancy (unit, start_date, end_date, unknown_tb,
belongWork_tb, floatIn_tb, floatOut_tb);
if (unknown_tb.FIRST is not NULL) then
unknown_tab := discrepTabTyp();
for j in unknown_tb.FIRST ..unknown_tb.LAST
loop
unknown_tab.extend;
unknown_tab(j) := discrepancyType (unknown_tb(j).empcd, unknown_tb(j).skilltpe,
unknown_tb(j).hprdcode, unknown_tb(j).wprdcode,
unknown_tb(j).strtdate, unknown_tb(j).enddate,
unknown_tb(j).empupdate,unknown_tb(j).empfnme,
unknown_tb(j).empmint, unknown_tb(j).emplnme, unknown_tb(j).prodcode,
unknown_tb(j).startscan, unknown_tb(j).endscan, unknown_tb(j).origstart,
unknown_tb(j).reason, unknown_tb(j).timeupdate);
end loop;
end if;
if (belongWork_tb.FIRST is not NULL) then
belongWork_tab := discrepTabTyp();
for j in belongWork_tb.FIRST ..belongWork_tb.LAST
loop
belongWork_tab.extend;
belongWork_tab(j) := discrepancyType (belongWork_tb(j).empcd,belongWork_tb(j).skilltpe,
belongWork_tb(j).hprdcode, belongWork_tb(j).wprdcode,
belongWork_tb(j).strtdate, belongWork_tb(j).enddate,
belongWork_tb(j).empupdate, belongWork_tb(j).empfnme,
belongWork_tb(j).empmint, belongWork_tb(j).emplnme, belongWork_tb(j).prodcode,
belongWork_tb(j).startscan, belongWork_tb(j).endscan, belongWork_tb(j).origstart,
belongWork_tb(j).reason, belongWork_tb(j).timeupdate);
end loop;
end if;
if (floatIn_tb.FIRST is not NULL) then
floatIn_tab := discrepTabTyp();
for j in floatIn_tb.FIRST ..floatIn_tb.LAST
loop
floatIn_tab.extend;
floatIn_tab(j) := discrepancyType (floatIn_tb(j).empcd,
floatIn_tb(j).skilltpe, floatIn_tb(j).hprdcode,
floatIn_tb(j).wprdcode, floatIn_tb(j).strtdate, floatIn_tb(j).enddate,
floatIn_tb(j).empupdate, floatIn_tb(j).empfnme,
floatIn_tb(j).empmint, floatIn_tb(j).emplnme, floatIn_tb(j).prodcode,
floatIn_tb(j).startscan, floatIn_tb(j).endscan, floatIn_tb(j).origstart,
floatIn_tb(j).reason, floatIn_tb(j).timeupdate);
end loop;
end if;
-- Copy float out table data to output array
if (floatOut_tb.FIRST is not NULL) then
floatOut_tab := discrepTabTyp();
for j in floatOut_tb.FIRST ..floatOut_tb.LAST
loop
floatOut_tab.extend;
floatOut_tab(j) := discrepancyType (floatOut_tb(j).empcd, floatOut_tb(j).skilltpe,
floatOut_tb(j).hprdcode, floatOut_tb(j).wprdcode,
floatOut_tb(j).strtdate, floatOut_tb(j).enddate,
floatOut_tb(j).empupdate, floatOut_tb(j).empfnme,
floatOut_tb(j).empmint, floatOut_tb(j).emplnme, floatOut_tb(j).prodcode,
floatOut_tb(j).startscan, floatOut_tb(j).endscan, floatOut_tb(j).origstart,
floatOut_tb(j).reason, floatOut_tb(j).timeupdate);
end loop;
end if;
end;
end timeKeeper_package;
GRANT EXECUTE ON TIMEKEEPER_PACKAGE TO public;
CREATE PUBLIC SYNONYM TIMEKEEPER_PACKAGE FOR TIMEKEEPER_PACKAGE;I figured out that when I upgraded from 9.2.03 to 9.2.0.8 that the problem went away. I think when I had it working earlier I may have been on 9.2.0.5
-
Records and Objects, Cast for PL/SQL Type RECORD and SQL Type OBJECT
Hi seniors:
In my job, we have Oracle 10g, programming with Packages, the parameters are PL/SQL Types,
Example:
PACKAGE BODY NP_CONTROL_EQUIPMENT_PKG
IS
TYPE TR_EQUIPMENT_OPERATION IS RECORD(
wn_npequipmentoperid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npequipmentoperid%TYPE,
wv_npactiveservicenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npactiveservicenumber%TYPE,
wv_npspecification ORDERS.NP_SPECIFICATION.npspecification%TYPE,
wv_nptype ORDERS.NP_SPECIFICATION.nptype%TYPE,
wn_nporderid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.nporderid%TYPE,
wn_npguidenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npguidenumber%TYPE,
wd_npdevolutionprogramdate CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npdevolutionprogramdate%TYPE
TYPE TT_TR_EQUIPMENT_OPERATION_LST IS TABLE OF TR_EQUIPMENT_OPERATION INDEX BY BINARY_INTEGER;
PROCEDURE SP_GET_EQUIPMENT_OPERATION_LST(
an_npequipstatid IN CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npequipstatid%TYPE,
at_equipment_operation_list OUT TT_TR_EQUIPMENT_OPERATION_LST,
av_message OUT VARCHAR2
IS
BEGIN
SELECT EO.npequipmentoperid,
EO.npactiveservicenumber,
S.npspecification,
S.nptype,
EO.nporderid,
EO.npguidenumber,
ES.npdevolutionprogramdate
BULK COLLECT INTO at_equipment_operation_list
FROM NP_EQUIPMENT_OPERATIONS EO,
NP_EQUIPMENT_STATUS ES,
ORDERS.NP_ORDER O,
ORDERS.NP_SPECIFICATION S
WHERE EO.npequipstatid = ES.npequipstatid
AND EO.nporderid = O.nporderid
AND O.npspecificationid = S.npspecificationid
AND EO.npequipstatid = an_npequipstatid;
EXCEPTION
WHEN OTHERS THEN
av_message := 'NP_CONTROL_EQUIPMENT_PKG.SP_GET_EQUIPMENT_OPERATION_LST: '||SQLERRM;
END SP_GET_EQUIPMENT_OPERATION_LST;
END;
Procedures calls other procedures and passing parameters IN OUT defined that PL/SQL Types. The problem appears when the access is through Java. Java can't read PL/SQL Types because only read SQL Types (Types defined in SCHEMA):
CREATE OR REPLACE
TYPE TO_EQUIPMENT_OPERATION AS OBJECT (
wn_npequipmentoperid NUMBER,
wv_npactiveservicenumber VARCHAR2(15),
wv_npspecification VARCHAR2(8),
wv_nptype VARCHAR2(2),
wn_nporderid NUMBER,
wn_npguidenumber NUMBER,
wd_npdevolutionprogramdate DATE
CREATE OR REPLACE
TYPE TT_EQUIPMENT_OPERATION_LST
AS TABLE OF "CONTROL_EQUIPMENT"."TO_EQUIPMENT_OPERATION"
Java can read this SQL Types. The problem is how cast OBJECT to RECORD, because I can't execute that:
DECLARE
wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
BEGIN
SELECT EO.npequipmentoperid,
EO.npactiveservicenumber,
S.npspecification,
S.nptype,
EO.nporderid,
EO.npguidenumber,
ES.npdevolutionprogramdate
BULK COLLECT INTO wt_operation_lst
FROM NP_EQUIPMENT_OPERATIONS EO,
NP_EQUIPMENT_STATUS ES,
ORDERS.NP_ORDER O,
ORDERS.NP_SPECIFICATION S
WHERE EO.npequipstatid = ES.npequipstatid
AND EO.nporderid = O.nporderid
AND O.npspecificationid = S.npspecificationid
AND EO.npequipstatid = an_npequipstatid;
END;
and throws NOT ENOUGH VALUES, and I modified to:
DECLARE
wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
BEGIN
SELECT TO_EQUIPMENT_OPERATION(EO.npequipmentoperid,
EO.npactiveservicenumber,
S.npspecification,
S.nptype,
EO.nporderid,
EO.npguidenumber,
ES.npdevolutionprogramdate)
BULK COLLECT INTO wt_operation_lst
FROM NP_EQUIPMENT_OPERATIONS EO,
NP_EQUIPMENT_STATUS ES,
ORDERS.NP_ORDER O,
ORDERS.NP_SPECIFICATION S
WHERE EO.npequipstatid = ES.npequipstatid
AND EO.nporderid = O.nporderid
AND O.npspecificationid = S.npspecificationid
AND EO.npequipstatid = an_npequipstatid;
END;
Worst is that I can't modify this procedure and PL/SQL Types will survive.
I have create a copy that CAST RECORD to OBJECT and OBJECT to RECORD too.
PROCEDURE SP_COPY_PLSQL_TO_SQL(
an_npequipstatid IN NUMBER,
at_dominio_lst OUT ORDERS.TT_EQUIPMENT_OPERATION_LST, --SQL Type
av_message OUT VARCHAR2
IS
wt_dominio_lst CONTROL_EQUIPMENT.NP_CONTROL_EQUIPMENT_PKG.TT_TR_EQUIPMENT_OPERATION_LST; --PL/SQL Type
BEGIN
SP_GET_EQUIPMENT_OPERATION_LST(an_npequipstatid, wt_dominio_lst, av_message);
IF av_message IS NULL THEN
at_dominio_lst := ORDERS.TT_EQUIPMENT_OPERATION_LST(ORDERS.TO_EQUIPMENT_OPERATION('','','','','','',''));
at_dominio_lst.EXTEND(wt_dominio_lst.COUNT - 1);
FOR i IN 1..wt_dominio_lst.COUNT LOOP
at_dominio_lst(i) := ORDERS.TO_EQUIPMENT_OPERATION(wt_dominio_lst(i).wn_npequipmentoperid,
wt_dominio_lst(i).wv_npactiveservicenumber,
wt_dominio_lst(i).wv_npspecification,
wt_dominio_lst(i).wv_nptype,
wt_dominio_lst(i).wn_nporderid,
wt_dominio_lst(i).wn_npguidenumber,
wt_dominio_lst(i).wd_npdevolutionprogramdate
END LOOP;
END IF;
END;
I would like that the CAST is direct. Somebody can help me?. Thank you so much!I am facing the same problem as u had...may I know how u solved ur probkem...
thanks,
kishore -
Passing Object types using JDBC
I need to pass Oracle user-defined object types in and out of
PL/SQL stored procedures. Is this possible???
Thanks
nullHi Tina,
I just had another thought. JDBC for 8.0 doesn't support
user-defined SQL types. This feature isn't implemented until 8i.
Sorry about the false lead!
So you'd have to wrapper your object in another PL/SQL method
which 'explodes' the user-defined type, as:
procedure can_call_from_jdbc (ename varchar2, empno number, ...)
is...
begin
call my_procedure(employee_t(ename, empno, ...));
end;
Pierre
Oracle Product Development Team wrote:
: Hi Tina,
: Yikes! I'm glad you asked; it made me realize that some info
: that's supposed to be posted on our external site is missing.
I
: think it'll take about a week to push this to our external
site.
: I'll try to find you a version and email it to you directly.
: Thanks!
: Pierre
: Tina Creighton (guest) wrote:
: : I'm currently using version 8.04 with Objects option, I'm
: trying
: : to locate the oracle.jpub class. Is there a way to download
: the
: : new jdbc that works with objects. Thanks. Tina
: : Oracle Product Development Team wrote:
: : : Absolutely!
: : : the easiest thing is first to use JPub to generate a Java
: : object
: : : which is an analogue to the SQL object you have. For
: example,
: : : if your SQL object is called 'EMPLOYEE_T', you can invoke
: JPub
: : : with:
: : : $ jpub -sql=employee_t -url=jdbc:oracle:oci8:@
: : -user=scott/tiger
: : : or even
: : : $ java oracle.jpub.Main -sql=employee_t
: -url=jdbc:oracle:oci8:@
: : : -user=scott/tiger
: : : This'll give you a Java class used to represent Java
: instances
: : of
: : : the SQL 'employee_t', featuring friendly setters and getter
: for
: : : the fields.
: : : If you have PL/SQL programs which take arguments of type
: : : employee_t, such as:
: : : PROCEDURE P1 (N NUMBER, E EMPLOYEE_T) IS...
: : : PROCEDURE P2 (N NUMBER, E OUT EMPLOYEE_T) IS...
: : : PROCEDURE P3 (N NUMBER, E IN OUT EMPLOYEE_T) IS...
: : : You can call them in a SQLJ program as:
: : : main () {
: : : employee_t e; // the class generated by JPub
: : : #sql {call P1(1, :e);}
: : : #sql {call P2(2, :out e);}
: : : #sql {call P3(3, :in out e);}
: : : to call your three PL/SQL procedures. After the call to P2
: and
: : : P3, your
: : : variable 'e' will be populated with the contents of the new
: : : employee_t value
: : : that was output from the PL/SQL method.
: : : (SQLJ is just a shorthand way of calling JDBC. SQLJ
programs
: : are
: : : translated
: : : into SQLJ programs by calling the "SQLJ Translator":
: : : $ sqlj myfile.sqlj
: : : Pierre
: : : Tina creighton (guest) wrote:
: : : : I need to pass Oracle user-defined object types in and
out
: of
: : : : PL/SQL stored procedures. Is this possible???
: : : : Thanks
: : : Oracle Technology Network
: : : http://technet.oracle.com
: Oracle Technology Network
: http://technet.oracle.com
Oracle Technology Network
http://technet.oracle.com
null -
Use TYPE RECORD or Create Object TYPE to build Collection?
Hi All,
I need to pull in data from our ERP system via a DB Link to keep some of our Web Data up to date. I wasn't sure if I should pull the data into my collection by creating a TYPE RECORD or Creating an Object Type and fillng it that way. Is there a preferrable method?
Record:
TYPE ItemInventory IS RECORD (
ProductID Products.ProductID%TYPE,
Qty Products.QTY%TYPE);
Object:
Create Type ProdObj as Object(
ProductID Products.ProductID%TYPE,
QTY Products.QTY%TYPE);
Maybe both are suitable....wasn't sure.
Any suggestions/info is greatly apprecaited.
S
Edited by: ScarpacciOne on Feb 21, 2010 7:54 PMScarpacciOne wrote:
We have a complex view we use from our ERP system that allows us to pull all of our available inventory and update our website with that information. What I was thinking I would do is refactor the current procedures that are in place to update this information and pull that views information into a collection so that I could speed up the update process.The basic difference between the two is that one is a dumb record structure (similar to a C struct), whereas the other is an intelligent class (similar to a class definition in Java/C++). It can have methods and constructors.
The next major difference is that one can only be use in the PL language and not in SQL. The record struct is a PL data type definition. PL cannot provide SQL engine support for it.
On the other hand, the SQL type definition is supported by both the PL and SQL languages. This allows the type to be transparently used in both languages.
I usually prefer the SQL type definition approach in general, as it allows for more flexibility.
However, for pure collection processing in PL/SQL, there's very little to choose between the two approaches as they serve the exact same purpose - increasing performance by decreasing context switching between the PL and SQL engines.
So you need to look beyond mere bulk collection and bulk processing to decide on which approach to use. For example, a SQL type definition allows for a standard SQL projection from cursors, enabling PL/SQL code to be cursor agnostic (as each cursor, irrespective of the table(s) queried, returns the same object type). However, if the aim is simply to bulk collect from that specific cursor, then it is a lot simpler to use a PL record struct. -
I am trying to select data from a table (while using TOAD) called HR_LOCATIONS_ALL (this is a seeded Oracle HRMS table) and get a message OCI-22303: type "MDSYS.
I don't get the same error when selecting data using SQL *Plus.
Does anyone have any idea why this is occuring and how to get rid of the message?
Thanks in advance!Could you please verify that your database (as opposed to just sqlplus) is 10.2.0.1?
For me, it works:
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 21 13:07:07 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and Data Mining options
SQL> select wktext from cs_srs where srid = 41155;
WKTEXT
PROJCS["Texas 4205, Southern Zone (1927)", GEOGCS [ "NAD 27 (Continental US)", D
ATUM ["NAD 27 (Continental US)", SPHEROID ["Clarke 1866", 6378206.4, 294.9786982
]], PRIMEM [ "Greenwich", 0.000000 ], UNIT ["Decimal Degree", 0.0174532925199433
0]], PROJECTION ["Lambert Conformal Conic"], PARAMETER ["Standard_Parallel_1", 2
6.166667], PARAMETER ["Standard_Parallel_2", 27.833333], PARAMETER ["Central_Mer
idian", -98.500000], PARAMETER ["Latitude_Of_Origin", 25.666667], PARAMETER ["Fa
lse_Easting", 2000000.0000], UNIT ["U.S. Foot", 0.3048006096012]]
SQL> SELECT sdo_cs.find_proj_crs(41155, 'FALSE') epsg_srid from dual;
EPSG_SRID
SDO_SRID_LIST(32041)
SQL> desc mdsys.sdo_srid_list;
mdsys.sdo_srid_list VARRAY(1048576) OF NUMBER
SQL>
Do you run the Enterprise Edition? -
After connection lost SetVector fails with OCI-22303: type not found
Hi there,
I use statelessConnectionPool and after application is loosing connection to oracle for short time, all folowing setVector calls will fail with
SetVector fails with OCI-22303: type "DEMO"."PROPERTIES" not found
however its there and was working fine before connection was lost,
As far as i read about the getConection for statelessConnectionPool will reestablish connection if required to return valid connection handle, but somehow the setVector does not work.
Any idea?
Thanks in advance
AndrewHi,
I want to reconnect to same instance, I think i missed tnsnames part, did not knew its required, so i should add to client tnsnames or server the FAILOVER_MODE part?
like this example:
PAYROLL =
(DESCRIPTION =
(ADDRESS =
(COMMUNITY = TCP.world)
(PROTOCOL = TCP)
(HOST = VSERVER)
(PORT = 1521)
(CONNECT_DATA =
(SID = HR)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 20)
(DELAY = 15)
strange thing that connection seams to be valid only in complains about type not found, or maybe connections are not valid only i cant see it, does the not valid connections in the pool are reconnected or make new when i call GetConnection? or i should terminate connections on "end of comm channel error" so when db is reachable again it will reestablish new connections?
Andrew -
How can I convert table object into table record format?
I need to write a store procedure to convert table object into table record. The stored procedure will have a table object IN and then pass the data into another stored procedure with a table record IN. Data passed in may contain more than one record in the table object. Is there any example I can take a look? Thanks.
I'm afraid it's a bit labourious but here's an example.
I think it's a good idea to work with SQL objects rather than PL/SQL nested tables.
SQL> CREATE OR REPLACE TYPE emp_t AS OBJECT
2 (eno NUMBER(4)
3 , ename VARCHAR2(10)
4 , job VARCHAR2(9)
5 , mgr NUMBER(4)
6 , hiredate DATE
7 , sal NUMBER(7,2)
8 , comm NUMBER(7,2)
9 , deptno NUMBER(2));
10 /
Type created.
SQL> CREATE OR REPLACE TYPE staff_nt AS TABLE OF emp_t
2 /
Type created.
SQL> Now we've got some Types let's use them. I've only implemented this as one public procedure but you can see the principles in action.
SQL> CREATE OR REPLACE PACKAGE emp_utils AS
2 TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
3 PROCEDURE pop_emp (p_emps in staff_nt);
4 END emp_utils;
5 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY emp_utils AS
2 FUNCTION emp_obj_to_rows (p_emps IN staff_nt) RETURN EmpCurTyp IS
3 rc EmpCurTyp;
4 BEGIN
5 OPEN rc FOR SELECT * FROM TABLE( CAST ( p_emps AS staff_nt ));
6 RETURN rc;
7 END emp_obj_to_rows;
8 PROCEDURE pop_emp (p_emps in staff_nt) is
9 e_rec emp%ROWTYPE;
10 l_emps EmpCurTyp;
11 BEGIN
12 l_emps := emp_obj_to_rows(p_emps);
13 FETCH l_emps INTO e_rec;
14 LOOP
15 EXIT WHEN l_emps%NOTFOUND;
16 INSERT INTO emp VALUES e_rec;
17 FETCH l_emps INTO e_rec;
18 END LOOP;
19 CLOSE l_emps;
20 END pop_emp;
21 END;
22 /
Package body created.
SQL>Looks good. Let's see it in action...
SQL> DECLARE
2 newbies staff_nt := staff_nt();
3 BEGIN
4 newbies.extend(2);
5 newbies(1) := emp_t(7777, 'APC', 'CODER', 7902, sysdate, 1700, null, 40);
6 newbies(2) := emp_t(7778, 'J RANDOM', 'HACKER', 7902, sysdate, 1800, null, 40);
7 emp_utils.pop_emp(newbies);
8 END;
9 /
PL/SQL procedure successfully completed.
SQL> SELECT * FROM emp WHERE deptno = 40
2 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7777 APC CODER 7902 17-NOV-05 1700
40
7778 J RANDOM HACKER 7902 17-NOV-05 1800
40
SQL> Cheers, APC -
Converting object wrapper type array into equivalent primary type array
Hi All!
My question is how to convert object wrapper type array into equivalent prime type array, e.g. Integer[] -> int[] or Float[] -> float[] etc.
Is sound like a trivial task however the problem is that I do not know the type I work with. To understand what I mean, please read the following code -
//Method signature
Object createArray( Class clazz, String value ) throws Exception;
//and usage should be as follows:
Object arr = createArray( Integer.class, "2%%3%%4" );
//"arr" will be passed as a parameter of a method again via reflection
public void compute( Object... args ) {
a = (int[])args[0];
//or
Object arr = createArray( Double.class, "2%%3%%4" );
public void compute( Object... args ) {
b = (double[])args[0];
//and the method implementation -
Object createArray( Class clazz, String value ) throws Exception {
String[] split = value.split( "%%" );
//create array, e.g. Integer[] or Double[] etc.
Object[] o = (Object[])Array.newInstance( clazz, split.length );
//fill the array with parsed values, on parse error exception will be thrown
for (int i = 0; i < split.length; i++) {
Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
o[i] = meth.invoke( null, new Object[]{ split[i] });
//here convert Object[] to Object of type int[] or double[] etc...
/* and return that object*/
//NB!!! I want to avoid the following code:
if( o instanceof Integer[] ) {
int[] ar = new int[o.length];
for (int i = 0; i < o.length; i++) {
ar[i] = (Integer)o;
return ar;
} else if( o instanceof Double[] ) {
//...repeat "else if" for all primary types... :(
return null;
Unfortunately I was unable to find any useful method in Java API (I work with 1.5).
Did I make myself clear? :)
Thanks in advance,
Pavel GrigorenkoI think I've found the answer myself ;-)
Never thought I could use something like int.class or double.class,
so the next statement holds int[] q = (int[])Array.newInstance( int.class, 2 );
and the easy solution is the following -
Object primeArray = Array.newInstance( token.getPrimeClass(), split.length );
for (int j = 0; j < split.length; j++) {
Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
Object val = meth.invoke( null, new Object[]{ split[j] });
Array.set( primeArray, j, val );
}where "token.getPrimeClass()" return appropriate Class, i.e. int.class, float.class etc. -
Null Pointer Exception in CO of type Webdynpro ABAP
Hi Friends,
I am getting an Error in creating a callable object of type Webdynpro ABAP,
The ABAP webdynpro application is working fine individually, but while creating a callable object of the same type, I get the following error,
(This happens when I click on <b>'Search'</b> button after putting the wd app name)
<i><b>The initial exception that caused the request to fail, was:
com.sap.mw.jco.JCO$Exception: (127) JCO_ERROR_FIELD_NOT_FOUND: Field LANGU not a member of INPUT
at com.sap.mw.jco.JCO$MetaData.indexOf(JCO.java:9372)
at com.sap.mw.jco.JCO$Record.setValue(JCO.java:14778)
at com.sap.caf.eu.gp.model.connect.rfc.abapwd.impl.ABAPWDAppManager.getAppInfo(ABAPWDAppManager.java:54)
at com.sap.caf.eu.gp.ui.co.config.abapwd.VSelect.getApplicationData(VSelect.java:493)
at com.sap.caf.eu.gp.ui.co.config.abapwd.VSelect.onActionSearch(VSelect.java:438)</b></i>
Do somebody has any idea about the problem?
Thanks in advance,
Deepak.Please send us the CreateEmployees.java. It seem the problem is in the way you using the generated java classes.
-
Hi,
I am getting an error OCI-22303 when trying to use OCITypeByName method.
Basically I am trying to use publish-subscribe notification mode to get get notification whenever a new message comes in the queue.
I am able to register my callback function with the oracle queue and whenever a new message is coming to the queue its my callback function is being invoked by oracle
but the problem is ,in that callback function when I am trying to dequeue the message it gives error on OCITypeByName method(ie OCI-22303).
Same code inside callback function is working fine when I am directly calling the callback function ie(not invoked by oracle).
Could you help me out what is the reason behind it?
Oracle version :8.1.6
In queue table payload is object type.
I have tried this with oracle8.1.7's catexp.sql also but it dint work
Please help me out
rajeevHi Rajiv,
Could you please provide more details?
Specifically, I would like to see how your
callback looks.
And you mentioned that if you directly called
the callback function, then OCITypeByName
worked. I am assuming you called this callback in some OCI program. So, I would also like to see the OCI program.
And one other thing. Did you make sure you had the same user session in both the cases?
thx,
Ravi -
Pass records from one procedure to another
hi,
I have created following procedure. It takes input parameter and selects some records in EMP table based on condition.
How to pass the output from this procedure to another procedure to manipulate the selected records further.
Do I need to pass REF CURSOR or RECORD ?
Thanks
===================================================
create or replace procedure empdetails(pid IN number)
is
type ref_cur is REF CURSOR;
rc ref_cur;
type myrec is RECORD(id number, name varchar2(15), sal number);
rec myrec;
begin
open rc for select id, name, sal from emp where deptid=pid;
loop
fetch rc into rec;
exit when rc%notfound;
dbms_output.put_line(rec.id||'--'||rec.name||'--'||rec.sal);
end loop;
close rc;
end empdetails;don123 wrote:
I have created following procedure. It takes input parameter and selects some records in EMP table based on condition.
How to pass the output from this procedure to another procedure to manipulate the selected records further.
Do I need to pass REF CURSOR or RECORD ?Record. The bulk collection approach is useful if you want to use the collection subsequently as a bind variable for bulk binding. But assuming you simply want to crunch data, the minimalistic approach would be:
SQL> declare
2 procedure ProcessEmp( e emp%RowType ) is
3 begin
4 dbms_output.put_line( 'processing employee..'||e.ename );
5 end;
6 begin
7 for e in(select * from emp order by 1) loop
8 ProcessEmp(e);
9 end loop;
10 end;
11 /
processing employee..SMITH
processing employee..ALLEN
processing employee..WARD
processing employee..JONES
processing employee..MARTIN
processing employee..BLAKE
processing employee..CLARK
processing employee..SCOTT
processing employee..KING
processing employee..TURNER
processing employee..ADAMS
processing employee..JAMES
processing employee..FORD
processing employee..MILLER
PL/SQL procedure successfully completed.
SQL> An implicit bulk collect is done by the FOR loop, courtesy of the PL/SQL optimiser. As the procedure ProcessEmp() does not perform SQL processing itself (e.g. using employee data to fire off UPDATE, DELETE or INSERT SQL statements), a collection is not really needed as it would not contribute to the procedure's performance.
If however nested SQL statements are fired from inside that cursor fetch loop, using a collection would enable these SQLs to make use of bulk binding.
However, this approach ALWAYS need to be question, examined and validated - as a single SQL can often be used, combining the outer read/fetch loop (SELECT), with the nested SQLs (UPDATE/INSERT) done - using the MERGE or INSERT..SELECT statements for example.
Explicit bulk processing should be an exception - as pushing data from the SQL engine to the PL/SQL engine, only to push that PL/SQL engine's data back to the SQL engine, is invariable a flawed, non performant, and non scalable approach. -
Will passing object as parameter increase memory usage?
Hi,
Will passing an object as a parameter increase the mmory usage? will it affect the performance of the application any means. Please share your view.
Regards,
A.Ananth.durai wrote:
Hi ,
Just to precise my question, suppose i have an object called Student.I want to pass the Student Object to a method called addStudent().Now rather than passing Student Object, i am passing it's super class "Object". (i.e)
addStudent(Object object) instead of addStudent(Student student)will it make any difference in performance?Those are declarations, not method passing. You'd still be passing the same thing, if it's just a question about how you declare the method.
And it will make no difference in performance, except when you start getting bugs. You might start getting bugs because you declared the parameter with a more general type than is really necessary. If the method takes a Student, then declare it as taking a Student. Making it say it takes an Object will just make things worse.
But as per Cogniac,
when you pass a parameter or use an accessor function (get() function) or something of that sort, it's actually just passing a pointer that points to the memory location of the Object you want, not actually passing the Object itself to you, nor is it instantiating a new instance of the Object for your use.if i pass Object itself instead of Student,which memory address it will point out?That question makes no sense. You pass what you pass. If it's a Student object, then the reference the method gets will point to that object, regardless of whether the method knows that it's a Student or just an Object generally.
Maybe you are looking for
-
My experience with a family pak
I upgraded five Macs from 10.4.10. Of the five, two came up with no install disk to select. I just re-ran the installer and then the startup disk appeared. On one of the Macs, after I did the upgrade, the user account disappeared and I couldn't log i
-
MAC MINI RAMM!! please help
hey guys. well im going to upgrade my ram on my mac mini late 2009 i have two slots at the moment, each with one gb in it. i know what memory (with details) i need to get the only thing i wanted to ask about was would it be possible to buy just a sin
-
Bank Charges on outgoing payment
Currently using SAP 8.8 PL 14 Question: On outgoing payments through Bank or RTGS there is some charges deduct by bank on these services. presently these charges are not showing in bank books. we are punching service entries extra for bank charges. i
-
Bluetooth versus airplay speakers
Hi, I have an hifi that supports airplay and it is absolutely brilliant. Now I'm looking for something smaller for my bedroom. Basically all I need are speakers because my ipad deals with the rest. But I can't find airplay speakers. All that seem to
-
1-Week-Old Macbook Pro won't turn on.
About a week after I bought it, my Macbook Pro unexpectedly shut off while I was watching a video, and would not turn back on. When I tried to turn it back on, I got the buzz and the little white light, but there was no chime, nothing on the screen,