SQL & PL/SQL :: Update With Recursive Query
Aug 5, 2010
I have this SQL select to give me all the nodes of a tree starting at a particular node:
SELECT tree.node_id, LEVEL depth_level
FROM tree_of_nodes nodes
START WITH nodes.node_id = 1000
CONNECT BY PRIOR nodes.node_id = nodes.parent_id
I need to update a column called dept_level, which is essentially the same as Oracle's LEVEL. Something like this statement is what I need, but obviously this statement doesn't work:
update tree_of_nodes
set depth_level = LEVEL
START WITH nodes.node_id = 1000
CONNECT BY PRIOR nodes.node_id = nodes.parent_id
I've tried inline views and other approaches and have not found a method that works.
View 3 Replies
ADVERTISEMENT
Sep 8, 2012
I need to do a PL/SQL program that prints the same that this WITH clause query, without using WITH or CONNECT BY, i was thinking about a solution with cursors?
WITH recursiveBOM
(assembly_id, assembly_name, parent_assembly) AS
(SELECT parent.assembly_id,
parent.assembly_name,
parent.parent_assembly
FROM bill_of_materials parent
[code].....
View 8 Replies
View Related
May 5, 2013
I have the following table structure...............
Main_Head table name
main_head_id ,pk
head_desc,
head_id ,
sub_head_id
keys
col table ref col
sub_head_id main_head head_id
the table is recursive table self join
-----------------------------------------
now i want to write the query which return all head_desc which have same head_id
View 12 Replies
View Related
Mar 5, 2013
To use dynatree (URL] I want the result to be in the xml form.but the result is not what I want.
SELECT
XMLELEMENT("div",xmlattributes('tree' AS "id"),
(SELECT DBMS_XMLGEN.getXMLType(
DBMS_XMLGEN.newContextFromHierarchy('
SELECT LEVEL,
case
when CONNECT_BY_ISLEAF = 0 then
[code]....
View 6 Replies
View Related
Nov 9, 2011
We are on oracle 10.2.0.4 on solaris 10. My question is on a sql query. Is it possible to rewrite a query to avoid the connect by and prior constructs and use joins? For example i have the following query:
SELECT empno,
ename,
job,
mgr,
hiredate
FROM emp
START WITH empno in (7566,7698)
CONNECT BY PRIOR empno = mgr
How can it be rewritten using a two table join (self join)? I am not sure if it can be done and whether it is possible.
View 4 Replies
View Related
Dec 6, 2011
I have a table:
create table FIELDS
(
FIELD_NAME VARCHAR2(30) not null,
PRG_FIELD NUMBER not null,
LENGTH NUMBER
);
with
INSERT INTO FIELDS VALUES('FIELD1', 1, 3);
INSERT INTO FIELDS VALUES('FIELD2', 2, 3);
INSERT INTO FIELDS VALUES('FIELD3', 3, 4);
INSERT INTO FIELDS VALUES('FIELD4', 4, 2);
INSERT INTO FIELDS VALUES('FIELD5', 5, 1);
I need to insert in a table:
create table STUFF
(
FIELD_NAME VARCHAR2(30) not null,
FSTART NUMBER not null,
LENGTH NUMBER
);
And the output I want is:
INSERT INTO STUFF VALUES('FIELD1',0,3);
INSERT INTO STUFF VALUES('FIELD2',3,3);
INSERT INTO STUFF VALUES('FIELD3',6,4);
INSERT INTO STUFF VALUES('FIELD4',10,2);
INSERT INTO STUFF VALUES('FIELD5',12,1);
So each field starts where the previous (ordered by PRG_FIELD asc) ends.
I think the query should use both lag and connect by but I haven't had any luck writing it. The problem is that all the examples I've seen around, using connect by prior, utilize 2 fields with different names, es connect by prior emp_id = mgr_id. Instead I should do something like connect by prior prg_field = prg_field-1 but that doesn't seem to work.
PS: I don't necessarily need to do this, I have a guy manually writing the inserts, this is just an exercise I would like to figure out
View 1 Replies
View Related
Jul 17, 2012
I am working on the quality center oracle database to write a query that fetches all steps of a test case including the ones having calls to tests. Structure of table is explained below. I've made up an example and attached it as an image to this post. This image also has the expected result of the query I want to write.
Table Name: STEPS (This table contains steps belonging to tests. Some steps are simply calls/links to other tests)
Columns:
STEP_ID (primary key - integer)
STEP_NAME (char)
STEP_DESC (char)
ORDER (integer)
TEST_ID (reference to table TEST.test_id)
[code].......
Referring to the example (see attached image), I'm looking to write a query that gives me all steps (including steps from called tests) of the test - "Empty trash from mailbox" in the correct order.
To start with I can write the following query to get steps of the test - "Empty trash from mailbox".
SELECT * FROM steps WHERE test_id = (SELECT test_id FROM test WHERE test_name = 'Empty trash from mailbox')
View 7 Replies
View Related
May 3, 2013
We have an requirement to create xml data for entire database (selected tables) which are in hierarchy.Procedure should read node_mapping table having parent and child tables relationship info and build XML Select statement.
Currently it is building SQL statement whenthere are one parent having multiple childrens i.e Dept having emp, emp_act, emp_rsch..but when child node are having childrens then it is not working - it has to repeatedly call this procedure (recursive) and build below given SQL statement.
1. To change procedure to build xml sql statement when there are multiple childrens to child nodes (hierarchy)
2. To format the output in xml data
We are using ORACLE 11G and WINDOWS 7
CREATE TABLE node_mapping
(
NODE_ID NUMBER(5) PRIMARY KEY,
PARENT_NODE VARCHAR2(100),
CHILD_NODE VARCHAR2(100),
PARENT_NODEID VARCHAR2(50),
CHILD_NODEID VARCHAR2(50)
[code]....
View 1 Replies
View Related
Jul 14, 2012
How can we overcome recursive triggers in oracle SQL?
View 7 Replies
View Related
Sep 24, 2012
I need to use Recursive Subquery Factoring for a project of mine, specifically I need to use some code I have found in a function.
[URL]
The code I have so far is this:
create or replace
function recursive
(
pattern in raw
, solution in raw
) return number as
[code]....
But when trying to compile it in Oracle SQL Developer, I get the following two errors:
Error(9,1): PL/SQL: SQL Statement ignored
Error(10,30): PL/SQL: ORA-00907: missing right parenthesis
The errors refer to these two lines:
with x( s, ind ) as
( select sud, instr( sud, '' '' )
I have looked over and over the code again, and I do not see any missing parenthesis. Furthermore I tried using with in a smaller test function:
create or replace function test
(
p in number
)
return number as
v number;
begin
with t(a) as
[code]....
Which compiles just fine, so I'm not sure why that line is being ignored in this function. The whole idea here is to replace the sudoku string in the function with a variable that I built from the two parameters.
View 5 Replies
View Related
Jun 26, 2012
How to update single table column using join query
Example:
Update table1 t1,table2 t2
set t1.column2 = 'Y'
where t1.column1 = t2.column1
View 8 Replies
View Related
Jun 12, 2013
I have 2 tables with 3 common columns (Col1, col2,Primary). One common column name is primary (oracle key word).Around 2 lakhs rows to be updated and No indexes are used on these tables. I need to write an update query as shown below.
Emp table
Col1col2primay
100101y
103104n
201105y
100101y
Dept table
Col1col2primay
100101null
103104null
000656null
Update query Result
Col1col2primary
100101y
103104n
View 16 Replies
View Related
Mar 14, 2011
I am using Oracle 10g Database as back end and Developer 6i as front end.I have a procedure which is called upon SAVE. Means before COMMIT;This procedure holds few updates and delete statments.
This prcedure is throughing sql error as follows: ORA-00604: error occurred at recursive SQL level
The error occur when an delete statment is issued which as follows: DELETE FROM DUMMY_TAB001;
I issue the same statement from SQL it is running fine. But when my from runs on this delete statment encounter it through the above oracle error ORA-00604.
View 7 Replies
View Related
May 11, 2011
In MS Windows, if I copy a file and paste it into the same folder, I get a copy with the text 'Copy of' in front of the file name. If I paste it again, I get another copy with a different version number.
E.g.
sqlnet.log
Copy of sqlnet.log
Copy (1) of sqlnet.log
Copy (2) of sqlnet.log
I was wondering if I could copy existing rows into a table and do the same thing?
So, for example if I had this table:
create table tst_srch (srch_is varchar(100), user_name varchar(100), srch_name varchar(100));
insert into tst_srch values (1,'USER1','SRCHA');
insert into tst_srch values (2,'USER1','SRCHB');
insert into tst_srch values (3,'USER1','SRCHC');
insert into tst_srch values (4,'USER1','SRCHD');
insert into tst_srch values (5,'USER2','SRCHC');
insert into tst_srch values (6,'USER2','SRCHD');
insert into tst_srch values (7,'USER2','SRCHD_1');
Could I write a procedure like copy_searches('USER1','USER2') that would copy all USER1's searches to USER2 - including renaming any duplicates.
So it would create these new rows:
8,USER2,SRCHA
9,USER2,SRCHB
10,USER2,SRCHC_1
11,USER2,SRCHD_2
I've looked at various insert statements, merge and match statements and exception handling in procedures .
View 6 Replies
View Related
Sep 9, 2009
I've just started with the Oracle SQL and come from a heavy MS SQL background and I understand that here are some natural differences in the syntax but I'm stumped as to why the following sql represents a problem:
update MASTERMICODES t1
set t1.TEMPTA = ( select t2.TAFCODE
from TA_FEATURES t2
where t2.FCODE = t1.FCODE
)
It returns Error report:
SQL Error: ORA-01427: single-row subquery returns more than one row
01427. 00000 - "single-row subquery returns more than one row"
*Cause:
*Action:
I want it to return more than one row...in fact I want it to make on all rows that have the same fcode between tables.
View 2 Replies
View Related
Jul 18, 2012
I am looking to build a query to update a current value in a DBA view to a new one.i.e. updating directories based on the current value:
CREATE OR REPLACE DIRECTORY 'DIRECTORY_NAME' AS 'DIRECTORY_PATH'(substr(directory_path, 1,5) + '/&dbname' {i.e. this is different for every database name }+ 'DIRECTORY_PATH'(string after /xyz/)
WHERE DIRECTORY_NAME in
( select DIRECTORY_NAME
from DBA_DIRECTORIES
WHERE DIRECTORY_PATH
like '/xyz/%'
)
i.e. resulting output should be:
CREATE OR REPLACE DIRECTORY 'ABC' AS '/xyz/DBNAME/abc/def/';
(when the directory previously was 'xyz/abc/def/') i.e. basically inserting the db name into the directory.where DBNAME is a variable more directories are added frequently so therefore this needs to be a dynamic procedure to change the directories in the db.
View 26 Replies
View Related
Sep 20, 2011
The requirement is I have a table (TAB1), wherein I have 3 columns, ID, LID and STATUS.
The value in ID column = ID_SEQ.NEXTVAL,and LID will be either 0 or 1 and the possible values for STATUS are 'ED','CP', NULL. The ID column is not suppose to have duplicate values, but there is no check on the table for the same.
Someone has updated the existing data and ID column is containing duplicate values. Wherever LID = 0 and STATUS = NULL and if only if ID is duplicated then the ID_SEQ.NEXTVAL has to be assigned to ID field, so that there are no more duplicate values.
CREATE TABLE tab1 (id NUMBER , lid NUMBER, status VARCHAR2(10));
Existing Data
------------------
INSERT INTO tab1 VALUES (1,0, 'ED');
INSERT INTO tab1 VALUES (1,0, 'CP');
INSERT INTO tab1 VALUES (1,0, NULL);
INSERT INTO tab1 VALUES (1,0, NULL);
INSERT INTO tab1 VALUES (1,0, NULL);
INSERT INTO tab1 VALUES (1,0, NULL);
[code]....
get the result using a single update statement.
View 5 Replies
View Related
Nov 22, 2011
How to update two tables in single set or single query ?
View 8 Replies
View Related
Jan 4, 2013
I am trying to use the below query
update t_emp set TTL_FLG =
CASE
WHEN EXISTS
(SELECT 1 from Schema1.T_STG_LW_EMP E
WHERE E.Employee = Schema2.T_emp.EMPLOYEE_NUMBER
AND E.JB_CODE like '%TP%' or E.JB_CODE like '%DGD%' or E.JB_CODE like '%PDD%'
or E.JB_CODE like '%YND%'
)
THEN 'Y'
ELSE 'N'
END;
View 1 Replies
View Related
Nov 19, 2010
We have a form which contain the multiple record.
I require to disable the record during the query, if the certain flag (Y) is activiate. And their as allow to display the next record without the flag (N) is editable.
how to done it.
View 1 Replies
View Related
Nov 16, 2012
I've seen this example numerous places, and tried to implement it, but I keep getting an "invalid identifier" error message, despite the fact that I've got the table and column specifically identified.For instance, my query reads like:
UPDATE tbl1
SET tbl1.EMPID =
(SELECT tbl2.EMPIDA FROM tbl2
WHERE LOWER(tbl1.EMAILCOL) = LOWER(tbl2.EMAILCOL2)
)
WHERE tbl2.EMPIDA IN ('Z1O435','S8M4722','M0D5156')
AND EXISTS
(SELECT tbl2.EMPIDA
FROM tbl2
WHERE tbl1.EMAILCOL= tbl2.EMAILCOL2 );
But I'll keep getting flagged at the tbl2.EMPIDA column reference. I have not tried this in SQL Plus, just in TOAD, but it seems to repeatedly fail.I have had to dump records to standalone Access tables and link back to perform the updates.
View 12 Replies
View Related
Mar 21, 2011
There is a table copper_terminal with columns
small_world_id,address_number,street_name.
I need to update small_world_id with address_number,street_name I am trying to write as
SQL> update COPPER_TERMINAL set smallworld_id=ADDRESS_NUMBER||_||STREET_NAME whe
re copper_terminal_id='45';
update COPPER_TERMINAL set smallworld_id=ADDRESS_NUMBER||,||STREET_NAME where co
pper_terminal_id='45'
*
ERROR at line 1: ORA-00911: invalid character
How to correct this??
View 4 Replies
View Related
Oct 15, 2012
is it possible to update a same column name in two tables.
I have two tables in same schema
(1)table name
pem.igp_parent
column name
igp_no.
igp_type
(2)table name
pem.igp_child
column name
igp_no.
igp_type
i want to update igp_no column in one query, how it would be possible.
View 2 Replies
View Related
Aug 19, 2010
Ive just tried running a simple
update BASIC set 'column name' = NULL
Which works fine if i specify a where clause that returns a low amount of values, but im trying to run this update for the whole column (1000's or records).
Ive had no experience of this error before and am unsure of where to start, ive had a quick read around but see something of removing triggers?
The full error is :
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-06512: at "new.su_Table", line 61
View 22 Replies
View Related
Nov 3, 2010
I'm trying to drop a user but it gives me below error message-
SQL> drop user <username> cascade;
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-24005: must use DBMS_AQADM.DROP_QUEUE_TABLE to drop queue tables
However when i check from dba_queue_tables or user_queue_tables it doest show any queue tables.
View 6 Replies
View Related
Jun 22, 2013
Oracle Version :- 11.2.0.2 I found a error in a trigger(Statement Level) ORA-00604:error occurred at recursive SQL level string. Before Finding this issue,Once the DB Response was slow . Will this be the issue Of DB Slow response. The Above trigger fires for each entry in an transaction table. The code is Patched and was executed . The above issue was found during another issue and not the DB Slow response. My Doubt is Whether DB response slow issue would be because of this. Now after fixing this Slow response was not reported.
View 0 Replies
View Related
Aug 29, 2012
I have getting error will insert into table i.e
i have a trigger as below
create or replace trigger INS_ERRORS
before insert on MIG_STG_ERRORS
for each ROW
declare
V VARCHAR2(22);
[code]........
when i insert into MIG_STG_ERRORS getting error message like 00036. 00000 - "maximum number of recursive SQL levels (%s) exceeded"
*Cause: An attempt was made to go more than the specified number of recursive SQL levels.
*Action: Remove the recursive SQL, possibly a recursive trigger.
View 4 Replies
View Related
Oct 6, 2010
I am running one update statement which is running almost one hour still no response.
I would like to know either query is processing or hanging(suppose to finish the update within few minutes).
Is there any way or sql to find either the statement(my update query) is running or hanging.
View 4 Replies
View Related
May 25, 2012
How to update two table column in single query ?
example :
update table1 t1 ,table2 t2
set t1.column = 'Yes',t2.column='Yes'
where t1.emp_code =t2.emp_code ;
View 1 Replies
View Related
Jan 27, 2012
Actully i am updating two table of data.. but below error message came..
update (select ename, dname
from emp e, dept d
where e.deptno = d.deptno
and empno = 7788)
set ename = 'X', dname = 'Y'
/
Error at line 1
ORA-01776: cannot modify more than one base table through a join view
View 10 Replies
View Related