Inserting, deleting in nested tables
I am trying to delete and insert to a nested table.
delete from table (select address from employee where
employeeId = 1 );
or
insert into table (select address from employee where
employeeId = 1 )
values ('street', 'city');
I get the error message:
<b>ORA-22906: cannot perform DML on expression or on nested
table view column</b>
Does anybody know what I am doing wrong?
Thank you.
You can select from a nested table like this
Create table like this
CREATE TYPE Address AS OBJECT (
street VARCHAR2(20),
city VARCHAR2(10)
We may create a type that is a (nested) table of
objects of this type by:
CREATE TYPE AddressTable AS
TABLE OF Address;
CREATE TABLE Employees (
empno number(5),
addr AddressTable
NESTED TABLE addr STORE AS
address_tab;
SELECT ad.city
FROM THE(
SELECT addr
FROM Employees
WHERE empno = 123
) ad 'You can also add a where clause after this to select a particular address if there are multiple addresses
Insert
Insert into employees values (345,
addresstable ( Address('Street','City')));
Hope this helps
Similar Messages
-
Insert data into nested tables
Hi,
Can someone please advice how can I insert data into nested tables using APEX.
I have a table "employee" and a column addresses of type address_table_type object which has address1, address2, address3 columns. I want to create form in APEX that will collect address1, address2, address3. I wonder how to do this? should the item be based in database item? if yes then how can I point to the column of address_table_type
Thanks
--AaliCan you post your tabB type, sample data, and your exact insert statement?
Is it overwriting or not commiting the inserts?
Have you traced your session to see what is happening? -
Please help with multiple insert query into nested table!!!!
I am having a problem with inserting multiple references to objects into a nested table using the following query:
INSERT INTO TABLE(SELECT Taken_by FROM courses WHERE course_number= 001)
(SELECT REF(p) FROM persons p
WHERE p.enroled_in = 'Computing for Business'
The database says that p.enroled_in is an invalid identifier. I know why this is. This is because the field enroled_in is part of a subtype of person called student_type and the query above is not accounting for this properly. I would like to know the correct syntax to use so I can insert into the nested table wherever a student is enroled into the 'computing for business' course. My full schema is below:
CREATE TYPE person_type;
CREATE TYPE student_type;
CREATE TYPE staff_type;
CREATE TYPE course_type;
CREATE TYPE module_type;
CREATE TYPE address_type AS OBJECT
Street VARCHAR2 (30),
Town VARCHAR2 (30),
County VARCHAR2 (30),
Postcode VARCHAR2 (9)
CREATE TYPE person_type AS OBJECT
Name VARCHAR2 (50),
Address address_type,
DOB DATE
) NOT FINAL;
CREATE TYPE staff_type UNDER person_type
Staff_number NUMBER (2,0)
) FINAL;
CREATE TYPE student_type UNDER person_type (
Student_number NUMBER (2,0),
Enroled_in VARCHAR2(50),
MEMBER FUNCTION getAge RETURN NUMBER
)NOT FINAL;
CREATE OR REPLACE TYPE BODY student_type AS
MEMBER FUNCTION getAge RETURN NUMBER AS
BEGIN
RETURN Trunc(Months_Between(Sysdate, DOB)/12);
END getAge;
END;
CREATE TYPE module_type AS OBJECT
Module_number VARCHAR2(6),
Module_name VARCHAR2(50),
Credit NUMBER(2,0),
Taught_in VARCHAR2(50)
CREATE TYPE students_tab AS TABLE OF REF person_type;
CREATE TYPE modules_tab AS TABLE OF REF module_type;
CREATE TYPE course_type AS OBJECT
Course_number NUMBER (2,0),
Course_name VARCHAR2(50),
Dept_name VARCHAR2(50),
Taken_by Students_tab,
Contains Modules_tab
CREATE TABLE modules OF module_type(
constraint pk_modules primary key (Module_number)
CREATE TABLE courses OF course_type(
constraint pk_courses primary key (Course_number)
NESTED TABLE Taken_by STORE AS students_nt,
NESTED TABLE Contains STORE AS modules_nt;By the way I am using oracle 9i and trying to insert into the nested table data from a subtype (i.e student is a subtype of person)
-
Inserting Data into nested table
I am exploring the differences between OBJECT & RECORD.
As i am still in process of learning, I found that both are structures which basically groups elements of different datatypes or columns of different datatypes, one is used in SQL and other is used in PL/SQL, please correct me if I am wrong in my understanding.
Below i am trying to insert data into an table of type object but i am unsuccessful can you please help.
CREATE OR REPLACE type sam as OBJECT
v1 NUMBER,
v2 VARCHAR2(20 CHAR)
---Nested Table---
create or replace type t_sam as table of sam;
--Inserting data----
insert into table(t_sam) values(sam(10,'Dsouza'));
Error Message:
Error starting at line 22 in command:
insert into table(t_sam) values(sam(10,'Dsouza'))
Error at Command Line:22 Column:13
Error report:
SQL Error: ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:Ariean wrote:
So only purpose of equivalent SQL types concept of nested tables is to use them as one of the data types while defining an actual table?
Sort of - you can definitely use them for more than just "defining an actual table". (I'm fairly certain you could pass a nested table into a procedure, for example - try it, though - I'm not 100% sure on that - it just "makes sense". If you can define a type, you can use it, pass it around, whatever.).
Ariean wrote:
And that nested table could be a record in SQL or an Object in PLSQL or just simple datatype(number,varchar etc)?
Nested tables are just like any other custom data type. You can create a nested table of other data types. You can create a custom data type of nested tables.
It could get stupidly .. er, stupid O_0
CREATE TYPE o_myobj1 AS object ( id1 number, cdate1 date );
CREATE TYPE t_mytype1 AS table of o_myobj1;
CREATE TYPE o_myobj2 AS object ( id2 number, dumb t_mytype1 );
CREATE TYPE t_dumber AS table of o_myobj2;
O_0
Ok, my brain's starting to hurt - I hope you get the idea
Ariean wrote:
Secondly is my understanding correct about OBJECT & RECORD?
I can't think of any benefit of describing it another way. -
Oracle Auditing for Insert/delete in a Table
Dear Oracle Guru's
I have a Master table for which records are added manually using the Insert command and not by any front end tools.
I have no Auditing for this table , like when an insert/delete is made in to this table.
Does oracle provides any other Tables/views like v$session to find out when such events happens.
Kindly guide me
With Warm Regards
ssrProbably not.
If your database is in ARCHIVELOG mode and you have the archived logs from the point in time that the DML happened, you could potentially use LogMiner to read the redo logs and get information about when the DML happened and who was responsible. That tends, however, to be a relatively painful manual process that is frequently complicated by the fact that most shops get rid of archived logs as soon as they are no longer necessary for database recovery which is frequently a matter of days or weeks.
Justin -
How to Insert records in Nested Table
Hello Friends,
I have doubt in below Nested table.
I have inserted the value in emp table
EMP TABLE
EMPNO ENAME PROJECTS
1 A DATASET
2 B DATASET
but not in project_type object. Now I want to insert the record in project_type for name and role field. Please resolve my problem.
SQL> create type project_type as object
2 (
3 name varchar2(50),
4 role varchar2(20)
5 )
6 /
Type created.
SQL>
SQL> create type ProjectTable as Table of Project_type
2 /
Type created.
SQL>
SQL> create table emp
2 ( empno number(5),
3 ename varchar2(30),
4 projects projecttable
5 )
6 nested table projects store as projects_nt
7 /
Table created.
Thanks...Ok if you have inserted a row in the emp table and now you want to update the projects column which is null then you would do something like:
update emp
set projects = projecttable(project_type('..', '..'))
where empno = ...However say that the projects column is not null and you want to add a new record into the nested table then you would do:
insert into (select projects from emp where empno = ...)
values ('...', '...')And finally imagine you have a record in the nested table that you want to update then you would do the following:
update (select projects from emp where empno = ...)
set role = '...'
where name = '...' -
HI,
I have a source table with millions of records .I need to insert some of the data (depending on a condition) to a repository table.
Once they are inserted they can be deleted from the source table.
The deletion is taking a lot of time .
I need to reduce the time to delete the records.
ex:- 1 million records in 8 seconds.
Had already used bulk collect and cursors but cannot succeed.
Please suggest how to increase the performance.
Thanks & RegardsAPPROACH 1:-
CREATE OR REPLACE PROCEDURE SP_BC
AS
DETAILS_REC SOURCETBL%ROWTYPE;
COUNTER NUMBER:=1;
RCOUNT NUMBER:= 1;
START_TIME PLS_INTEGER;
END_TIME PLS_INTEGER;
CURSOR C1 IS
SELECT * FROM SOURCETBL WHERE DOJ<SYDATE;
BEGIN
START_TIME := DBMS_UTILITY.GET_TIME;
DBMS_OUTPUT.PUT_LINE(START_TIME/100);
OPEN C1;
LOOP
FETCH C1 INTO DETAILS_ROW;
EXIT WHEN C1%NOTFOUND;
BEGIN
EXIT WHEN COUNTER >10000;
INSERT INTO DESTINATIONTBL VALUES DETAILS_REC;
IF SQL%FOUND THEN
DELETE FROM SOURCETABLE WHERE ID= DETAILS_REC.ID;
COUNTER:=COUNTER+1;
END IF;
COMMIT;
END;
COUNTER:=1;
END LOOP;
COMMIT;
END;
APPROACH 2:-
CREATE OR REPLACE PROCEDURE SP_BC1
IS
TYPE T_DET IS TABLE OF SOURCETBL%ROWTYPE;
T_REC T_DET;
BEGIN
SELECT * BULK COLLECT INTO T_REC FROM SOURCETBL
WHERE NAME=@NAME;
FOR I IN T_REC .FIRST ..T_REC .LAST
LOOP
INSERT INTO DESTINATIONTBL VALUES T_REC (I);
IF SQL%FOUND THEN
DELETE FROM SOURCETBL WHERE ID =
WHERE ID = T_REC (I).ID;
END IF;
EXIT WHEN T_REC=0;
END LOOP;
COMMIT;
END;
APPROACH 3:-
CREATE OR REPLACE PROCEDURE SP_BC2
AS
TYPE REC_TYPE IS TABLE OF SOURCETBL%ROWTYPE ;
DETAILS_ROW REC_TYPE;
CURSOR C1 IS
SELECT * FROM
SOURCETBL WHERE END<SYSDATE;
BEGIN
OPEN C1;
LOOP
FETCH C1 BULK COLLECT INTO DETAILS_ROW LIMIT 999;
FORALL I IN 1..DETAILS_ROW.COUNT
/* A BATCH OF 999 RECORDS WILL BE CONSIDERED FOR DATA MOVEMENT*/
INSERT INTO DESTINATIONTBL VALUES DETAILS_ROW(I);
-- IF SQL%FOUND THEN
-- DELETE from SOURCETBL WHERE ID IN DETAILS_ROW(I).ID;
-- END IF;
EXIT WHEN C1%NOTFOUND;
COMMIT;
END LOOP;
COMMIT;
3rd approach seems better but i have an issue with referring the fileds of a record type. -
Hi
I have created one nested table with the follwing columns. I have to insert records into the nested table. And also I have to update the nested table. Please find below my table and getting error message.
Please advose...!!
SQL> create type details as object(
2 basic number(7,2),
3 da number(6,2),
4 hra number(6,2),
5 pf number(6,2),
6 it number(6,2),
7 gross number(7,2),
8 ded number(6,2),
9 net number(8,2));
10 /
Type created.
SQL> create type details_t is table of details;
2 /
Type created.
SQL> ed
Wrote file afiedt.buf
1 create table emp_tab(empno number(4),name varchar2(10),details_tab details_t)
2* nested table details_tab store as empl_details
SQL> /
Table created.
SQL> ed
Wrote file afiedt.buf
1* insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null)))
SQL> /
Enter value for empno: 1
Enter value for name: asdf
Enter value for da: 120
Enter value for hra: 130
Enter value for pf: 120
Enter value for it: 120
old 1: insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null
new 1: insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null)))
insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null)))
ERROR at line 1:
ORA-02315: incorrect number of arguments for default constructorCan I use '&' while inserting records into nested table? yes / no ?
I have to update gross, ded, net columns also..!!
Please help me..!!
Regards
Azep@dev>
zep@dev> create type details as object
2 (
3 basic number(7, 2),
4 da number(6, 2),
5 hra number(6, 2),
6 pf number(6, 2),
7 it number(6, 2),
8 gross number(7, 2),
9 ded number(6, 2),
10 net number(8, 2)
11 )
12 /
Type created
zep@dev> create type details_t is table of details
2 /
Type created
zep@dev> create table emp_tab(empno number(4),name varchar2(10),details_tab details_t)
2 nested table details_tab store as empl_details
3 /
Table created
zep@dev> insert into emp_tab
2 values
3 (1,
4 'asdf',
5 details_t(details(120, 130, 120, 120, 1, 2, 3, 4)));
1 row inserted
zep@dev>
zep@dev> select *
2 from table (select details_tab
3 from emp_Tab t
4 where t.empno = 1);
BASIC DA HRA PF IT GROSS DED NET
120,00 130,00 120,00 120,00 1,00 2,00 3,00 4,00
zep@dev> -- second object in the same empno = 1
zep@dev> insert into table
2 (select details_tab
3 from emp_Tab t
4 where t.empno = 1)
5 values
6 (details(200, 230, 220, 220, 10, 11, 12, 13));
1 row inserted
zep@dev>
zep@dev> select *
2 from table (select details_tab
3 from emp_Tab t
4 where t.empno = 1);
BASIC DA HRA PF IT GROSS DED NET
120,00 130,00 120,00 120,00 1,00 2,00 3,00 4,00
200,00 230,00 220,00 220,00 10,00 11,00 12,00 13,00
zep@dev>
zep@dev> update table (select details_tab
2 from emp_Tab t
3 where t.empno = 1)
4 set gross = nvl(basic,0) + nvl(da,0) + nvl(hra,0),
5 ded = nvl(pf,0) + nvl(it,0),
6 net = nvl(gross,0) - nvl(ded,0)
7 where basic = 120;
1 row updated
zep@dev>
zep@dev> select *
2 from table (select details_tab
3 from emp_Tab t
4 where t.empno = 1);
BASIC DA HRA PF IT GROSS DED NET
120,00 130,00 120,00 120,00 1,00 370,00 121,00 -1,00
200,00 230,00 220,00 220,00 10,00 11,00 12,00 13,00
zep@dev> -
Can't insert into nested table
I can't inserted into a nested table and my SQL is listed below.
SQL> CREATE TYPE naming_t AS OBJECT (name VARCHAR2(30), alias VARCHAR2(30)) NOT FINAL;
2 /
Type created.
SQL> CREATE TYPE terminal_t;
2 /
Type created.
SQL> CREATE TYPE terminal_t_nt AS TABLE OF REF terminal_t;
2 /
Type created.
SQL> CREATE TYPE connectivitynode_t UNDER naming_t (terminals terminal_t_nt) NOT FINAL;
2 /
Type created.
SQL> CREATE TYPE connectivitynode_t_nt AS TABLE OF REF connectivitynode_t;
2 /
Type created.
SQL> CREATE TYPE terminal_t UNDER naming_t (connectivitynodes connectivitynode_t_nt) NOT FINAL;
2 /
Type created.
SQL>
SQL> CREATE TABLE naming_tb (name VARCHAR2(30), alias VARCHAR2(30));
Table created.
SQL> CREATE TABLE connectivitynode_tb (name VARCHAR2(30), terminals terminal_t_nt) NESTED TABLE terminals STORE AS terminals_tb;
Table created.
SQL> CREATE TABLE terminal_tb (name VARCHAR2(30), connectivitynodes connectivitynode_t_nt) NESTED TABLE connectivitynodes STORE AS connectivitynodes_tb;
Table created.
SQL>
SQL> INSERT INTO naming_tb (name) VALUES ('AP1.132.B/C.T1');
1 row created.
SQL> INSERT INTO terminal_tb (name) VALUES ('AP1.132.B/C.T1');
1 row created.
SQL> INSERT INTO naming_tb (name) VALUES ('AP1.132.B/C.T2');
1 row created.
SQL> INSERT INTO terminal_tb (name) VALUES ('AP1.132.B/C.T2');
1 row created.
SQL>
SQL> INSERT INTO naming_tb (name) VALUES ('AP1.132.B/C.N1');
1 row created.
SQL> INSERT INTO connectivitynode_tb (name) VALUES ('AP1.132.B/C.N1');
1 row created.
SQL> INSERT INTO TABLE (SELECT terminals FROM connectivitynode_tb WHERE name='AP1.132.B/C.N1') SELECT REF(p) FROM terminal WHERE p.name='AP1.132.B/C.T1' OR p.name='AP1.132.B/C.T2';
INSERT INTO TABLE (SELECT terminals FROM connectivitynode_tb WHERE name='AP1.132.B/C.N1') SELECT REF(p) FROM terminal WHERE p.name='AP1.132.B/C.T1' OR p.name='AP1.132.B/C.T2'
ERROR at line 1:
ORA-00942: table or view does not existI think you dont have the table terminal referred in following select statement
SELECT REF(p) FROM terminal WHERE p.name='AP1.132.B/C.T1' OR p.name='AP1.132.B/C.T2';
Chandar -
Select from nested table in a nested table security problem
please help
running Oracle 9.2.0.3.0 on RH AS 2.1
I can select the inner most nested table as the creator, but can't use the same select statement as USER2.
ORA-00942: table or view does not exist
-- begin make of objects and tables
create or replace type mydata_t as object ( x float, y float);
create or replace type mydata_tab_t as table of mydata_t;
create or replace type mid_t as object (
graphname varchar2(12),
datapoints mydata_tab_t );
create or replace type mid_tab_t as table of mid_t;
create or replace type top_t as object (
someinfo int,
more_mid mid_tab_t );
create table xyz (
xyzPK int,
mainstuff top_t )
nested table mainstuff.more_mid store as mid_nt_tab
(nested table datapoints store as mydata_nt_tab)
-- grants
grant all on mydata_t to user2;
grant all on mydata_tab_t to user2;
grant all on mid_t to user2;
grant all on mid_tab_t to user2;
grant all on top_t to user2;
grant all on xyz to user2;
-- insert
insert into xyz values (1, top_t(22,mid_tab_t(mid_t('line1',mydata_tab_t(
mydata_t(0,0),
mydata_t(15,15),
mydata_t(30,30))))));
commit;
-- select fails as user2
select * from table(select Y.datapoints as DP_TAB
from table(select X.mainstuff.more_mid as MORE_TAB
from scott.xyz X
where X.xyzPK=1) Y
where Y.graphname='line1') Z;
-- select works as user2, but i need individual lines
select Y.datapoints as DP_TAB
from table(select X.mainstuff.more_mid as MORE_TAB
from scott.xyz X
where X.xyzPK=1) Y
where Y.graphname='line1';Thank you for your reply.
I have tried
select value(t) from table t;
but it is still not working. I got almost the same answer as before.
Anyway thank you very much again.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by MARCELO OCHOA ([email protected]):
Originally posted by meimei wu ([email protected]):
[b]I created a nested object-relational table using REF type in oracle8i. when I tried to select * from the table, I got lots of number as the ref type values, but actually, the value in ref type should be of type varchar2 and number. The number I got looked like following code:
JARTICLE_REF_TYPE(000022020876108427C2FE0D00E0340800208FD71F76103B99B12009C0E0340800208FD71F,
Does anyone know how I can get the actual value that I inserted into the nested table?
your help is appreciated.<HR></BLOCKQUOTE>
Try this:
select value(t) from table t;
Best regards, Marcelo.
null -
How to assign Values to nested table and pass as parameter to procedure?
How to assign Values to nested table and pass as parameter to procedure?
Below is the Object and its type
create or replace type test_object1 as object
val1 varchar2(50),
val2 varchar2(50),
val3 varchar2(50)
create or replace type test_type1 is table of test_object1;
create or replace type test_object2 as object
val1 varchar2(50),
val2 varchar2(50),
val3 varchar2(50)
create or replace type test_type2 is table of test_object2;
GRANT ALL ON test_object1 TO PUBLIC;
GRANT ALL ON test_type1 TO PUBLIC;
GRANT ALL ON test_object2 TO PUBLIC;
GRANT ALL ON test_type2 TO PUBLIC;
here is the table made of object type:
create table test_object_tpe
sl_num NUMBER,
description VARCHAR2(100),
main_val1 test_type1,
main_val2 test_type2
NESTED TABLE main_val1 STORE AS tot1
NESTED TABLE main_val2 STORE AS tot2;
here is the procedure which inserts values into nested table:
PROCEDURE INSERT_TEST_DATA(sl_num IN NUMBER,
description IN VARCHAR2,
p_main_val1 IN test_type1,
p_main_val2 IN test_type2
IS
BEGIN
FOR rec in p_main_val1.first..p_main_val1.last
LOOP
INSERT INTO xxdl.test_object_tpe
sl_num,
description,
main_val1,
main_val2
VALUES
sl_num
,description
,test_type1 (test_object1(
p_main_val1(rec).val1,
p_main_val1(rec).val2,
p_main_val1(rec).val3
,test_type2 (test_object2( p_main_val2(rec).val1,
p_main_val2(rec).val2,
p_main_val2(rec).val3
END LOOP;
commit;
END INSERT_TEST_DATA;
here is the anonymoys block which assigns values to the object type and pass values into the procedure:
set serveroutput on;
declare
p_sl_num NUMBER := 1001;
p_description VARCHAR2(50) := 'Testing Val1';
inval1 test_type1 := test_type1();
inval2 test_type2 := test_type2();
begin
inval1(1).val1 := 'testx1';
inval1(1).val2 := 'testx2';
inval1(1).val3 := 'testx3';
inval2(1).val1 := 'testy1';
inval2(1).val2 := 'testy2';
inval2(1).val3 := 'testy3';
CSI_PKG.INSERT_TEST_DATA(sl_num => p_sl_num,
description => p_description,
p_main_val1 => inval1,
p_main_val2 => inval2
end;
Can anybody correct me.
Thanks,
LavanThanks for posting the DDL and sample code but whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
>
How to assign Values to nested table and pass as parameter to procedure?
>
Well you are doing almost everything wrong that could be done wrong.
Here is code that works to insert data into your table (the procedure isn't even needed).
declare
p_sl_num NUMBER := 1001;
p_description VARCHAR2(50) := 'Testing Val1';
inval1 test_type1 := test_type1();
inval2 test_type2 := test_type2();
begin
inval1.extend();
inval1(1) := test_object1('testx1', 'testx2', 'testx3');
inval2.extend();
inval2(1) := test_object2('testy1', 'testy2', 'testy3');
INSERT INTO test_object_tpe
sl_num,
description,
main_val1,
main_val2
VALUES
(p_sl_num, p_description, inval1, inval2);
commit;
end;
/See Example 5-15 Referencing a Nested Table Element in Chap 5 Using PL/SQL Collections and Records in the PL/SQL doc
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/collections.htm#CJABEBEA
1. You don't even need the procedure since all it does is a simple INSERT into the table which you can do directly (see my code above)
inval1(1).val1 := 'testx1';There is no element one (1) of 'inval1' since you haven't created any elements yet. You need to EXTEND the collection to add an element
inval1.extend();And then there is an empty element but 'inval1' is a container for objects of type 'test_object1' not for scalars like 'val1', 'val2', and 'val3'.
So you can't do
inval1(1).val1 := 'testx1';You have to create an instance of 'test_object1'
inval1(1) := test_object1('testx1', 'testx2', 'testx3');And so on for the other collection
You don't need the procedure (as my sample code shows) but once you populate the variables properly it will work. -
Inserting into a doubly nested table through an object view
Can anyone give me an example of an INSTEAD OF trigger that will mediate an INSERT into a doubly nested table of an Object View? Is there syntax that will allow it?
Here's some code to demonstrate. Note that relational tables, not an object table, are used to store object instances:
create or replace type TInnerNestedTable
is table of varchar2(20)
create or replace type TOuterNestedTable
is table of TInnerNestedTable
create or replace type TMyObject
is object
id varchar2(20)
, tab TOuterNestedTable
create
table T_MY_OBJECT
id varchar2(20) not null
, primary key (id)
create
table T_MY_OBJECT_TAB_OUTER
id varchar2(20) not null
, outerIndex integer not null
, primary key (id, outerIndex)
, foreign key (id) references T_MY_OBJECT on delete cascade
create
table T_MY_OBJECT_TAB_INNER
id varchar2(20) not null
, outerIndex integer not null
, innerIndex integer not null
, innerValue varchar2(20)
, primary key (id, outerIndex, innerIndex)
, foreign key (id, outerIndex) references T_MY_OBJECT_TAB_OUTER on delete cascade
create or replace view V_MY_OBJECT
of TMyObject
with object identifier (id)
as
select t.id
, cast(multiset(
select cast(multiset(
select i.innerValue
from T_MY_OBJECT_TAB_INNER i
where i.id = o.id
and i.outerIndex = o.outerIndex
) as TInnerNestedTable)
from T_MY_OBJECT_TAB_OUTER o
where o.id = t.id
) as TOuterNestedTable)
from T_MY_OBJECT t
create or replace trigger TR_II_V_MY_OBJECT
instead of insert on V_MY_OBJECT
for each row
begin
insert
into T_MY_OBJECT
id
values (
:new.id
insert
into T_MY_OBJECT_TAB_OUTER
id
, outerIndex
select :new.id
, rownum
from table(:new.tab) o;
insert
into T_MY_OBJECT_TAB_INNER
id
, outerIndex
, innerIndex
, innerValue
select :new.id
, o.outerIndex
, rownum
, value(i)
from (
select :new.id
, rownum outerIndex
, value(o) innerTab
from table(:new.tab) o
) o
, table(o.innerTab) i;
end;
insert
into V_MY_OBJECT
values (
new TMyObject(
'A'
, TOuterNestedTable(
TInnerNestedTable('A','B','C')
, TInnerNestedTable('AA')
, TInnerNestedTable('AB')
insert
into V_MY_OBJECT
values (
new TMyObject(
'B'
, TOuterNestedTable(
TInnerNestedTable('X','Y','Z')
, TInnerNestedTable('Hello', 'World!')
/Selecting from the view shows the results:
select value(o)
from V_MY_OBJECT o
VALUE(O)(ID, TAB)
TMYOBJECT('A', TOUTERNESTEDTABLE(TINNERNESTEDTABLE('A', 'B', 'C'), TINNERNESTEDTABLE('AA'), TINNERNESTEDTABLE('AB')))
TMYOBJECT('B', TOUTERNESTEDTABLE(TINNERNESTEDTABLE('X', 'Y', 'Z'), TINNERNESTEDTABLE('Hello', 'World!')))
2 rows selected.Hope that helps...
Gerard -
Insert /delete data from SAP Z table to Oracle table and opposite
Hi,
Can u help me write this FM from the SAP side?
So, I have two tables ZTABLE in SAP and Oracle table ORAC.
Let's put three columns in each of them, for example
TEL1
TEL2
ADRESS
NAME
where TEL field is primary from ZTABLE to ORAC...
(in FM there shoud be abap code for writing data in ZTABLE after we press some pushbutton made in sap screen painter..)
for example, when we write new record in ZTABLE
00
112233
Street 4
Name1
this data shoud be inserted in Oracle table ORAC.
when we write new record in Oracle table for example
01
445566
New Street
Name2
this data shoud be inserted in ZTABLE.
Field TEL1 can be only of two values 01 or 02, other combination is not valid...
I must have all data from Oracle table ORAC in ZTABLE and opposite.
It should be the same scenario for DELETE...
And this communication should be online between sap and table in oracle database...
Can u help me from sap side? and give idea how to configure on oracle side??
Thanks a lot,
NihadI dont know if we can directly connect to a oracle database ( wait for the answers from others on this )
but in XI we have the JDBC adaptor to insert and retrieve data.
so for the outbound from SAP the flow can be something like this (with XI in landscape):
1) You have a screen to maintain a new entry / delete an entry
2) On save , this record gets saved or deleted from the Ztable in SAP
3)) In the same screen you can call a proxy class-method (generated using SPROXY transaction ) to send the record to XI.
4) XI to format it and insert into the oracle table
Mathews -
Using Insert and Delete icons in table control wizard.
Can anyone tell me how to perform a new row insertion or deletion in a table created using the table control wizard.
I see there is a form fcode_insert_row and fcode_delete_row, but dont know how to call them and what parameters to pass and all.
Since iam new to SAP-ABAP, some code samples will be a great help.
Thanks to all in advance.Hi Lavanya ,
You have to add the icons personally in the table control.. . Put fcode for addition button as INSE and delete as DELE ..coding will be already thr in the wizard no need to anything just add icons in the table control by selecting from f4 help on icons option of screen.
Thanks,
Vishnu . -
How to delete the NULL entries in nest table
Hi,
After I used a loop and open/fetch cursor populated the object table
I found there are random NULL entries in my object table (nest table)
The data look like this
NULL NULL NULL
NULL NULL NULL
123 03-MAY-04 ACTIVE
NULL NULL NULL
NULL NULL NULL
234 21-MAY-04 ACTIVE
NULL NULL NULL
345 11-MAY-04 ACTIVE
NULL NULL NULL
How can I get rid of those NULL entries in my nest table? So it can become
123 03-MAY-04 ACTIVE
234 21-MAY-04 ACTIVE
345 11-MAY-04 ACTIVE
Additional info:
create type myType as object
(id NUMBER (10,0),
eff_date date,
status VARCHAR2(17)
create type myNestTab as table of myType;
I have tried Delete procedure in following two ways.
Version 1:
FOR i IN l_my_nest_tab.FIRST..l_my_nest_tab.LAST
LOOP
IF l_my_nest_tab(i).id IS NULL THEN
l_curr_event_tb.DELETE(i);
END IF;
END LOOP;
Version 2:
FOR i IN l_my_nest_tab.FIRST..l_my_nest_tab.LAST
LOOP
IF l_my_nest_tab(i) IS NULL THEN
l_curr_event_tb.DELETE(i);
END IF;
END LOOP;
Both of them give me the error no data found. And only left me the first NOT NULL entry in the table.
123 03-MAY-04 ACTIVE
Thanks in avdance.Hi Vishnu,
u can write a report program for this and in that use the event :
AT NEW <field-name> ( use primary key)
your statements
ENDAT
for eg.
loop at itab ( herfe itab must be of type of table for which u want to track new entries)
at new matnr
write:/ new record
endat
endloop.
schedule this report in background to run in every 5 or 10 mins as per your requirement and hence changes can be tracked.
regards
Vinod
Maybe you are looking for
-
ITunes won't connect to iPod due to an unknown error (0xE800000A)
Hello all, I have had my iPod touch for more than a year and I really love it, having had no problems whatsoever. However, a few days ago, I realized that it wouldn't mount in iPhoto or QuickCapture. I did several tests and decided to do a restore. B
-
How to fetch data based on this selection screen
Hi Friends: I've a selection screen which contains these 3 fields: company code (t001-bukrs) material division (mara-spart) posting date (bkpf-budat) based on the above fields, I've to fetch the following: ekpo-bukrs mara-spart mseg-werks mseg-lg
-
Keynote jumps to the iPad home screen when importing ppt. file from my email. What.s wrong?
-
How to make the session to wait until other session get closed successfully
Hi , In my program , I am calling sql loader and after that I am opening a session and inside that I am calling stored procedure which validates the data. above calling of sql loader and stored procedure is done inside the shell script i.e .prog file
-
Hi All, I am using SOA suite 11g. I have confusion with Oracle Enterprise Service Bus and Oracle Service Bus 1> Is ESB and OSB same ? If not, then from where do i download Oracle ESB ? and what would it do different from OSB (*I already downloaded OS