Updating child table with parent table
Can anyone help me with this update statement?
I have a table BETA with children of the family list and I have table GAMA with children and family list. The relation between family and children is 1 to many. Now we have decided to update table BETA which has children list with table GAMA’s family list. So I did as below.
UPDATE beta B
SET (b.childe_code
,b.childe_name) =(SELECT DISTINCT g.family_code
,g.family_name
FROM gama g
WHERE b.childe_code IN (SELECT g.childe_code
FROM gama g)
AND g.period = (SELECT MAX(period) FROM gama g))
WHERE EXISTS (SELECT 1
FROM gama g
WHERE b.childe_code IN (SELECT g.childe_code
FROM gama g)
AND g.period = (SELECT MAX(period) FROM gama g));It is giving this error: ORA-01427: single-row subquery returns more than one row
Could someone please help me with this?
Thanks for the help.
Hello tubby,
Here is the answers for all your questions.
How about you post your Oracle version
select * from v$version
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - ProductionThe DDL for BETA and GAMA tables (create table statements).
CREATE TABLE BETA
CHILDE_CODE NUMBER,
CHILDE_NAME VARCHAR2(50 BYTE),
PERIOD INTEGER
CREATE TABLE GAMA
FAMILY_CODE NUMBER,
FAMILY_NAME VARCHAR2(50 BYTE),
CHILDE_CODE NUMBER,
CHILDE_NAME VARCHAR2(50 BYTE),
PERIOD INTEGER
)Sample data for both tables (in the form of INSERT statements) which represent a small test case you've constructed.
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(10, 'google', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(11, 'amazon', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(12, 'ebay', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(13, 'yahoo', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(20, 'word', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(21, 'excel', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(22, 'access', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(23, 'cognos', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(30, 'cell phone', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(31, 'laptop', 201010);
Insert into BETA
(CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(32, 'pager', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(1, 'website', 10, 'google', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(1, 'website', 11, 'amazon', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(1, 'website', 12, 'ebay', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(1, 'website', 13, 'yahoo', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(2, 'software', 20, 'word', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(2, 'software', 21, 'excel', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(2, 'software', 22, 'access', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(2, 'software', 23, 'cognos', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(3, 'wireless', 30, 'cell phone', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(3, 'wireless', 31, 'laptop', 201010);
Insert into GAMA
(FAMILY_CODE, FAMILY_NAME, CHILDE_CODE, CHILDE_NAME, PERIOD)
Values
(3, 'wireless', 32, 'pager', 201010);The desired output you want based on the input data, with an explanation as to how the data needs to be transformed.
I want to replace data of childe_code and childe_name with family_code and family_name in the beta table. The error message you are currently getting is quite descriptive, you are getting back more than a single row for a given row you are trying to update. If you can deterministically decide which rows to take and outline that in your example, we can help you.
Similar Messages
-
Partition exchange error on table with nested table
On Oracle 11.2.0.1, I have a partitioned table with some partitions that need to be 'archived' (in terms of moving partitions to an 'archive' table).
I have a source table like:
CREATE TABLE IS_PODACI245
ID_OBJEKTA_IDENTIFIKACIJA NUMBER(10),
ID_OBJEKTA NUMBER(20),
DATUM TIMESTAMP(6) NOT NULL,
TZ NUMBER(3),
DATA1 NUMBER(10),
DATA2 NUMBER(6),
DATA3 NUMBER(10),
DATA4 NUMBER,
DATA5 T_NTCIP_CLIMATE_TABLE
NESTED TABLE DATA5 STORE AS IS_PODACI245_STORE_TABLE
TABLESPACE DATA
PARTITION BY RANGE (DATUM)
PARTITION P_201107 VALUES LESS THAN (TIMESTAMP' 2011-08-01 00:00:00')
LOGGING
NOCOMPRESS
TABLESPACE DATA,
PARTITION P_MAXVALUE VALUES LESS THAN (MAXVALUE)
LOGGING
NOCOMPRESS
TABLESPACE DATA
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE INDEX IDX_IS_PODACI245_KOMPLEKS ON IS_PODACI245
(ID_OBJEKTA_IDENTIFIKACIJA, ID_OBJEKTA, DATUM)
TABLESPACE DATA
LOCAL (
PARTITION P_201107
LOGGING
NOCOMPRESS
TABLESPACE DATA,
PARTITION P_MAXVALUE
LOGGING
NOCOMPRESS
TABLESPACE DATA
NOPARALLEL;
CREATE OR REPLACE TYPE t_ntcip_climate_table as table of t_ntcip_climate_fmt;
CREATE OR REPLACE TYPE t_ntcip_climate_FMT as object
( dev_index number(6)
, dev_description varchar2(512)
, dev_type number(10)
, dev_status number(10)
, dev_mfr_status varchar2(512)
, dev_active number(3)
, dev_test_activation number(10)
/I would like to make exchange partition using stage table, and everything is going fine on all tables, but only on a few of them (listed source is one of them, and they're only tables with nested tables wihin), where I get an error.. but sometimes ;)
on a statement like:
ALTER TABLE IS_PODACI245_ARH EXCHANGE PARTITION P_201106 WITH TABLE IS_PODACI245_STAGE EXCLUDING INDEXES WITHOUT VALIDATION;I got an error:
ORA-00001: unique constraint (TXV.SYS_C0032911) violated
it's an unique index between parent and nested table.
what could cause that problem?Dear,
I suppose that the unique constraint
ORA-00001: unique constraint (TXV.SYS_C0032911) violatedis the one you 've created on the nested table IS_PODACI245_STORE_TABLE
If so, why not disable that constraint and try again.
I have never exchanged such a kind of partitioned table having a nested table in it. But, I could imagine that the cloned non partitioned table IS_PODACI245_STAGE should at least be the exact image of the partitioned table IS_PODACI245_ARH (of course without the partition part) but with the nested table part and including all indexes
In addition, if you have a parent/child relationship between your partitioned tables, then there is a chronological order of exchange starting by the child and then finishing by the parent
see the following link for more information about this order of exchange (and comment 2 for an example also)
http://jonathanlewis.wordpress.com/2006/12/10/drop-parent-partition/#more-65
Hope this helps
Mohamed Houri -
Mix object tables with relational tables?
Hallo,
is it possible to mix object tables with relational tables in one database?
I didn't succeed in assigning a foreign key from a relational table to an object table.
Is this only working with column objects in relational tables?Hi
is it possible to mix object tables with relational tables in one database?
Every database contains both types of tables. So, it is basically not a problem.
I didn't succeed in assigning a foreign key from a relational table to an object table.
Is this only working with column objects in relational tables?It would be interesting to know how you tried... e.g. what error you get... Here an example (executed on 11.1).
SQL> create or replace type tt as object ( n number );
2 /
SQL> create table ot of tt (constraint ot_pk primary key (n));
SQL> create table rt (n number, constraint rt_ot_fk foreign key (n) references ot (n));
SQL> insert into ot values (tt(1));
SQL> insert into rt values (1);
SQL> insert into rt values (2);
insert into rt values (2)
ERROR at line 1:
ORA-02291: integrity constraint (OPS$CHA.RT_OT_FK) violated - parent key not foundHTH
Chris -
Import tables with nested table : ORA-00600
In Oracle 9.2
Create object, type as table, and table with nested table (store as syms_ntab) are successfully.
Also its export.
In process of import on another server (also 9.2, 'fromuser=one touser=two') shows errors:
. . importing table "SYMS_NTAB"
IMP-00058: ORACLE error 600 encountered
ORA-00600: internal error code, arguments: [kokeeafi1], [2], [2], [], [], [], [], []
IMP-00075: Warning: The nested table may contain partial rows or duplicate rows
But for all that table is created and error occur on phase inserting strings.
What is this?
In Oracle 8.0.5 i perform similar operation without error.From Oracle error messages and codes manual:
ORA-00600 internal error code, arguments: [string], [string], [string], [string], [string], [string], [string], [string]
Cause: This is the generic internal error number for Oracle program exceptions. It indicates that a process has encountered a low-level, unexpected condition. Causes of this message include:
* timeouts
* file corruption
* failed data checks in memory
* hardware, memory, or I/O errors
* incorrectly restored files
The first argument is the internal message number. Other arguments are various numbers, names, and character strings. The numbers may change meanings between different versions of Oracle.
Action: Report this error to Oracle Support Services after gathering the following information:
* events that led up to the error
* the operations that were attempted that led to the error
* the conditions of the operating system and databases at the time of the error
* any unusual circumstances that occurred before receiving the ORA-00600 message
* contents of any trace files generated by the error
* the relevant portions of the Alter files
Note: The cause of this message may manifest itself as different errors at different times. Be aware of the history of errors that occurred before this internal error. -
Linking user table with system table
Hello, I'm trying to link a user table with IC table in order to asign many sales person to a customer.
I've created a new button in the IC form. When clicked a new form is opened to asign sales person to the IC. Now I need to retrieve the records assigned to this IC. How can I do that???
Regards.
Angel.Hi Angel,
I would put a matrix in the new form where you could see/asign/delete the sales person.
Have a look at this post where you can find a great code from Sebastian Danober to fill a matrix from a recordset.
Another option could be to modify the existing IC form and add a new folder with a matrix where you can manage the sales person.
Check this other post with code for adding folder to an existing form.
Regards,
Ibai Peñ -
Join Istore table with AR tables
Hi Gurus,
How to join ibe_msites_b table with AR table. I am trying to get list of all customers from different mini sites. These are the AR tables i am using
HZ_Cust_Accounts
HZ_Parties
Regards,The following query should give you resullts for B2C. Change the query based on your requirement incase if you want it for B2B. Please note that I haven't added alll the conditions. This should be your starting point.
Hope this helps,
RK
SELECT imt.msite_name,
hp.party_name
FROM jtf_um_subscription_reg jusr,
jtf_um_subscription_resp jure,
fnd_responsibility fr,
ibe_msite_resps_b imrb,
ibe_msites_tl imt,
fnd_user fu,
hz_parties hp
WHERE jusr.subscription_id = jure.subscription_id
AND jure.responsibility_key = fr.responsibility_key
AND fr.responsibility_id = imrb.responsibility_id
AND imrb.msite_id = imt.msite_id
AND imt.language = USERENV('LANG')
AND fu.user_id =jusr.user_id
AND fu.person_party_id = hp.party_id -
How to link TCJ_Documents table with BKPF table
Dear all,
i am new ABAPer, i need to join TCJ_Documents table with BKPF table.
but, i can not find the relationship between this two tables.
so, please help !
thanks !Hi....
There is a company code (BUKRS) in both tables.
Also Fiscal year(GJAHR)...
What is the problem with that?
Sample code...
data: begin of itab occurs 0,
bukrs type bukrs,
cjnr type cjnr,
belnr type belnr_d,
end of itab.
start-of-selection.
select p~bukrs p~belnr q~comp_code from bkpf as p
inner join tcj_documents as q
on p~bukrs = q~comp_code
into table itab.
loop at itab.
write:/ itab-bukrs.
endloop.
Thanks,
Naveen.i -
Help in joining nested table with regular table
Im creating a nested table codelist as object prtcnpt_info. In a anonymous block im declaring t_code as nested table type codelist.
Now when i try to join the nested table with the regular oracle DB table and i get error: PL/SQL: ORA-00904: "COLUMN_VALUE": invalid identifier.
Please help me on this and provide tutorial link pertaining to this concepts..Below is the code i wrote
--Code Start;
create or replace type prtcnpt_info as object ( id number
,name varchar2(200)
,code varchar2(30));
create type codelist is table of prtcnpt_info;
declare
t_code codelist;
begin
select prtcnpt_info(b.pid ,b.name ,pt.code) bulk collect into t_code
from part pt
,mc_code b
where pt.cd in ('AAA','BBB')
and pt.ptype_id=b.pt_type_id;
INSERT INTO table ( ID
,RUN_ID
,DATA
,P_ID
SELECT id
,run_id
,data
,prtct.id ----> 1
FROM table_2 t2
,(select column_value from table(t_code)) prtct
WHERE prtct.id=t2.P_ID; ------> 2
end;
--Code End;
also from the anonymous block
1 => is this correct way to get value of id (b.pid) from the nested tablet_code aliased as prtct ?
2 => is this correct way to join the nested table with regular table? i want to join the column id's in both the tables.
Edited by: 914912 on Apr 30, 2012 2:11 AMWhen you create a table type without an object, i.e. a single column type like this you will get the column name as COLUMN_VALUE.
SQL*Plus: Release 10.2.0.5.0 - Production on Mon Apr 30 07:38:32 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create or replace type mytbl as table of varchar2(10)
2 /
Type created.
SQL> var rc refcursor
"afiedt.buf" 11 lines, 162 characters
1 declare
2 ltbl mytbl;
3 begin
4 select to_char(level) bulk collect into ltbl
5 from dual
6 connect by level <= 10;
7 open :rc for
8 select * from table(ltbl);
9* end;
10 /
PL/SQL procedure successfully completed.
SQL> print rc
COLUMN_VAL
1
2
3
4
5
6
7
8
9
10
10 rows selected.And when you create a table type with object you will get the object column name.
SQL> drop type mytbl
2 /
Type dropped.
SQL> create type myobj as object (id varchar2(10))
2 /
Type created.
SQL> create type mytbl as table of myobj
2 /
Type created.
SQL> declare
2 ltbl mytbl;
3 begin
4 select myobj(to_char(level)) bulk collect into ltbl
5 from dual
6 connect by level <= 10;
7 open :rc for
8 select * from table(ltbl);
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> print rc
ID
1
2
3
4
5
6
7
8
9
10
10 rows selected.
SQL> -
Is any one created Table with in table using adv table with VOs without EOs
If you have created Advnace table Master-Detail (Table with in table), please let me know the Controller code. I am using below. But getting Nullpointer excveption at innerTable.setAttributeValue(VIEW_LINK_NAME,"ViewLink1VL"); Please help me.
===========================
OAWebBean outerTable = (OAWebBean)webBean.findChildRecursive("region2");
OAWebBean innerTable = (OAWebBean)webBean.findChildRecursive("region4");
if (outerTable != null)
outerTable.setAttributeValue(CHILD_VIEW_ATTRIBUTE_NAME,"FLEX_VALUE_X");
outerTable.setAttributeValue(VIEW_LINK_NAME,"ViewLink1VL");
if (innerTable != null)
innerTable.setAttributeValue(CHILD_VIEW_ATTRIBUTE_NAME,"FLEX_VALUE_X");
innerTable.setAttributeValue(VIEW_LINK_NAME,"ViewLink1VL");
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.invokeMethod("initGoodsQuery");
============================My problem was solved when i used ,"ViewLink1VL1" instead of ,"ViewLink1VL" in controller code.
thanks.
Gopi. -
Creating View for a table with parent child relation in table
I need help creating a view. It is on a base table which is a metadata table.It is usinf parent child relationship. There are four types of objects, Job, Workflow, Dataflow and ABAP dataflow. Job would be the root parent everytime. I have saved all the jobs
of the project in another table TABLE_JOB with column name JOB_NAME. Query should iteratively start from the job and search all the child nodes and then display all child with the job name. Attached are the images of base table data and expected view data
and also the excel sheet with data.Picture 1 is the sample data in base table. Picture 2 is data in the view.
Base Table
PARENT_OBJ
PAREBT_OBJ_TYPE
DESCEN_OBJ
DESCEN_OBJ_TYPE
JOB_A
JOB
WF_1
WORKFLOW
JOB_A
JOB
DF_1
DATAFLOW
WF_1
WORKFLOW
DF_2
DATAFLOW
DF_1
DATAFLOW
ADF_1
ADF
JOB_B
JOB
WF_2
WORKFLOW
JOB_B
JOB
WF_3
WORKFLOW
WF_2
WORKFLOW
DF_3
DATAFLOW
WF_3
WORKFLOW
DF_4
DATAFLOW
DF_4
DATAFLOW
ADF_2
ADF
View
Job_Name
Flow_Name
Flow_Type
Job_A
WF_1
WORKFLOW
Job_A
DF_1
DATAFLOW
Job_A
DF_2
DATAFLOW
Job_A
ADF_1
ADF
Job_B
WF_2
WORKFLOW
Job_B
WF_3
WORKFLOW
Job_B
DF_3
DATAFLOW
Job_B
DF_4
DATAFLOW
Job_B
ADF_2
ADF
I implemented the same in oracle using CONNECT_BY_ROOT and START WITH.
Regards,
MeghaI think what you need is recursive CTE
Consider your table below
create table basetable
(PARENT_OBJ varchar(10),
PAREBT_OBJ_TYPE varchar(10),
DESCEN_OBJ varchar(10),DESCEN_OBJ_TYPE varchar(10))
INSERT basetable(PARENT_OBJ,PAREBT_OBJ_TYPE,DESCEN_OBJ,DESCEN_OBJ_TYPE)
VALUES('JOB_A','JOB','WF_1','WORKFLOW'),
('JOB_A','JOB','DF_1','DATAFLOW'),
('WF_1','WORKFLOW','DF_2','DATAFLOW'),
('DF_1','DATAFLOW','ADF_1','ADF'),
('JOB_B','JOB','WF_2','WORKFLOW'),
('JOB_B','JOB','WF_3','WORKFLOW'),
('WF_2','WORKFLOW','DF_3','DATAFLOW'),
('WF_3','WORKFLOW','DF_4','DATAFLOW'),
('DF_4','DATAFLOW','ADF_2','ADF')
ie first create a UDF like below to get hierarchy recursively
CREATE FUNCTION GetHierarchy
@Object varchar(10)
RETURNS @RESULTS table
PARENT_OBJ varchar(10),
DESCEN_OBJ varchar(10),
DESCEN_OBJ_TYPE varchar(10)
AS
BEGIN
;With CTE
AS
SELECT PARENT_OBJ,DESCEN_OBJ,DESCEN_OBJ_TYPE
FROM basetable
WHERE PARENT_OBJ = @Object
UNION ALL
SELECT b.PARENT_OBJ,b.DESCEN_OBJ,b.DESCEN_OBJ_TYPE
FROM CTE c
JOIN basetable b
ON b.PARENT_OBJ = c.DESCEN_OBJ
INSERT @RESULTS
SELECT @Object,DESCEN_OBJ,DESCEN_OBJ_TYPE
FROM CTE
OPTION (MAXRECURSION 0)
RETURN
END
Then you can invoke it as below
SELECT * FROM dbo.GetHierarchy('JOB_A')
Now you need to use this for every parent obj (start obj) in view
for that create view as below
CREATE VIEW vw_Table
AS
SELECT f.*
FROM (SELECT DISTINCT PARENT_OBJ FROM basetable r
WHERE NOT EXISTS (SELECT 1
FROM basetable WHERE DESCEN_OBJ = r.PARENT_OBJ)
)b
CROSS APPLY dbo.GetHierarchy(b.PARENT_OBJ) f
GO
This will make sure it will give full hieraracy for each start object
Now just call view as below and see the output
SELECT * FROM vw_table
Output
PARENT_OBJ DESCEN_OBJ DESCEN_OBJ_TYPE
JOB_A WF_1 WORKFLOW
JOB_A DF_1 DATAFLOW
JOB_A ADF_1 ADF
JOB_A DF_2 DATAFLOW
JOB_B WF_2 WORKFLOW
JOB_B WF_3 WORKFLOW
JOB_B DF_4 DATAFLOW
JOB_B ADF_2 ADF
JOB_B DF_3 DATAFLOW
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Union on tables with parent-child records and Sorting
Hi,
I have an application that has an existing query which returns org units (parent and child) from organization table with a sort on createddate + org_id combination
WITH Org_TREE AS (
SELECT *, null as 'IS_DELETED', convert (varchar(4000), convert(varchar(30),CREATED_DT,126) + Org_Id) theorderby
FROM Organization WHERE PARENT_Org_ID IS NULL and case_ID='43333'
UNION ALL
SELECT a1.*, null as 'IS_DELETED', convert (varchar(4000), a2.theorderby + convert(varchar(30),a1.CREATED_DT,126) + a1.Org_Id)
FROM Organization a1 INNER JOIN Org_TREE a2 ON a1.PARENT_Org_ID = a2.Org_Id and case_ID='43333'
SELECT * FROM Org_TREE order by theorderby
I have created a new log table for organization 'Organization_Log' with exact columns as Organization table with an additional 'IS_DELETED' bool column.
Questions:
I need to modiy the query,
1. To display the parent and child records both from the organization table and organization_log table.
2. the sort on the result should be based on 'Organization Name' column asc. First with parent org and the child org underneath it. For eg.
aaa
==>fff
==>ggg
bbb
==> aaa
==> hhh
Any help on how the query should be constructed?
Thanks
gkol@Visakh16,
I am getting...
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
The problem is that you will have different number of columns in both log and Organization and Organizationlog tables. UNION/UNION ALL expect the same number of columns.
Try the below:
WITH Org_Log_TREE AS (
SELECT Organization_name,Org_id,Parent_Org_id, IS_DELETED, CAST(Organization_Name AS varchar(max)) AS theorderby,1 AS level
FROM Organization_Log WHERE PARENT_Org_ID IS NULL and case_ID='43333'
UNION ALL
SELECT a1.Organization_name,a1.Org_id,a1.Parent_Org_id, a1.IS_DELETED, CAST(a2.theorderby +'/' + CAST(a1.Organization_Name AS varchar(1000)) AS varchar(max)),a2.Level + 1
FROM Organization_Log a1 INNER JOIN Org_Log_TREE a2 ON a1.PARENT_Org_ID = a2.Org_Id and case_ID='43333'
) ,Org_TREE AS (
SELECT Organization_name,Org_id,Parent_Org_id, NULL AS IS_DELETED, CAST(Organization_Name AS varchar(max)) AS theorderby,1 AS level
FROM Organization WHERE PARENT_Org_ID IS NULL and case_ID='43333'
UNION ALL
SELECT a1.Organization_name,a1.Org_id,a1.Parent_Org_id,NULL AS IS_DELETED, CAST(a2.theorderby +'/' + CAST(a1.Organization_Name AS varchar(1000)) AS varchar(max)),a2.Level + 1
FROM Organization a1 INNER JOIN Org_TREE a2 ON a1.PARENT_Org_ID = a2.Org_Id and case_ID='43333'
SELECT * FROM Org_Log_TREE
UNION ALL
SELECT * FROM Org_TREE
ORDER BY LEFT(theorderby,CHARINDEX('/',theorderby + '/')-1),Level -
How to check that my table is parent table or child table before trucating
Hi:
say i wanted to trucate a table .the table might be a parent table or might be a child table.if its a child table then there wouldnt be any problems in truncating.
if its a parent table the i believe i would have to diable all the foreign key constraints from the child table referring to the parent table ..my question is
1. i have a table say ABC. before truncating how do i find out if table ABC is a parent table or not?
2.lets assume i tried to truncate the table ABC and i got the error saying that disable the foreign keys on the child table referring to the parent table ABC.
in my schema there are say 50 tables.out of which there might be 10 odd child tables referring to my parent table ABC.
so my question here would be how do i specifically find out these 10child tables referring to the Parent table ABC so that i can disable the foreign keys on the child tables.
Thanks 4 ur time in reading this and hopefully i think u wld give me a solution!!Hi,
Try this SQL below:
select r.owner, r.table_name
from user_constraints r, user_constraints o
where r.r_owner = o.owner and r.r_constraint_name = o.constraint_name
and o.constraint_type in ('P','U') and r.constraint_type = 'R'
and o.table_name = 'ABC';Cheers -
Query to determined what tables are associated with parent table
Hello -
how would I query the data dictionary to determine what tables are referenced by a parent table via Pk/FK relationship?
Thanks in advance!
MikeHi,
Try this:
UNDEFINE table
UNDEFINE owner
ACCEPT owner CHAR PROMPT 'Enter Owner: '
ACCEPT table CHAR PROMPT 'Enter Table: '
COLUMN y new_value sid NOPRINT
SELECT name||'_'||TO_CHAR(sysdate, 'ddmonyy_hh24miss') y FROM v$database;
SPOOL constraints_&owner..&table..&sid..txt
SELECT a.constraint_name constraint, DECODE(a.constraint_type,
'C', 'Check',
'P', 'Primary Key',
'U', 'Unique Key',
'R', 'Referential Integrity',
'V', 'With Check Option',
'O', 'With Read Only') constraint_type,
a.index_name, a.owner||'.'||a.table_name table, a.status,
DECODE(a.r_owner||'.'||a.r_constraint_name,'.',null,a.r_owner||'.'||a.r_constraint_name) rconstraint,
f.constraint_name fconstraint, DECODE(f.owner||'.'||f.table_name,'.',null,f.owner||'.'||f.table_name) ftable,
f.status fstatus
FROM dba_constraints a, dba_constraints f
WHERE a.owner = f.r_owner(+) AND
a.constraint_name = f.r_constraint_name(+) AND
a.owner LIKE UPPER('&owner') AND
a.table_name LIKE UPPER('&tabla')
ORDER BY 3,1;
SELECT constraint_name constraint, owner||'.'||table_name||'.'||column_name column, position
FROM dba_cons_columns
WHERE owner LIKE UPPER('&owner') AND
table_name LIKE UPPER('&tabla')
ORDER BY 1,2;
SPOOL OFF
UNDEFINE table
UNDEFINE owner
PROMPT
PROMPT ******************************************** DEPENDENCIES ************************************************************
PROMPT
UNDEFINE object
UNDEFINE owner
UNDEFINE type
ACCEPT owner CHAR PROMPT 'Enter Owner: '
ACCEPT object CHAR PROMPT 'Enter Object: '
ACCEPT type CHAR PROMPT 'Enter Type: '
COLUMN REFERENCED_LINK_NAME FORMAT a10
PROMPT ******************************************** OBJECTS WITH DIRECT REFERENCE
SELECT owner||'.'||name object, type , referenced_owner||'.'||referenced_name robject, referenced_type rtype, dependency_type, referenced_link_name
FROM dba_dependencies
WHERE owner LIKE UPPER('&owner') AND
name LIKE UPPER('&object');
execute deptree_fill('&type','&owner','&object');
PROMPT ******************************************** DEPENDENCIES TREE
SELECT nested_level, schema||'.'||name object, type, seq#
FROM deptree
ORDER BY seq#;
UNDEFINE object
UNDEFINE owner
UNDEFINE typeCheers,
Francisco Munoz Alvarez
http://www.oraclenz.com -
How to Compare Data length of staging table with base table definition
Hi,
I've two tables :staging table and base table.
I'm getting data from flatfiles into staging table, as per requirement structure of staging table and base table(length of each and every column in staging table is 25% more to dump data without any errors) are different for ex :if we've city column with varchar length 40 in staging table it has 25 in base table.Once data is dumped into staging table I want to compare actual data length of each and every column in staging table with definition of base table(data_length for each and every column from all_tab_columns) and if any column differs length I need to update the corresponding row in staging table which also has a flag called err_length.
so for this I'm using cursor c1 is select length(a.id),length(a.name)... from staging_table;
cursor c2(name varchar2) is select data_length from all_tab_columns where table_name='BASE_TABLE' and column_name=name;
But we're getting data atonce in first query whereas in second cursor I need to get each and every column and then compare with first ?
Can anyone tell me how to get desired results?
Thanks,
Mahender.This is a shot in the dark but, take a look at this example below:
SQL> DROP TABLE STAGING;
Table dropped.
SQL> DROP TABLE BASE;
Table dropped.
SQL> CREATE TABLE STAGING
2 (
3 ID NUMBER
4 , A VARCHAR2(40)
5 , B VARCHAR2(40)
6 , ERR_LENGTH VARCHAR2(1)
7 );
Table created.
SQL> CREATE TABLE BASE
2 (
3 ID NUMBER
4 , A VARCHAR2(25)
5 , B VARCHAR2(25)
6 );
Table created.
SQL> INSERT INTO STAGING VALUES (1,RPAD('X',26,'X'),RPAD('X',25,'X'),NULL);
1 row created.
SQL> INSERT INTO STAGING VALUES (2,RPAD('X',25,'X'),RPAD('X',26,'X'),NULL);
1 row created.
SQL> INSERT INTO STAGING VALUES (3,RPAD('X',25,'X'),RPAD('X',25,'X'),NULL);
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT * FROM STAGING;
ID A B E
1 XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX
2 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX
3 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX
SQL> UPDATE STAGING ST
2 SET ERR_LENGTH = 'Y'
3 WHERE EXISTS
4 (
5 WITH columns_in_staging AS
6 (
7 /* Retrieve all the columns names for the staging table with the exception of the primary key column
8 * and order them alphabetically.
9 */
10 SELECT COLUMN_NAME
11 , ROW_NUMBER() OVER (ORDER BY COLUMN_NAME) RN
12 FROM ALL_TAB_COLUMNS
13 WHERE TABLE_NAME='STAGING'
14 AND COLUMN_NAME != 'ID'
15 ORDER BY 1
16 ), staging_unpivot AS
17 (
18 /* Using the columns_in_staging above UNPIVOT the result set so you get a record for each COLUMN value
19 * for each record. The DECODE performs the unpivot and it works if the decode specifies the columns
20 * in the same order as the ROW_NUMBER() function in columns_in_staging
21 */
22 SELECT ID
23 , COLUMN_NAME
24 , DECODE
25 (
26 RN
27 , 1,A
28 , 2,B
29 ) AS VAL
30 FROM STAGING
31 CROSS JOIN COLUMNS_IN_STAGING
32 )
33 /* Only return IDs for records that have at least one column value that exceeds the length. */
34 SELECT ID
35 FROM
36 (
37 /* Join the unpivoted staging table to the ALL_TAB_COLUMNS table on the column names. Here we perform
38 * the check to see if there are any differences in the length if so set a flag.
39 */
40 SELECT STAGING_UNPIVOT.ID
41 , (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_A
42 , (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_B
43 FROM STAGING_UNPIVOT
44 JOIN ALL_TAB_COLUMNS ATC ON ATC.COLUMN_NAME = STAGING_UNPIVOT.COLUMN_NAME
45 WHERE ATC.TABLE_NAME='BASE'
46 ) A
47 WHERE COALESCE(ERR_LENGTH_A,ERR_LENGTH_B) IS NOT NULL
48 AND ST.ID = A.ID
49 )
50 /
2 rows updated.
SQL> SELECT * FROM STAGING;
ID A B E
1 XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX Y
2 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX Y
3 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXHopefully the comments make sense. If you have any questions please let me know.
This assumes the column names are the same between the staging and base tables. In addition as you add more columns to this table you'll have to add more CASE statements to check the length and update the COALESCE check as necessary.
Thanks! -
WD4A Dynamic ALV Table with dynamic tables
Hi all,
first I want give you the information what I try to do.
I have an another WD4A application for administrative use in which I can assign certain tablefields to a certain user. You can say it's something like a customizing application.
In the next application (with my issues) I will display the tables for the user, but these tables are not the complete table.
I have a node in my context of the component controller which is bound to my ALV. I add during the runtime attributes to my node.
* .... coding ....declaration
* get the node
lr_node = wd_context->get_child_node( 'M_TABLE' ).
lr_node_info ?= lr_node->get_node_info( ).
* remove the attributes, if exists
lr_node_info->remove_dynamic_attributes( ).
* .... coding ....
* add attributes
LOOP AT l_t_m_table INTO l_s_m_table.
CLEAR ls_attribute.
* name of the attribute
MOVE l_s_m_table-NAME TO ls_attribute-NAME.
* DDIC type of the attribute
MOVE l_s_m_table-TYPE_NAME TO ls_attribute-TYPE_NAME.
* If the DDIC has a gen namespace like /B135/ replace the / with _
REPLACE ALL OCCURRENCES OF '/' IN ls_attribute-NAME WITH '_'.
* add the attribute
lr_node_info->add_attribute( EXPORTING
attribute_info = ls_attribute ).
ENDLOOP.
This coding works fine I get the columns in my ALV. Then I tried to fill my ALV table with data from a database table.
I created dynamicly an internal table with the following coding:
* Create dynamic table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = l_t_FLDCAT
IMPORTING
EP_TABLE = l_t_NEW_M_TABLE.
* assign the table
ASSIGN l_t_NEW_M_TABLE->* TO <M_TABLE>.
* structure of table
CREATE DATA l_s_NEW_M_TABLE LIKE LINE OF <M_TABLE>.
ASSIGN l_s_NEW_M_TABLE->* TO <l_s_m_table>.
* get data from database
SELECT * FROM (l_m_table) INTO CORRESPONDING FIELDS OF TABLE <M_table> WHERE OBJVERS = 'A'.
With this coding I get the data from the database and only the required fields that means I have e.g. an itab with columns1, columns3, columns4 from the database.
I also added e.g. these columns (columns1, columns3, columns4 from the database) to the node as attribute. Now it should be possible to bind the table to the structure with this coding:
lr_comp_usage_m = wd_this->wd_cpuse_usage_alv_M_table( ).
* create component if not active
IF lr_comp_usage_m->has_active_component( ) IS INITIAL.
lr_comp_usage_m->create_component( ).
else.
* set data if node exists
l_ref_interfacecontroller = wd_this->wd_cpifc_usage_alv_M_table( ).
l_ref_interfacecontroller->set_data( lr_node ).
endif.
* bind table
lr_node->bind_table( <M_TABLE> ).
Now, I get an error, which is caused by the table binding.
In ST22 I get:
Short text
Line types of an internal table and a work area not compatible.
What happened?
Error in the ABAP Application Program
The current ABAP program "CL_WDR_CONTEXT_NODE_VAL=======CP" had to be
terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
The statement
"INSERT wa INTO TABLE itab"
requires the lines of the internal table "TABLE" and the
work area " wa" to be compatible. Compatibility means
equivalence in the context of ABAP/4 type checking.
In this case, the condition is not satisfied because the internal table
"TABLE" has the line type "u" and the length 28, but the work area " wa"
has the type "C" and the length 2.
(If the work area " wa" is the header line of the internal
table "TABLE", the above inconsistency can arise if an internal
table t with the line type T1 is passed to a subroutine (FORM or
FUNCTION) as an actual parameter and the corresponding formal
parameter p is declared in the subroutine by "TABLES p STRUCTURE T2".
If then T1 and T2 are incompatible, the header line p
has the type T2 (specifed by STRUCTURE), but the internal
table p has the line type T1 (passed from the actual parameter)).
Source Code Extract
Line SourceCde
1 method if_wd_context_node~get_static_attributes_table .
2
3 field-symbols:
4 <element> like line of me->collection,
5 <static_attributes> type data,
6 <table> type index table.
7
8 * check whether elements are supllied or not
9 if me->elements_supplied = abap_false.
10 me->supply_elements( ).
11 endif.
12
13 clear table.
14
15 if me->table_ref is not initial.
16 assign me->table_ref->* to <table>.
17 table = <table>.
18 else.
19 loop at me->collection assigning <element> from from to to.
20 assign <element>->static_attributes->* to <static_attributes>.
error in line 21 insert <static_attributes> into table table.
22 endloop.
23 endif.
24
25 endmethod.
Any suggestions? Is it allowed to use bind_table() with a field symbol?
Another strange thing is that if I try the same with static itab and attributes during runtime it works, but only if the fields of the itab has the same name as the attributes, which means that I can not use itabs with fieldnames like /BI0/S_CUSTOMER and if I can not use them it's difficult to read data from database with SELECT * FROM ... INTO CORRESPONDING FIELDS OF TABLE itab.
Thanks in advance for your suggestions!
Best Regards,
MarcelHi Francois,
I solve it with the RTTI and the method
lr_node_info = lr_node_info->add_new_child_node(
name = 'Dynamic_TABLE'
IS_MANDATORY = ABAP_false
IS_MULTIPLE = ABAP_true
STATIC_ELEMENT_RTTI = lr_struct_descr
IS_STATIC = ABAP_false
I don't know why it doesn't work with adding attributes and binding the table after adding the attributes.
Anyway thanks for your help.
Best Regards,
Marcel
Maybe you are looking for
-
Windows Phone 8.1 Preview users still need to downgrade their OS in order to get Lumia Cyan
Just an FYI for those of you who jumped on the Windows Phone Developer bandwagon and subscribed to the Windows Phone Developer Preview to get an early look at 8.1. This is not such good news. As is the case with all Microsoft Beta and Pre Release S
-
24" iMac has buzzing sound every 5 min during sleep after upgrading to is x lion
I have a 24" iMac purchased new in 2009. Haven't had a problem and usually put it to sleep mode at night with no problem. I recently upgraded to OS X Lion and started noticing 2 problems during sleep mode. One is a constant humming noise that wasn
-
500 Internal Server Error in UWL Configuration Wizards
Hi All. I'm trying to configure UWL view thru wizards options. Unfortunately it comes with "500 Internal Server Error". The Root cause section tell me "The initial exception that caused the request to fail, was: java.lang.ClassCastException" Does any
-
It does all the steps but can't write a DVD, Right after failing, Toast pops open and wants to write a DVD. I tried a smaller project and still no writing. I'm seriously bummed as I can't see the video from a recent vacation until I get this figured
-
Do you prefer a stand-alone keyboard or a snap-in one, for your IPAD?
Hello all; thanks for reading: I'd like to buy a keyboard for my Ipad and I am up in the air between the Apple Bluetooth Keyboard and the Logitech Ultrathin Keyboard. The former seems like it would be easier to use while in bed, as I could propr up t