The object Type VARRAY
Hello
I'm still very new to PL/SQL please bare with me if you can. I am trying to learn how to store the data of an object in a single varray of objects. My code below attempts to declare a type of object with instance attributes 3 and 3 methods of instance of getter and setter method.
So, I want to create a varray type to store an array of types of objects 'employee '.
Here I am trying to use a loop to retrieve the 10 first ename and empno, sal chronogram EMP table and store it in the variable array of 10 items.
Finally, I tried to use another loop to produce the ename, empno and sal in the order opposite.
My goal and my body of the object was created successfully without error.
The problem starts when I start anonymous block that creates the varray is when I get an error at the end.
At the end of my code is I get the error message. Can anyone suggest me what I am doing wrong, or what I can do to accomplish this task.
SET SERVEROUTPUT ON
-create object
CREATE OR REPLACE TYPE used AS OBJECT)
ename_obj VARCHAR2 (10),
empno_obj number 4,
sal_obj NUMBER (7.2).
Getename RETURN of the FUNCTION MEMBER VARCHAR2.
Getempno RETURN NUMBER of MEMBER FUNCTION
FUNCTION RETURN NUMBER getsal MEMBER);
/
-create bodies of the object
CREATE or REPLACE TYPE BODY used as
FUNCTION MEMBER getename IS return VARCHAR2
BEGIN
RETURN ename_obj;
END;
FUNCTION MEMBER getempno IS return VARCHAR2
BEGIN
RETURN empno_obj;
END;
FUNCTION MEMBER getsal IS return VARCHAR2
BEGIN
RETURN sal_obj;
END;
END;
/
-create varray of object and start line 1 of the Error Message.
1 > DECLARE
2 > TYPE tvrEmploy IS the VARRAY (10) OF the employee;
3 > vClient tvrEmploy;
4 > iCounter integer: = 1;
5 > CURSOR client_cursor IS
6 > SELECT ename, sal
7 > FROM emp
8 > WHERE rownum < 11;
9 > START
10 > vClient: = tvrEmploy (null, null, null, null, null, null, null, null, null, null);
11 > FOR i IN client_cursor LOOP
12 > vClient (iCounter) .ename_obj: = i.ename;
13 > vClient (iCounter) .empno_obj: = i.empno;
14 > vClient (iCounter) .sal_obj: = i.sal;
15 > iCounter: = iCounter + 1;
16 > END of LOOP;
17 > FOR I IN REVERSE 1.10 LOOP
18 > dbms_output.put_line (to_char (I) |) » '|| vClient (I) .ename_obj | » '|| vClient (I) .empno_obj | » '||
vClient (I) .sal_obj);
19 > END of LOOP;
20 > END;
21 >.
-"' '" Error message below -
DECLARE
*
ERROR on line 1:
ORA-06530: Reference to the composite uninitialized
ORA-06512: at the level of line 12
Thanks again for your time and patience.
-Todd
Hello
The error occurs on line 12, the first time in the loop when you try to run:
vClient (iCounter) .ename_obj: = i.ename;
At that point, vClient (1) is not an Employee object. It has the value NULL.
Try this:
DECLARE
TvrEmploy TYPE IS the VARRAY (10) OF the employee;
vClient tvrEmploy;
iCounter integer: = 1;CURSOR client_cursor IS
SELECT ename, sal
, empno -- ADDED
FROM scott.emp
WHERE rownum<>
BEGIN
vClient: = tvrEmploy (null, null, null, null, null, null, null, null, null, null);
I'm IN client_cursor LOOP
vClient (iCounter): employee = (i.ename, i.empno, i.sal); --ALSO CHANGED
iCounter: = iCounter + 1;
END LOOP;
FOR I IN REVERSE 1.10 LOOP
dbms_output.put_line (to_char (I) |) » '|| vClient (I) .ename_obj | » '|| vClient (I) .empno_obj | » '||
vClient (I) .sal_obj);
END LOOP;
END;
/
Tags: Database
Similar Questions
-
Define a map or ORDER method for the object type
Hi gurus
I created an object and then its type and then I use this object and type based on line, see below:
Create the object
CREATE OR REPLACE
TYPE test_object
IS
OBJECT
(
next_appearance_dt DATE, - next_appearance_dt
youth_adult VARCHAR2 (5) - youth_adult
) ;
/Create the object Type
CREATE or REPLACE TYPE t_docket_object IS TABLE OF THE test_object;
/
Create function Pipeline
FUNCTION to CREATE or REPLACE f_report (p_dt date, p_c_cd VARCHAR2)
return t_test_object pipeline
IS
BEGIN
FOR J IN)
Select distinct test_object)
next_appearance_dt,--862,
'YOUTH '.
) AS test_object
Jen.next_appearance base
WHERE 1 = 1
AND (base.next_appearance_dt = p_dt)
AND (base.circuit_point_cd = p_c_cd)
- and cse.information_id = 322
-ORDER 15 - alias_name
)loop
PIPE ROW (J.test_object);
END loop;
END;/
Run function
SELECT * FROM TABLE (F_REPORT (TO_DATE('25-sep-2015','dd-mon-yyyy'),'1 '))
Error
ORA-22950: cannot ORDER objects without map or ORDER method
ORA-06512: at "F_REPORT", line 5
22950 00000 - "cannot ORDER objects without map or ORDER method.
* Cause: an object type must have a defined for map or ORDER method
all comparisons other than equality and inequality comparisons.
* Action: Define a map or ORDER method for the object type
I know the reason of this error and the reason is that I use the clause separate in my pipeline service, but do not know how to get rid of this error...
Confuse you the type of table with the object type. He forge
Select test_object (next_appearance_dt) test_object
Not:
Select t_test_object (next_appearance_dt) test_object
Then:
SQL > CREATE OR REPLACE
FUNCTION f_report (DATE p_dt 2,
3 P_C_CD VARCHAR2
4 )
5 t_test_object of RETURN
6 IN PIPELINE
7 EAST
BEGIN 8
9 FOR (IN) v_rec
10 WITH () DID
11. SELECT TO_DATE('01-jan-2015','dd-mon-yyyy') NEXT_APPEARANCE_DT
the double 12
13 )
14 select test_object (next_appearance_dt) test_object
15 from t
16 ) LOOP
PIPE 17 ROW (v_rec.test_object);
18 END OF LOOP;
END 19;
20.The function is created.
SY.
-
How to fill the value in the nested table by using the object type
Hi gurusI created an object type and able to fill the values in it, now I want to create a nested table type of this object and fill it but looks like I'm doing something wrong, see my code below.
Code example
CREATE or REPLACE TYPE countries_o
AS
OBJECT
(
COUNTRY_ID TANK (2 BYTES),
COUNTRY_NAME VARCHAR2 (40 BYTE),
REGION_ID NUMBER);
/create or replace type countries_t is table of the countries_o;
/CREATE OR REPLACE
ABC of the PROCEDURE
IS
v_print countries_t; -: = arr_countries_t('01','Aus',1);
BEGIN
v_print: = countries_t('01','A',11);
DBMS_OUTPUT. Put_line (v_print. COUNTRY_ID | v_print. COUNTRY_NAME | v_print. REGION_ID);
END;
/
Error
- Error (6.3): PL/SQL: statement ignored
- Error (6,12): PLS-00306: wrong number or types of arguments in the call to 'COUNTRIES_T '.
- Error (7.3): PL/SQL: statement ignored
- Error (7.32): PLS-00302: component 'COUNTRY_ID' must be declared
Thanks in advance
Concerning
Muzz
Hi user,
Here is another method that you can try-
CREATE OR REPLACE
ABC of the PROCEDURE
IS
v_print countries_t: = countries_t (countries_o('01','A',11));
BEGIN
DBMS_OUTPUT. Put_line (v_print (1).) COUNTRY_ID | v_print (1). COUNTRY_NAME | v_print (1). REGION_ID); -you're accessinf the first element of the nested table, which in turn points to the object.
END;
In the sections of the declaration you have assigned values to the nested table.
Kind regards
Maxou - Error (6.3): PL/SQL: statement ignored
-
How to return data using the object type?
Hello all - I have an obligation to return the values object type.
In the same way as
list - Plan1, Subplan1, Fund1, 2 Fund Fund 3
list - Plan2, Subplan2, Fund2
list - plane3, Subplan3, not funds
To achieve this I wrote below proc but its giving as response below which is does not correspond with my requirement. Someone has an idea how to write code to get the list of funds against each plan in each line?
Output:
PDB01. () T_T_CONTRACT
PDB01. T_O_CONTRACT ('p1', 's1', PDB01. T_O_FUND ('p1', 's1', 'f1')),
PDB01. T_O_CONTRACT ('p1', 's1', PDB01. T_O_FUND ('p1', 's1', 'f2')),
PDB01. T_O_CONTRACT ('p1', 's1', PDB01. T_O_FUND ('p1', 's1', 'f3')),
PDB01. T_O_CONTRACT ('p2', 's2', PDB01. T_O_FUND ('p2', 's2', 'f2')),
PDB01. T_O_CONTRACT ('p3', 's3', PDB01. T_O_FUND (NULL, NULL, NULL))
)
DROP TYPE T_T_fund;
create or replace
TYPE T_O_fund
AS OBJECT)
argument plan_id Varchar2 (128).
subplan_id Varchar2 (128).
fund_id Varchar2 (128)
)
No final;
/
create or replace
type T_T_FUND
as the table of T_O_FUND;
/
type of projection T_T_CONTRACT;
create or replace
TYPE T_O_contract
AS OBJECT)
argument plan_id Varchar2 (128).
SUBPLAN_ID varchar2 (128).
ov_fund T_o_fund
)
no final;
/
create or replace
type T_t_contract as the T_O_contract table;
/
-------------------------
/ * Remove T_T_FUND;
DROP TYPE T_O_fund;
type of projection T_T_CONTRACT;
DROP TYPE T_O_contract; * /
----------------
create or replace
procedure test_cursor (o_c1 OUT sys_refcursor) is
V_T_T_FUND T_T_FUND;
v_T_t_contract T_t_contract;
Start
WITH (CONTRACTS AS
SELECT "p1" PLAN_ID, "s1" SUBPLAN_ID FROM DUAL UNION ALL
SELECT "p2" PLAN_ID, 's2' SUBPLAN_ID FROM DUAL UNION ALL
SELECT "p3" PLAN_ID, 's3' SUBPLAN_ID FROM DUAL
),
Fund)
Select "p1" PLAN_ID, SUBPLAN_ID 's1', 'f1' FUND_ID of all the DOUBLE union
Select "p1" PLAN_ID, SUBPLAN_ID 's1', 'f2' FUND_ID of all the DOUBLE union
Select plan_id "p1", "s1" subplan_id argument, "f3" fund_id Union double all the
Select the argument plan_id 'p2', 's2' subplan_id, 'f2' double fund_id
)
Select T_O_contract (c.PLAN_ID, c.SUBPLAN_ID, T_o_FUND (f.PLAN_ID, f.SUBPLAN_ID, f.FUND_ID))
TO COLLECT FEES IN BULK
in v_T_t_contract
c CONTRACTS, FUND F
where C.PLAN_ID = F.PLAN_ID
and c.SUBPLAN_ID = f.SUBPLAN_ID (+);
Open the O_C1 for
SELECT 't' TYP, v_T_t_contract contract_LST
FROM DUAL;
end;
/
impression o_test
You can declare the attribute OV_FUND as T_T_FUND data type:
create or replace type t_o_contract as object ( plan_id varchar2(128) , subplan_id varchar2(128) , ov_fund t_t_fund ); /
You will be able to do this:
with contracts as ( select 'p1' plan_id, 's1' subplan_id from dual union all select 'p2' plan_id, 's2' subplan_id from dual union all select 'p3' plan_id, 's3' subplan_id from dual ), funds as ( select 'p1' plan_id , 's1' subplan_id, 'f1' fund_id from dual union all select 'p1' plan_id , 's1' subplan_id, 'f2' fund_id from dual union all select 'p1' plan_id , 's1' subplan_id, 'f3' fund_id from dual union all select 'p2' plan_id , 's2' subplan_id, 'f2' fund_id from dual ) select t_o_contract( c.plan_id , c.subplan_id , cast( multiset( select t_o_fund(f.plan_id, f.subplan_id, f.fund_id) from funds f where f.plan_id = c.plan_id and f.subplan_id = c.subplan_id ) as t_t_fund ) ) from contracts c ;
-
Retrieve by using the TYPE attribute of the element type VArray
I want to recover the varray stores through the type attribute type or no matter WHAT work-around.
for example, our type is defined as SUCH CREATE "READS" AS VARRAY (200) OF NUMBER (21: 6); (reading is with elements of number type varray (21.6))
READING is a column in a table of INTERVALS. INTERVALS is a central table and we batch on the INTERVALS that are running sql store procedures. In the stored procedure we have hardcoded the declarations of variables mapping to the element type of type VArray of READING which is NUMBER (21: 6); for example, the stored procedure has declarations of variables such as
NUMBER OF CONSUMPTION (21: 6);
each Varray definition is changed or varray is deleted and recreated with precision and of different size, ex on number (21.6) past to number (25.9), we need declarations of variables to change in our store to batch process procedures. I am looking for is CONSUMPTION variable declaration, refer to item VArray type. I want something like that
INTERVALS OF CONSUMPTION. READINGS. COLUMN_TYPE % TYPE; (I want something like this, identify the type of the items stored by varray)No problem. Discussions forum flags viewers have read so you don't need to keep posting.
In response to your question I don't know of a direct method, but it doesn't seem to be syntactically possible to anchor via a SLIDER instead diverted the road % TYPE and % ROWTYPE.
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> CREATE OR REPLACE TYPE type_name 2 AS 3 VARRAY (200) OF VARCHAR2 (3); 4 / Type created. SQL> SQL> DECLARE 2 CURSOR cursor_name 3 IS 4 SELECT COLUMN_VALUE column_name 5 FROM TABLE (type_name ()); 6 7 record_name cursor_name%ROWTYPE; 8 9 variable_name record_name.column_name%TYPE := 'AAAA'; 10 BEGIN 11 NULL; 12 END; 13 / DECLARE * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 9 SQL>
However, if you try this with a digital item type precision and scale are not kept and you will end up with a NUMBER.
I said just a subtype corresponding to the same place, declaring variables, on this basis and do with it.
-
Function returns the object type
Hello
This isn't a duplicate of another thread, I posted earlier with the procedure...
Now I try the subprogramme with the service, as required by the client., so I opened the question in another thread
I get the following error:, I tried it but no luck on my sideCREATE OR REPLACE TYPE Type_Rt IS OBJECT (Rt_Type VARCHAR2(2000), cdtRt VARCHAR2(2000), lqdtRt VARCHAR2(2000), Olk VARCHAR2(2000), cdtwh VARCHAR2(2000) ) CREATE OR REPLACE TYPE Rt_Type_Var IS TABLE OF Type_Rt; CREATE OR REPLACE FUNCTION FUNC_RAT ( Cp_Id VARCHAR2, St_Id VARCHAR2, cdt_Rt VARCHAR2, liq_Rt VARCHAR2, Olk VARCHAR2, cdt_Wh VARCHAR2) RETRUN Rt_Type_Var IS v_typ_rat_List Type_Rt ; var1_nri varchar2(100) := 'ST'; BEGIN IF ( Cp_Id = 'NTE' AND St_Id = 'Y' ) THEN --select distinct ne_rt_issue into var1_nri from rt_con where ltr_ener = cdt_rt; v_typ_rat_List := new Type_Rt ('STRT',var1_nri ,liq_Rt,'Stle' ,null); END IF; RETURN v_typ_rat_List; END; /
After you create the function, I have to call this function asPLS-00382: expression is of wrong type
Could you please help me with thisSELECT * FROM TABLE(FUNC_RAT ('NTE','Y','AB','C','Y',NULL))
The same basic problem as in your previous thread. Confusion between creating an object from a collection/table of this object.
Here's a basic example:
SQL> create or replace type TScalar is object( 2 id integer, 3 name varchar2(10) 4 ); 5 / Type created. SQL> SQL> create or replace type TArray is table of TScalar; 2 / Type created. SQL> SQL> --// creating a scalar SQL> select TScalar( 1, 'John' ) as OBJ from dual; OBJ(ID, NAME) -------------------- TSCALAR(1, 'John') SQL> SQL> --// creating an array/collection SQL> select 2 TArray( 3 TScalar( 1, 'John' ), 4 TScalar( 2, 'Tom' ) 5 ) as ARRAY 6 from dual; ARRAY(ID, NAME) -------------------------------------------------- TARRAY(TSCALAR(1, 'John'), TSCALAR(2, 'Tom')) SQL>
So in your function, you will need to place objects in the collection.
return( Rt_Type_Var( --// instantiate the collection Type_Rt ('STRT',var1_nri ,liq_Rt,'Stle' ,null) --// place an object into the collection ) );
And use appropriate type names and the object. Poorly chosen and non standard naming conventions just add to the confusion.
-
Where I'm going wrong with the object Type
Hello world
I am trying to insert data into a table using a type of object
Here is my code
Please help me where I'm wrong...
Thank you
Code for the object. Type
Now I want to insert data into the table like thiscreate or replace type emp_rec_type as object ( empno number ,name varchar2(20) ,salary number(7,2) ,job varchar2(10) ,hiredate date ,commno number(7,2) ,deptno number(4));
I don't want to create a variable of the object... Initialization type I want to create just to insert the value using the default constructor.begin insert into emp5 values(emp_rec_type(5,'jack',1000,'salesman','12-apr-2000',300.00,20)); end;
Concerning
ProstYou can create the table of the object:
create table emp5 of emp_rec_type;
Kind regards
Sayan M. -
Create the object type with a member function that returns an array of the object type
Hello
Is possible to compile code like this in Oracle SQL?
CREATE OR REPLACE TYPE type_obj IS OBJECT ( MEMBER FUNCTION f RETURN table_obj ); CREATE OR REPLACE TYPE table_obj AS TABLE OF type_obj;
In Java, it would be possible.
Thanks in advance
Circular dependencies must be resolved by means of REF pointers and incomplete type definition.
See: Oracle objects management
CREATE or REPLACE TYPE type_obj;
/
CREATE or REPLACE TYPE table_obj AS TABLE OF ref type_obj;
/
CREATE or REPLACE TYPE type_obj () IS OBJECT
fake number
Table_obj RETURN of the FUNCTION MEMBER f
);
/
Now, it must implement the body of type.
Note that a table of the REFs is not very useful in the plain of PL/SQL, the underlying data must be stored in a nested table if you want to use.
-
Test a SP with the object type
Hi, I have a MS in which I created an object of TYPE and through multiple values as param.
SP signatureTYPE typ_clint_id_rec AS OBJECT ( CLIENT_ID VARCHAR2(20); TYPE typ_clinet_id_tab AS TABLE OF typ_clint_id_rec;
Now, I'm testing the PC like this:PROCEDURE test( in_username IN char in_client_name IN typ_clinet_id_tab, in_out_cur IN OUT out_cursor) ;
But it gives wrong number or types of arguments in the call to typ_clinet_id_tab?declare ref_cursor sys_refcursor; in_client_name typ_clinet_id_tab := typ_clinet_id_tab (); begin in_client_name := typ_clinet_id_tab ('AAA','BBB'); test(in_username=> 'test' , in_client_name=>in_client_name ,in_out_cur => ref_cursor); end;
Can someone tell me what is wrong with that?
AashishEach attribute of your object to table table must consist of the typ_clint_id_rec object.
So the data must be wrapped as follows;
typ_clinet_id_tab (typ_clint_id_rec'AAA'),typ_clint_id_rec('BBB'));
-
Background image, change of color of the object/type
I retouched an image that I then placed in CC Id as part of the background. Unfortunately, the type and the items that were on top of this image are corrupted. The text looks like it's more "BOLD" and transparent colored box of 50% is much darker where they overlap the picture. This problem appears if I make a PDF print. Anyone know what is happening here, and how I can solve it? Thanks in advance!
In InDesign, choose the [Black] swatch is automatically set to overprinting. It is defined in the preferences > appearance of black. Uncheck the option or create your own black shade to K100.
-
Function returning the tree used with the object type
Hi guys!
I'm fighting for some time now of a function that should return the tree structure of the employees. Let me clarify...
I have a table say Manager and employees (two columns for an example)
MANAGER_ID
EMPLOYEE_ID
Example:
MAN_ID - 1; EMPLOYE_ID - 2;
MAN_ID - 2; EMPLOYE_ID - 3;
MAN_ID - 2; EMPLOYE_ID - 4;
MAN_ID - 4; EMPLOYE_ID - 5
The purpose of my function is back for a specified MAN_ID everyone in the tree...
Example:
RETURN_TREE (1) return {2,3,4,5};
RETURN_TREE (2) returns {3,4,5};
RETURN_TREE (4) returns {5};
How to get there?
With respect,
PsmakRAnd use BULK COLLECT or the COLLECT function to build the collection:
create type emp_table as table of number(6); /
DECLARE v_emp_list emp_table; BEGIN select cast(collect(employee_id) as emp_table) into v_emp_list from employees connect by prior employee_id = manager_id start with manager_id = :p_man_id -- or /* select employee_id bulk collect into v_emp_list from employees connect by prior employee_id = manager_id start with manager_id = :p_man_id */ END; /
-
Collection to contain the object type? OR typical hash in java?
Hi people,
I used to work in perl and use hashes a lot (a typical perl hash is String = > string). Well now, I am doing something a bit dirty - I need something that does what the class that I put in place down, it doesn't... Y at - it such an object which wouldn't bother me that the keys and values are not unique (can be same values with the keys and values). What I must apply myself, or is there something that does this...
No collection seems to fit in this...
public class CantFindYouInJava {}
private String [] listOfKeys;
private String [] listOfValues.
' Public Sub put (String key, String value) {}
where int = listOfkeys.length + 1;
listOfKeys [where] = key;
listOfValues [where] = value;
}
..
}koszta5 wrote:
I need an object that did what did the class that I've set up there... Y at - it such an object which wouldn't bother me that the keys and values are not unique (can be same values with the keys and values). What I must apply myself, or is there something that does this...It really depends on what the relationship between a key and its associated value, and the kind of performance you expect to recover from.
Kayaman suggestion is probably the best if the relationship of key / value is 1-to-many; You can also write your own map
> class. If it's really one-to-many, and you need good performance in both directions, you may need to wrap two MultiMaps - one go of the key values and a second to go in the other direction. Don't know what you'd call it however. Winston
-
BEGINNING about the object type indexes per table
Hi all
I've been tyring just what follows.
declare
type ty_tab is table of the directory index ty_test;
my_tab ty_tab;
Start
my_tab (1):=ty_test(1111,ty_info('ashok',1000));
my_tab (2):=ty_test(2222,ty_info('Rashmi',2000));
my_tab (3):=ty_test(3333,ty_info('unknown',3000));
for me in my_tab.first... loop of my_tab. Last
dbms_output.put_line (my_tab (i) .empno |) » '|| my_tab (i) .info);
end loop;
end;
/
When running the script, I get the following error.
ORA-06550: line 13, column 25:
PLS-00306: wrong number or types of arguments in the call to ' |'
ORA-06550: line 13, column 4:
PL/SQL: Statement ignored
Can anyone suggest?
Thanxthe attributes of the type ty_info assuming that are name and val:
dbms_output.put_line(my_tab(i).empno||' '||my_tab(i).info.name||' '||my_tab(i).info.val);
SY.
Published by: Solomon Yakobson, March 16, 2010 05:01
-
execution of actions on a selection based on the object type
Hello.
I am trying to write an AppleScript that considers the current selection, then redefines the scaling of all lines of that selection to 100%, and then sets the absolute horizontal scale of the remaining elements of the selection to 100%.
My attempts so far are:
say application «Adobe InDesign CS3»
put Original_Selection to selection
put to each graphic line of Original_Selection Lines_Selection -this part is not working
put transform reference point of window layout 1 to anchor Center
Choose Lines_Selection
redefine the scaling to the selection {1.0 , 1.0}
Choose Original_Selection - but it must be ' Original_Selection less Lines_Selection ' somehow
put horizontal scale absolute at 100
end say
None of this really works as I expect, but I can't find out the required syntaxes. Anyone know where I am going wrong?
Thank you.
Try this:
say application «Adobe InDesign CS3»
the value transform reference point of window layout 1 of anchorage Center
redefine the scaling of (each point of selection which class is the line graph) to {1.0, 1.0}
the horizontal scale absolute value of (each element of selection whose class is not graphic line) to 100
end say
--
Shane Stanley [email protected]>
AppleScript Pro, April 2010, Florida http://www.applescriptpro.com>
-
Type of the object called several times Oracle constructor
I have an object of type with a custom constructor. In SQL, when I reference attributes the constructor is called several times in Oracle 11.2.0.4.
- Why the constructor is called more than once?
- How can I stop it?
My current job is about to reference attributes and use the / * + materialize * / tip.
Problem installationcreate or replace type Foo as object ( Bar1 NUMBER, Bar2 NUMBER, Bar3 NUMBER, CONSTRUCTOR FUNCTION Foo(p_Bar1 NUMBER, p_Bar2 NUMBER, p_Bar3 NUMBER) RETURN SELF AS RESULT DETERMINISTIC ) / create or replace type body Foo is -- Member procedures and functions CONSTRUCTOR FUNCTION Foo(p_Bar1 NUMBER, p_Bar2 NUMBER, p_Bar3 NUMBER) RETURN SELF AS RESULT DETERMINISTIC AS BEGIN SELF.Bar1 := p_Bar1; SELF.Bar2 := p_Bar2; SELF.Bar3 := p_Bar3; dbms_output.put_line('Foo Constructor Called'); RETURN; END; end;
Problem
-- Constructor is called 6 times! -- Once for each column and once for each predicate in the where clause. SELECT x.f.bar1 AS bar1, x.f.bar2 AS bar2, x.f.bar3 AS bar3, f FROM ( SELECT foo(p_Bar1 => 1, p_Bar2 => 2, p_Bar3 => 3) f FROM dual d ) x WHERE x.f.bar1 = x.f.bar1 AND x.f.bar2 = x.f.bar2
Output
Foo constructor called
Foo constructor called
Foo constructor called
Foo constructor called
Foo constructor called
Foo constructor called
Workaround
-- Work Around -- Constructor is called 3 times -- Once for each column in the inline view. -- Note, I removed column f (the object type) because it's not compatible with the materialize hint. WITH y AS ( SELECT /*+ materialize */ x.f.bar1 AS bar1, x.f.bar2 AS bar2, x.f.bar3 AS bar3 FROM ( SELECT foo(p_Bar1 => 1, p_Bar2 => 2, p_Bar3 => 3) f FROM dual d ) x ) SELECT y.bar1, y.bar2, y.bar3 FROM y WHERE y.bar1 = y.bar1 AND y.bar2 = y.bar2
Another solution is described in this thread... Access to the fields of an object custom type... which makes use of a type of collection combined with SCOREBOARD operator, like this...
create or replace type FooTable as table of Foo; SELECT x.bar1 AS bar1, x.bar2 AS bar2, x.bar3 AS bar3, value(x) f FROM table(FooTable( foo(p_Bar1 => 1, p_Bar2 => 2, p_Bar3 => 3) )) x WHERE x.bar1 = x.bar1 AND x.bar2 = x.bar2 ; BAR1 BAR2 BAR2 F 1 2 3 (1, 2, 3) Foo Constructor Called
Hope that helps...
Gerard
Maybe you are looking for
-
I can't watch YouTube on Safari... once again.
Yes, I tried to download and update flash player. But it simply does not work, and when I tried to use HTML5
-
El Capitan permissions bad for lib with multiple users
On my Mac with multiple users and running El Capitan, I encountered a problem with an application (GoGlobal) failed to start with "errno = 13", which is a problem of permissions with usr/local/lib /. I determined that on Yosemite, usr/local/lib was o
-
I searched a VGA adapter cable for my Libretto U100 so I can have one on the monitor at home and at work. Unfortunately, I have not been able to locate anyone to sell them, and that they are not listed on the Toshiba site as an accessory.Does anyone
-
officejet6600: scanner stops mid scan and said troubleshooting user cancelled
Scan stops mid scan and freezes. Troubleshooting program says "user cancelled" during the test, but I didn't touch system. All connections are fine. uninstalled and reinstalled the drivers. Printer restarted several times. Help!
-
After refusing to allow a person in India take control of my computer, I am unable to get my hotmail accounts. I don't know how they cut all my Hotmail account, but they did. NOW, GET MY HOTMAIL SERVICE LIGHT NOW. YOU'RE NOT GOING TO LOVE MY NEXT MOV