Nested table updation in FOR Cursor loop
Hello,
I have nested table as follows:
SQL> desc fp
Name Null? Type
ORDER_NUM NOT NULL VARCHAR2(10)
ORDER_TIE_NUM NOT NULL VARCHAR2(10)
FACILITY NOT NULL VARCHAR2(10)
ON_SHORTS NUMBER(2)
ACTIVE_SHORTS NUMBER(2)
PARTS DPM_TRANSFORM_CODE.FP_SLC_SHORT
FIRST_SHORT DATE
LAST_SHORT DATE
SQL> desc DPM_TRANSFORM_CODE.FP_SLC_SHort
DPM_TRANSFORM_CODE.FP_SLC_SHort TABLE OF DPM_TRANSFORM_CODE.FP_SHORT_INFO
Name Null? Type
PART_NUM VARCHAR2(7)
AREA VARCHAR2(7)
PART_QTY NUMBER(3)
ON_SHORT_CNT NUMBER(4)
OFF_SHORT_CNT NUMBER(4)
FIRST_DATE DATE
LAST_DATE DATE
UPDATE TABLE(SELECT PARTS FROM DPM_REPORTING.FP WHERE ORDER_NUM = P.ORDER_NUM AND ORDER_TIE_NUM = P.ORDER_TIE_NUM) PARTS
SET PARTS.OFF_SHORT_CNT = PARTS.OFF_SHORT_CNT + 1
WHERE PARTS.last_date < SYSDATE - 2/24;
This Update Statement is in FOR Cursor Loop
where select statement for the cursor is
"SELECT ORDER_NUM,ORDER_TIE_NUM,PARTS FROM DPM_REPORTING.FP WHERE FACILITY = 'PN1'"
This select statement generates 20000 records & due to which the Update statement gets executed that many times inside FOR loop.The Procedure has become quite slow due to this.
Please help.
Thanks,
Rekha
You could do it all in one sql update statement, without any pl/sql or cursor or looping:
UPDATE fp t1
SET t1.parts =
CAST (MULTISET (SELECT part_num, area, part_qty, on_short_cnt,
CASE WHEN last_date < SYSDATE - 2/24
THEN off_short_cnt + 1
ELSE off_short_cnt
END,
first_date, last_date
FROM TABLE (SELECT parts
FROM fp
WHERE facility = 'PN1'
AND order_num = t1.order_num
AND order_tie_num = t1.order_tie_num))
AS fp_slc_short)
WHERE t1.facility = 'PN1'
/
Similar Messages
-
Nested Tables in Pages for iPad
I am using Pages on my iPad2. When opening a document with nested tables, it loses oll formatting for the nested tables. Is there a way to avoid this?
Doesnt look like it doesn combination Letter/number/roman numeral lists. I was able to get it to do multi level numbers or letters. But no combinations. As soon as you indicate letter as your second, it resets the next level up number list.
1 text
1 text
1 text
2 text
3 text
2 text
2 text
3 text
Jason -
Nested table update gets ORA-00904 with ExecuteSQL, error-free in TOAD
I'm trying to run an UPDATE query through the ExecuteSQL method
of the oraDatabase object. The catch seems to be that this one
affects a nested table (field to be updated is a table itself).
This SQL runs perfectly in T.O.A.D. ...
UPDATE B457.AIRLINE a SET
a.rental_cust_code=B457.RENTCUSTCODELIST(rentcustcodes
('45645'),rentcustcodes('1234'),rentcustcodes('234234')) WHERE
a.AIRLINE_CODE='RCR'
...but, it produces the "SQL execution error, ORA-00904: invalid
column name" when run using ExecuteSQL.
Do I need to use a different syntax?and the complete example
SQL> create or replace TYPE t_indirizzo AS OBJECT (
2 via VARCHAR(45),
3 numero NUMBER,
4 cap INTEGER(5),
5 citta VARCHAR(30),
6 provincia VARCHAR(30),
7 regione VARCHAR(30)
8 );
9 /
Type created.
SQL>
SQL>
SQL> create or replace TYPE t_telefono AS OBJECT (
2 num_tel NUMBER(15)
3 );
4 /
Type created.
SQL>
SQL> create or replace TYPE t_listaTelefono AS TABLE OF t_telefono
2 /
Type created.
SQL>
SQL> create or replace TYPE t_cliente AS OBJECT (
2 cod_cliente NUMBER(8),
3 indirizzo t_indirizzo,
4 email VARCHAR(30),
5 telefono t_listaTelefono
6 ) NOT FINAL;
7 /
Type created.
SQL>
SQL> CREATE TABLE cliente OF t_cliente(
2 cod_cliente NOT NULL,
3 indirizzo NOT NULL,
4 email NOT NULL,
5 PRIMARY KEY (cod_cliente)
6 ) nested table telefono store as numTelCli_tab
7 return as value
8 /
Table created.
SQL> -
Nested FOR cursor LOOPs, BASIC QUESTION
Hello,
I am trying to nest a For-loop using a cursor (see below), but the program is not entering the second (nested) for-loop. This program compiles fine, but during run-time, the nested loop does not execute. I'd rather not use FETCH statements and keep everything in place. I think the solution is rather trivial, but I'm new to PL/SQL. PLEASE HELP!!!!!
cursor c1 is
select coi_con_uid,coi_not_code,coi_closed_yn,coi_timestamp
from s_coi_con_issue
where coi_not_code = 'NOT107'
and coi_timestamp <= v_aweekago
and coi_closed_yn = 'N';
cursor c2 is
select tsk_uid
from s_tsk_task
where tsk_status in ('C')
and tsk_tty_code = 'CONTAC'
and tsk_date_end = '' FOR UPDATE;
BEGIN
select to_date(sysdate - 7) into v_aweekago from dual;
DBMS_OUTPUT.PUT_LINE('System date used is ' || v_aweekago);
FOR coi_row in c1 LOOP
v_tsk_cnt := 0;
v_coi_row_cnt := v_coi_row_cnt + 1;
v_con_uid := rtrim(to_char(coi_row.coi_con_uid));
v_tsk_act_str := ('"CON_UID","' || v_con_uid || '"') ;
DBMS_OUTPUT.PUT_LINE('COI_CON_UID: ' || v_con_uid);
DBMS_OUTPUT.PUT_LINE('v_tsk_act_str: ' || v_tsk_act_str);
-----The Program is not entering into this Loop
FOR tsk_row in c2 LOOP
v_update_cnt := v_update_cnt + 1;
update s_tsk_task
set tsk_status = 'A'
where tsk_uid = tsk_row.tsk_uid and
tsk_action_string = v_tsk_act_str;
DBMS_OUTPUT.PUT_LINE('----Task updated');
END LOOP;
END LOOP;
COMMIT;using your query on your cursor c2 when you execute it on sql*plus did it return any rows?
select tsk_uid
from s_tsk_task
where tsk_status in ('C')
and tsk_tty_code = 'CONTAC'
and tsk_date_end = ''; if not it might have something to do with the predicates in your where clause
and tsk_date_end = '';consider revising your c2 cursor select statement to something like:
cursor c2 is
select tsk_uid
from s_tsk_task
where tsk_status = 'C'
and tsk_tty_code = 'CONTAC'
and tsk_date_end IS NULL
FOR UPDATE; -
Search in Nested Tables and Insert the result into new Nested Table!
How can I search in Nested Tables ex: (pr_travel_date_range,pr_bo_arr) using the SQL below and insert the result into a new Nested Table: ex:g_splited_range_arr.
Here are the DDL and DML SQLs;
Don't worry about the NUMBER( 8 )
CREATE OR REPLACE TYPE DATE_RANGE IS OBJECT ( start_date NUMBER( 8 ), end_date NUMBER( 8 ) );
CREATE OR REPLACE TYPE DATE_RANGE_ARR IS TABLE OF DATE_RANGE;
DECLARE
g_splited_range_arr DATE_RANGE_ARR := DATE_RANGE_ARR( );
g_travel_range DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
g_bo_arr DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
FUNCTION split_date_sql( pr_travel_date_range DATE_RANGE,
pr_bo_arr DATE_RANGE_ARR )
RETURN DATE_RANGE_ARR
IS
l_splited_range_arr DATE_RANGE_ARR;
BEGIN
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM (WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
UNION ALL
SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date);
RETURN l_splited_range_arr;
END;
BEGIN
g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP
DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-' || g_splited_range_arr(index_g_splited_range_arr).end_date );
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
NULL;
END;Or can I create a VIEW with parameters of Nested Tables in it so I can simply call
SELECT *
BULK COLLECT INTO g_splited_range_arr
FROM view_split_date(g_travel_range,g_bo_arr);@riedelme
For your questions:
1) I don't want to store in the database as a nested table
2) I don't want to retrieve data from the database. Data will come from function split_date() parameter and data will be processed in the function and function will return it in nested table format. For more detail please look at the raw function SQL.
I have a SQL like:
WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM travel
UNION ALL
SELECT tr_end_date, 0 FROM travel
UNION ALL
SELECT bo_start_date - 1, 1 FROM black_out_dates
UNION ALL
SELECT bo_end_date + 1, -1 FROM black_out_dates),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val)
AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val)
AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date;I want to change the tables black_out_dates and travel to Nested Array so I can use it in a function with Nested Array travel and Nested Array black_out_dates parameters and the function will return Nested Array of date ranges.
Here is what I want in raw SQL:
DECLARE
g_splited_range_arr DATE_RANGE_ARR := DATE_RANGE_ARR( );
g_travel_range DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
g_bo_arr DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
FUNCTION split_date_sql( pr_travel_date_range DATE_RANGE,
pr_bo_arr DATE_RANGE_ARR )
RETURN DATE_RANGE_ARR
IS
l_splited_range_arr DATE_RANGE_ARR;
BEGIN
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM (WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
UNION ALL
SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date);
RETURN l_splited_range_arr;
END;
BEGIN
g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP
DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-' || g_splited_range_arr(index_g_splited_range_arr).end_date );
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
NULL;
END;I must change the tables black_out_dates and travel in a way so it will be something like
FROM TABLE( pr_travel_date_range )to get the result into l_splited_range_arr so it will be something like
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM ( -
How do I reference a column in a nested table in a trigger. I am issuing an update statement:
UPDATE TABLE (SELECT inv_level
FROM inventory_level
WHERE machine_id = '1111'
SET inventory_level = '15'
WHERE column_id = '2'
I want to create a trigger that execute before the insert. I want to insert the machine_id, the column_id, inventory_level into a change history table. The issue is he column_id and inventory_level fields are in the nested table. I tried to reference them as :NEW.column_id, but that didn't work.I too have had problems working with triggers & nested tables. This may help
Imagine the scenario of a table that holds customer data that needs a specific record per user of the database to indicate if they can contact that customer.
To solve this I created the following
create type contact_type as object
(username varchar2(30),
can_mail number,
can_phone number);
create type contact_nt_type as table
of contact_type;
--table cust
create table cust_table(
custid number,
custname varchar2(50),
contact_nt contact_nt_type)
nested table contact_nt store as contact_nt_tab;
-- populate tables
insert into cust_table
values(1001,'Customer1',
contact_nt_type(
contact_type('SCOTT',1,0),
contact_type('TIMS',0,1)));
insert into cust_table
values(1002,'Customer2',
contact_nt_type(
contact_type('SCOTT',0,0),
contact_type('TIMS',0,0)));
-- view cust_vu
create or replace view cust_vu
as
select ct.custid, ct.custname, nt.can_mail, nt.can_phone
from cust_table ct, table(ct.contact_nt) nt
where nt.username = user;
Now, if scott looks at the customer through the view he sees one set of contact details and if I look I see another. But if we try to update the view we get
ORA-01733: virtual column not allowed here
To solve this create an "instead of" trigger
create or replace trigger cust_vu_update
instead of update on cust_vu
for each row
begin
-- update the parent table
update cust_table
set custname = :new.custname
where custid = :old.custid;
-- update the nested table
update table(
select contact_nt
from cust_table
where custid = :old.custid)
set can_mail = :new.can_mail,
can_phone = :new.can_phone
where username = user;
end;
The documentation has a whole section on triggers & nested tables which, for me, did not solve any of my issues. Following the Create trigger syntax, specifically the dml_event_clause, caused me 0600 errors and my session was terminated!
There may be better solutions but this one works for me. -
Nested Tables and Advanced Queues- Please Help.
How do i work with NestedTable type and Advanced Queue.
I have done the following
I have Oracle 8.1.7 enterprise edition.
create type myType as TABLE OF varchar(32);
create type myObject as OBJECT (
id int,
myt myType);
DECLARE
BEGIN
dbms_aqadm.create_queue_table(
queue_table => 'my_queue_table',
multiple_consumers => TRUE,
queue_payload_type => 'myObject',
compatible => '8.1.3'
END;
The Nested Table and Object are created successfully.
but the queue is not created.
I get the following message.
DECLARE
ERROR at line 1:
ORA-22913: must specify table name for nested table column or
attribute
ORA-06512: at "SYS.DBMS_AQADM_SYS", line 2012
ORA-06512: at "SYS.DBMS_AQADM", line 55
ORA-06512: at line 3
I know how to specify the nested table storage clause for
create table statement, but there is no provision for
it in the create_queue_table procedure.
Any help will be greately appriciated.
i have already created and tested aqs with simple data types,
also i have created simple tables with nested table type
elements.
but the combo of Nested tables and AQ is not working.
thanks in advance.Hi Francois. Thank you very much for your reply, but it seems that i still get errors. So let me tell what i have done.
As you suggested me: i have done a block based on a sub-query for the nested-table:
'select courses from department where name= :department.name'.
In the master block(department) i have the when-new-record-instance trigger:
Declare
LC$Req varchar2(256);
Begin
LC$Req := '(select ns.courses from table
( select courses from department where name = ''' || :DEPARTMENT.name || ''' ) ns )';
Go_block('block11');
Clear_Block ;
Set_Block_Property( 'block11', QUERY_DATA_SOURCE_NAME, LC$Req ) ;
Execute_query ;
End ;
Now the errors i receive, this time in the runtime mode are:
- FRM-41380: Cannot set the blocks query data source
-FRM-41003: This function cannot be performed here.
Since it seems that you know how to work with the nested table i would really appreaciate your help. I am new in the nested table and if you could give an ex with my tables it would be great.
Thank you in advance. -
Can a nested table Tab1 have another nested table Tab2 as an attribute? If yes, when the declaration of storing (e.g., nested table Tab2 store as Tab2_TAB) goes, in nested table Tab1 declaration (create type Tab1 as table of ...) or in Create table X that used double nested tables? THANKS for whoever can help me that!!!!! Elka
Multi-level nesting is only available since 9i. Before that, you'd need to break out the nesting as references to other object tables. Which is still a viable option depending on the business rules of your system. You're code was basically right, I just added an object table of type d_t with the syntax to provide storage for all the nested tables and ran a test insert to make sure you could get data in. Works fine. If you select * from that new table you'll see everything, but you may want to de-nest to only get specific data so you'll need to use the table function in your select statement. The oracle docs for all of this are quite good in the 'Application Developer's Guide - Object-Relational Features'. Check it out, and good luck!
Jason Ladd
E-Tech Solutions
create type a_t as object (
foobar varchar(20)
create type a_list_t as table of a_t
create type b_t as object (
foo_b varchar2(20),
foo_b_list a_list_t
create type b_list_t as table of b_t
create type c_t as object (
foo_c varchar2(20),
foo_c_list b_list_t
create type c_list_t as table of c_t
create type d_t as object (
foo_d varchar2(20),
foo_d_list c_list_t
create table d_table of d_t
nested table foo_d_list store as d_ntab1
(nested table foo_c_list store as d_ntab2
(nested table foo_b_list store as d_ntab3
insert into d_table values(
'foo_d',
(c_list_t(c_t('foo_c',(b_list_t(b_t('foo_b',(a_list_t(a_t('foobar'))))))))) -
Help how to create full set of nested table with given xml schema?
Hi everyone, I am new to oracle and programming language. Recently I was asked to create nested table with given a complex xml schema. I knew that after the registration of xsd file, oracle will generate few tables( including nested table) and types for the users. But it seems to be not complete set of tables. Can anyone please help me with the problem. Really thanks a lot on the help given. I would like to give extra explanation if what I have given above is not clear enough. Thanks
How about posting the XML Schema, the code you used to register it, the database version you are using and the list of nested tables that were generated...
-
Using FOR .. LOOP counter in handling of PL/SQL procedures with nest. table
Hi all!
I'm learning PL/SQL on Steve Bobrovsky's book (specified below sample is from it) and I've a question.
In the procedure of specified below program used an integer variable currentElement to get reference to the row of nested table of %ROWTYPE datatype.
Meanwhile, the program itself uses a common FOR .. LOOP counter i.
DECLARE
TYPE partsTable IS TABLE OF parts%ROWTYPE;
tempParts partsTable := partsTable();
CURSOR selectedParts IS
SELECT * FROM parts ORDER BY id;
currentPart selectedParts%ROWTYPE;
currentElement INTEGER;
PROCEDURE printParts(p_title IN VARCHAR2, p_collection IN partsTable) IS
BEGIN
DBMS_OUTPUT.PUT_LINE(' ');
DBMS_OUTPUT.PUT_LINE(p_title || ' elements: ' || p_collection.COUNT);
currentElement := p_collection.FIRST;
FOR i IN 1 .. p_collection.COUNT
LOOP
DBMS_OUTPUT.PUT('Element #' || currentElement || ' is ');
IF tempParts(currentElement).id IS NULL THEN DBMS_OUTPUT.PUT_LINE('an empty element.');
ELSE DBMS_OUTPUT.PUT_LINE('ID: ' || tempParts(currentElement).id || ' DESCRIPTION: ' || tempParts(currentElement).description);
END IF;
currentElement := p_collection.NEXT(currentElement);
END LOOP;
END printParts;
BEGIN
FOR currentPart IN selectedParts
LOOP
tempParts.EXTEND(2);
tempParts(tempParts.LAST) := currentPart;
END LOOP;
printParts('Densely populated', tempParts);
FOR i IN 1 .. tempParts.COUNT
LOOP
IF tempParts(i).id is NULL THEN tempParts.DELETE(i);
END IF;
END LOOP;
FOR i IN 1 .. 50
LOOP
DBMS_OUTPUT.PUT('-');
END LOOP;
printParts('Sparsely populated', tempParts);
END;
/When I've substituted an INTEGER global variable with such FOR .. LOOP counter, an APEX have returned an error "ORA-01403: no data found".
DECLARE
TYPE partsTable IS TABLE OF parts%ROWTYPE;
tempParts partsTable := partsTable();
CURSOR selectedParts IS
SELECT * FROM parts ORDER BY id;
currentPart selectedParts%ROWTYPE;
PROCEDURE printParts(p_title IN VARCHAR2, p_collection IN partsTable) IS
BEGIN
DBMS_OUTPUT.PUT_LINE(' ');
DBMS_OUTPUT.PUT_LINE(p_title || ' elements: ' || p_collection.COUNT);
FOR i IN 1 .. p_collection.COUNT
LOOP
DBMS_OUTPUT.PUT('Element is ');
IF tempParts(i).id IS NULL THEN DBMS_OUTPUT.PUT_LINE('an empty element.');
ELSE DBMS_OUTPUT.PUT_LINE('ID: ' || tempParts(i).id || ' DESCRIPTION: ' || tempParts(i).description);
END IF;
END LOOP;
END printParts;
BEGIN
FOR currentPart IN selectedParts
LOOP
tempParts.EXTEND(2);
tempParts(tempParts.LAST) := currentPart;
END LOOP;
printParts('Densely populated', tempParts);
FOR i IN 1 .. tempParts.COUNT
LOOP
IF tempParts(i).id is NULL THEN tempParts.DELETE(i);
END IF;
END LOOP;
FOR i IN 1 .. 50
LOOP
DBMS_OUTPUT.PUT('-');
END LOOP;
printParts('Sparsely populated', tempParts);
END;
/When I've tried to handle this code in SQL*Plus, the following picture have appeared:
Densely populated elements: 10
Element is an empty element.
Element is ID: 1 DESCRIPTION: Fax Machine
Element is an empty element.
Element is ID: 2 DESCRIPTION: Copy Machine
Element is an empty element.
Element is ID: 3 DESCRIPTION: Laptop PC
Element is an empty element.
Element is ID: 4 DESCRIPTION: Desktop PC
Element is an empty element.
Element is ID: 5 DESCRIPTION: Scanner
Sparsely populated elements: 5
DECLARE
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 14
ORA-06512: at line 35What's wrong in code(or what I have not understood)? Help please!942736 wrote:
What's wrong in code(or what I have not understood)? Help please!First code. You have collection of 10 elements:
1 - null
2 - populated
3 - null
4 - populated
5 - null
6 - populated
7 - null
8 - populated
9 - null
10 - populated
Then you delete null elements and have 5 element collection
2 - populated
4 - populated
6 - populated
8 - populated
10 - populated
Now you execute:
printParts('Sparsely populated', tempParts);Inside procedure you execute:
currentElement := p_collection.FIRST;
This assingns currentElement value 2. Then procedure loops 5 times (collection element count is 5). Element 2 exists. Inside loop procedure executes:
currentElement := p_collection.NEXT(currentElement);
which assigns currentElement values 4,6,8,10 - all existing elements.
Now second code. Everything is OK until you delete null elements. Again we have:
2 - populated
4 - populated
6 - populated
8 - populated
10 - populated
Again you execute:
printParts('Sparsely populated', tempParts);Now procedure loops 5 times (i values are 1,2,3,4,5):
FOR i IN 1 .. p_collection.COUNT
Very first iteration assingns i value 1. And since collection has no element with substript 1 procedure raises no data found.
SY. -
How to update a column in a nested table for a given record in the master t
Hi I have translations for all attributes of an item stored as a nested table
CREATE OR REPLACE TYPE T_ITM_ATTR AS OBJECT(
ATTR_NM VARCHAR2(30),
ATTR_VAL VARCHAR2(200 CHAR),
ATTR_STS_BL NUMBER(1))
INSTANTIABLE
FINAL
CREATE OR REPLACE TYPE T_ITM_ATTRIBUTES AS TABLE OF T_ITM_ATTR;
CREATE TABLE XGN_MOD_ITEMS_T
IDS NUMBER,
MOD_IDS NUMBER NOT NULL,
MOD_ITM_IDS NUMBER NOT NULL,
LGG_ID VARCHAR2(3 CHAR) NOT NULL,
ITM_TYPE VARCHAR2(50 CHAR) NOT NULL,
ITM_NM VARCHAR2(50 CHAR) NOT NULL,
ITM_BLOCK VARCHAR2(50 CHAR),
ITM_ATTR T_ITM_ATTRIBUTES,
ITM_COL1 VARCHAR2(1 CHAR),
ITM_DSC VARCHAR2(100 CHAR),
CREATED_BY VARCHAR2(30 CHAR) DEFAULT USER NOT NULL,
CREATION_DATE DATE DEFAULT SYSDATE NOT NULL,
LAST_UPDATED_BY VARCHAR2(30 CHAR),
LAST_UPDATE_DATE DATE
NESTED TABLE ITM_ATTR STORE AS NESTED_ITM_ATTR_T
TABLESPACE XGN4_TAB
PCTUSED 40
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
What I want to do is to update only the attr_val of each item to a value coming from a temporary table where the user inserted his translations
So how can I update ?
this doesn't work since I have to know the previous value?
update table(
select t2.attr_val
from XGN_MOD_ITEMS_T t1, table(t1.itm_attr) t2
where t1.mod_itm_ids=160) attr
set value(attr) = 'Profil'
where value(attr) = 'Profile'
This updates all occurences for all entries wich doesn't work either because I have for each language another record
UPDATE /*+ NESTED_TABLE_GET_REFS */
NESTED_ITM_ATTR_T
SET attr_val = 'SHIT'
WHERE attr_val = 'Profile'http://www.psoug.org/reference/nested_tab.html
Look for UPDATE. There is a working demo on the page.
That said nested tables are not a good place to store data. Reconsider using relational tables with, if necessary, object views. -
Open cursor for a nested table
Hi,
I want to open a cursor like:
open c1 for select * from emp;
BUT
I what the cursor results to be populated with contents of a nested table or associative array..
How can this be done???
Thanks in advance,
teoWell, given a variable YOUR_EMP of nested table type EMP_NT it could be as simple as
open c1 for select * from TABLE( CAST(your_emp AS emp_nt));Cheers, APC -
HOw to improve insert/update/select for nested table.
Hi All,
I think this is my second thread for nested table.
i just want to know what are the different ways available to improve the insert/update/select operation on Nested table.
Thanks in advance.By not using a nested table for data storage in the first place...
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8135488196597
Perhaps Parallel Query/DML might give some relief. -
Hi All,
I have a update problem in nested table.
Below is my query:
CREATE OR REPLACE TYPE TRACER.SEARCH_DATA AS TABLE OF VARCHAR2(20);
UPDATE TRACER_SEARCH_SCHEDULE_LOT_NUM
SET NOT_FOUND_SOR_LOT_NUM = SEARCH_DATA(
SELECT
COLUMN_VALUE
FROM
TABLE (SELECT SORTING_LOT_NUMBER FROM TRACER_SEARCH_SCHEDULE_LOT_NUM WHERE JOB_ID = 8)
WHERE
TRIM(COLUMN_VALUE) NOT IN (SELECT DISTINCT (SORTING_LOT_NUMBER) FROM SEARCH_SCHEDULE_RESULT_LOT_NUM WHERE JOB_ID = 8)
) WHERE JOB_ID = 8;
ORA-00936: missing expression
or I try as following
DECLARE
sor_lot_num_not_found SEARCH_DATA :=
SEARCH_DATA
SELECT
FROM
TABLE (SELECT SORTING_LOT_NUMBER FROM TRACER_SEARCH_SCHEDULE_LOT_NUM WHERE JOB_ID = 8)
WHERE
TRIM(COLUMN_VALUE) NOT IN (SELECT DISTINCT (SORTING_LOT_NUMBER) FROM SEARCH_SCHEDULE_RESULT_LOT_NUM WHERE JOB_ID = 8)
BEGIN
UPDATE TRACER_SEARCH_SCHEDULE_LOT_NUM SET NOT_FOUND_SOR_LOT_NUM = sor_lot_num_not_found WHERE JOB_ID = 8;
END;
ORA-06550: line 5, column 9:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( ) - + case mod new not null others <an identifier>
table avg count current exists max min prior sql stddev sum
variance execute multiset the both leading trailing forall
merge year month DAY_ hour minute second timezone_hour
timezone_minute timezone_region timezone_abbr time timestamp
interval date
<a string literal with character set specificat
ORA-06550: line 11, column 5:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
; for and or group having intersect minus order start union
where connect
ORA-06550: line 14, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted d
I have try on the Select Statement, it work. So is it the way that I assign data from nested table and update method is wrong?
Edited by: skymonster84 on Mar 8, 2011 5:12 PMHi,
I think MULTISET operators might interest you.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/operators006.htm
Not tested :
UPDATE tracer_search_schedule_lot_num
SET not_found_sor_lot_num =
sorting_lot_number
MULTISET EXCEPT ALL
CAST(
MULTISET(
SELECT distinct sorting_lot_number
FROM search_schedule_result_lot_num
WHERE job_id = 8
AS search_data
WHERE job_id = 8
; -
Trigger how to get new and old value for nested table column?
Hi,
I have created a nested table based on the following details:
CREATE TYPE typ_item AS OBJECT --create object
(prodid NUMBER(5),
price NUMBER(7,2) )
CREATE TYPE typ_item_nst -- define nested table type
AS TABLE OF typ_item
CREATE TABLE pOrder ( -- create database table
ordid NUMBER(5),
supplier NUMBER(5),
requester NUMBER(4),
ordered DATE,
items typ_item_nst)
NESTED TABLE items STORE AS item_stor_tab
INSERT INTO pOrder
VALUES (800, 80, 8000, sysdate,
typ_item_nst (typ_item (88, 888)));
Now I would like to create a trigger on table pOrder for after insert or update or delete
and I would like to track the new and old value for the columns inside nested table.
Can anybody direct me how to do it?
I would like to know the sytax for it like:
declare
x number;
begin
x := :new.nestedtablecolumn;--how to get the new and old value from nested table columns
end;
Hope my question is clear.
Thanks,
LavanHi,
Try like this:
CREATE OR REPLACE TRIGGER PORDER_I
BEFORE INSERT
ON PORDER
REFERENCING OLD AS old NEW AS new
FOR EACH ROW
DECLARE
items_new typ_item_nst;
ordid_NEW NUMBER;
BEGIN
FOR i IN :new.items.FIRST .. :new.items.LAST LOOP -- For first to last element
DBMS_OUTPUT.PUT_LINE(':new.items(' || I || ').prodid: ' || :new.items(I).prodid );
DBMS_OUTPUT.PUT_LINE(':new.items(' || I || ').price: ' || :new.items(I).price );
END LOOP;
END;Regards,
Peter
Maybe you are looking for
-
Hi, I am unable to connect to the store on iTunes 10.6.7.1 on Win7 64 bit. From my iPhone I can connect to the store. Any thoughts?
-
Error creating Production Orders in UNCONSTR version
I am copying prodcution orders from version 000 to unconstr version through Report I am getting following error. Error creating Production Orders in UNCONSTR version and Message no. ZSXXPAPO140. when I am executed in background it is giving following
-
Error : Create Application server Connection.
Hi Friends, I am new to SOA Suite, I have installled SOA sute on my laptop on which i have Oracle -E-Business Suite R12. I have installed "soa_windows_x86_101310_disk1_1" and J-Dev "jdevstudio10134" My SOA suite is working fine (I think so) but when
-
how to fix this error?
-
Flex 4 FABridge dosen't work in subapplications
Hi, i try to map the class interface to javascript with <fx:Declarations> <fab:FABridge xmlns:fab="bridge.*" /> </fx:Declarations> The effect is that the FABridge is for the parent class and for the current class corrupted. Have some one an idea?