Update a column using a connect by or other for hierachical relationships
I have a column which represents the 'order' of which a record loaded out of a table.
This 'order' is coming in wrong.
I know, because of a relatoinship between two of the columns what the correct order should be.
So for example if I do this:
select transid, laborcode, supervisorfrom enclabor_iface
connect by prior laborcode = supervisor
start with supervisor = 0;
I get all the records in the correct order... but of course I'd like to figure out how to use this in an update statement to update the transid columns, which is the order.
Can someone tell me if this is possible, and if so, how to do so?
I have tried a few things with no luck yet, as the attempt took over 15 minutes to run so I thought I had coded it badly.
thanks
Jeff
Hi, Jeff,
Sure, that's possible.
The ROWNUM pseudo-column is assigned as the CONNECT BY clause (including ORDER SIBLINGS BY) is being applied, so you can use ROWNUM to capture the hierarchical order.
I don't have a copy of your table, so I'll use scott.emp to illustrate:
SELECT ename, empno, mgr
, ROWNUM AS r_num
FROM scott.emp
START WITH mgr IS NULL
CONNECT BY mgr = PRIOR EMPNO
ORDER SIBLINGS BY ename
;Output:
ENAME EMPNO MGR R_NUM
KING 7839 1
BLAKE 7698 7839 2
ALLEN 7499 7698 3
JAMES 7900 7698 4
MARTIN 7654 7698 5
TURNER 7844 7698 6
WARD 7521 7698 7
CLARK 7782 7839 8
MILLER 7934 7782 9
JONES 7566 7839 10
FORD 7902 7566 11
SMITH 7369 7902 12
SCOTT 7788 7566 13
ADAMS 7876 7788 14The default CONNECT BY ordering guarantees that (for example) all of BLAKEs descendants will come after BLAKE and before anyone who is not a descendant of BLAKE. However, it says nothing about whether BLAKE will come before JONES, or vice-versa. If that's important, use ORDER SIBLINGS BY.
To store those numbers in your table, do the query above in a MERGE statement.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
If you're asking about a DML statement, such as MERGE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using.
Edited by: Frank Kulash on Feb 7, 2012 11:46 AM
Similar Messages
-
Update some columns using case....
Hi ,
Is it possible to update some columns using case statement...????
For example when col1 is null then update to a value 'x' else update it to the value '*' , when col2 is null then update to a value y else update it to compute the running total up to that time....
This update statement is contained in db packaged procedure and it receives the values...as parameters....
How can i write down this update statement...?????
Many thanks,
SimonHi ,
Cant' it be used for two or more columns that have to be updated....????
i mean
update table set col_a = case when col_a is null then col_a else '*',
col_b = case when col_b is null then col_b else col_b+col_b_var
end
where .....The above in bold is running total.... This update is defined in a procedure and it receives numbers as parameters, so the need is to add them for every record it receives...., that's why i set above col_b+col_b_var... where col_b_var is the parameter of the procedure....
SORRY...IT IS POSSIBLE.....
Thanks , a lot
Simon
Message was edited by:
sgalaxy -
Dear Manger,
Our business would like to use or connect to an other online payment gateway on Business Catalyst, That's the KCP (www.KCP.co.kr) serviced in South Korea.
We have registered already at KCP. Can we use or connect the payment gateway service on Bc? I think, a technical issue is not the problem.
Of course, a business target of the global online shop is Asia including South Korea. So we need the global & domestic payment gateway. Our headquarter is in Korea, Republic of. (South Korea).
Is it something problem for using the payment gateway service?
And If we get possible, how long take the installation period?
Your reply is much awaited.
All the best of success.
Sincerely,
William NAMI don't believe that is a supported gateway with BC.
Talk to these guys: Two Blokes With A Postie - They can help you integrate a third party gateway with BC using the API. -
How to update a column using hibernate
how to update a particular column using hibernate..
iam using oracle databaseI think you didn't get the point. This is a generic Java forum... not a Hibernate forum.
-
Hi everyone,
still playing around with newbie stuff here. Is it possible to update a column or a row using a cursor? I understand how to fetch a data using a cursor, but not sure if it can help to update a data.
If it can, what's the syntax?
Regards,
Valeriehi,
why you opted to update rows by using cursor.
why not you opt DML
or
just want to know
SQL> SET LINE 32323
SQL> /
Rollback complete.
SQL> SELECT *FROM EMP;
7499 KITTU SALESMAN 7698 20-FEB-81 15800 25050 30
7566 JONES MANAGER 7839 02-APR-81 3175 446.25 20
7654 RAVIKUMAR SALESMAN 7698 28-SEP-81 1450 1587.5 30 [email protected]
7698 BLAKE MANAGER 7839 01-MAY-81 3050 427.5 30
7782 CLARK MANAGER 7839 09-JUN-81 2650 367.5 10
7788 SCOTT ANALYST 7566 09-DEC-82 3200 450 20
7839 KING PRESIDENT 17-NOV-81 5200 8250 10
7844 TURNER SALESMAN 7698 08-SEP-81 1700 225 30
7876 ADAMS CLERK 7788 12-JAN-83 1300 165 20
7900 JAMES CLERK 7698 03-DEC-81 1150 85.5 30 [email protected]
7902 FORD ANALYST 7566 03-DEC-81 3200 450 20
7934 MILLER CLERK 7782 23-JAN-82 1500 195 10
8000 KINGBABA PRESIDENT 17-NOV-81 5200 8250 10
8001 TURNER RAV SALESMAN 8000 08-SEP-81 1700 450 30
14 rows selected.
SQL> DECLARE
2 CURSOR CUR_EMP IS SELECT *FROM EMP;
3 CUR_EMP1 CUR_EMP%ROWTYPE;
4 BEGIN
5 OPEN CUR_EMP;
6 LOOP
7 FETCH CUR_EMP INTO CUR_EMP1;
8 EXIT WHEN CUR_EMP%NOTFOUND;
9 UPDATE EMP SET ENAME='TEST'
10 WHERE ENAME=CUR_EMP1.ENAME;
11 END LOOP;
12 CLOSE CUR_EMP;
13 END;
14 /
PL/SQL procedure successfully completed.
SQL> SELECT *FROM EMP;
7499 TEST SALESMAN 7698 20-FEB-81 15800 25050 30
7566 TEST MANAGER 7839 02-APR-81 3175 446.25 20
7654 TEST SALESMAN 7698 28-SEP-81 1450 1587.5 30 [email protected]
7698 TEST MANAGER 7839 01-MAY-81 3050 427.5 30
7782 TEST MANAGER 7839 09-JUN-81 2650 367.5 10
7788 TEST ANALYST 7566 09-DEC-82 3200 450 20
7839 TEST PRESIDENT 17-NOV-81 5200 8250 10
7844 TEST SALESMAN 7698 08-SEP-81 1700 225 30
7876 TEST CLERK 7788 12-JAN-83 1300 165 20
7900 TEST CLERK 7698 03-DEC-81 1150 85.5 30 [email protected]
7902 TEST ANALYST 7566 03-DEC-81 3200 450 20
7934 TEST CLERK 7782 23-JAN-82 1500 195 10
8000 TEST PRESIDENT 17-NOV-81 5200 8250 10
8001 TEST SALESMAN 8000 08-SEP-81 1700 450 30
14 rows selected.Edited by: user291283 on Sep 1, 2009 10:42 PM -
Update hidden column using Apply MRU
I want to update username which is a hidden column with an value when I submit update using ApplyMRU. How can I do it?
Apex 4.1, Browser IE/FireFox, Using Form Tabular with ApplyMRU.Can someone help on this?
-
How to update the columns using sql queries?
create table emp(eno number(5),ename varchar2(20),dno number(2),dname varchar2(20),loc_id number(3), location varchar2(10));
insert into emp(eno,ename,dno,loc_id) values(1,'tom1',10,1);
insert into emp(eno,ename,dno,loc_id) values(2,'tom2',20,2);
insert into emp(eno,ename,dno,loc_id) values(3,'tom3',30,3);
insert into emp(eno,ename,dno,loc_id) values(4,'tom4',40,4);
insert into emp(eno,ename,dno,loc_id) values(5,'tom5',50,5);
insert into emp(eno,ename,dno,loc_id) values(6,'tom6',60,6);
insert into emp(eno,ename,dno,loc_id) values(7,'tom7',70,7);
insert into emp(eno,ename,dno,loc_id) values(8,'tom8',80,8);
create table dept(dno number(3),dname varchar2(10));
insert into dept values(10,'RM');
insert into dept values(10,'DD');
insert into dept values(10,'TD');
create table location(loc_id number(3),location varchar2(20));
insert into location values(1,'palani');
insert into location values(1,'salem');
insert into location values(1,'kalpattu');
insert into location values(1,'thirukoyilur');
insert into location values(2,'thaeni');
insert into location values(2,'villupuram');
insert into location values(2,'yercaud');
insert into location values(3,'thiruvanamalai');
insert into location values(3,'trichy');
insert into location values(7,'tanjore');
insert into location values(4,'tirunelveli');
insert into location values(4,'namakal');
insert into location values(5,'bangalore');
insert into location values(6,'chennai');
insert into location values(6,'calcutta');
insert into location values(7,'tirupathy');
insert into location values(7,'bombay');
insert into location values(7,'kumbokonam');
My requirement is to update the department name and location of toms present in employee table without using cursors, loops.
The column department number and loc_id are used for joins.
I am in a situation to deliver my code on time.try this
update emp tt
set (dname,location ) = (
select res,res1 from (select a.eno,a.ename,a.dno,b.dname,a.loc_id,c.location
from emp a,
dept b,
location c
where a.dno = b.dno
and a.loc_id = c.loc_id
) t
where tt.eno = t.eno
model
return updated rows
partition by (eno)
dimension by (row_number() over (order by eno) as rn)
measures(cast (dname as varchar2(50)) as res,cast (location as varchar2(300)) as res1)
rules
upsert
iterate(1000)
until(presentv(res[iteration_number + 2],1,0) = 0)
res[0] = res[0] ||','|| res[iteration_number + 1],
res1[0] = res1[0] ||','|| res1[iteration_number + 1]))
;output
1 tom1 10 ,RM,RM,RM,RM,DD,TD,DD,DD,TD,TD,TD,DD 1 ,palani,salem,kalpattu,thirukoyilur,palani,thirukoyilur,kalpattu,thirukoyilur,palani,salem,kalpattu,salem
2 tom2 20 2
3 tom3 30 3
4 tom4 40 4
5 tom5 50 5
6 tom6 60 6
7 tom7 70 7
8 tom8 80 8 -
Updating a column using deleted/inserted during update statement execution
I need to capture the old value while update statement is executed. I can not insert into temp table (there are many samples online where you can use OUTPUT clause to insert data in same table or another temp table)
something like
declare @count table
id int,
changed varchar (50)
insert into @count (id,changed) values (2,'T')
insert into @count (id,changed) values (3,'T')
insert into @count (id,changed) values (4,'T')
select * from @count
UPDATE @count
SET id=5,
Changed = GETDATE() -- here instead of date, I want to get inserted.id and deleted.id
OUTPUT inserted.id,
deleted.id
where id = 2
SELECT *FROM @count
Any help on this will be very much appreciated....I am not sure to follow your question but you can get the old value just by doing:
UPDATE @count
SET id=5,
Changed = id
OUTPUT inserted.id,
deleted.id
WHERE id = 2;
since SQL Server uses all-at-once operations.
Microsoft SQL Server 2012 T-SQL Fundamentals
http://shop.oreilly.com/product/0790145321978.do
AMB
Some guidelines for posting questions... -
Need to update multiple columns using another table
I have 2 tables. and i need to update rows of 1 table using another table
Table1
Serial_no. payment_date Payment_amt
101 22/11/2010 150
101 18/03/2011 355
102 15/04/2011 488
103 20/05/2011 178
102 14/06/2011 269
101 28/06/2011 505
Table2
Serial_no Charge_amt Last_paymt_dt Last_paymt_amt
101 255
102 648
103 475
I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
Update Table2
set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
where table1.Serial_no = table2.Serial_no group by payment_amt)
kindly suggest how should i update.SQL> select * from table1
2 /
SERIAL_NO PAYMENT_DA PAYMENT_AMT
101 22/11/2010 150
101 18/03/2011 355
102 15/04/2011 488
103 20/05/2011 178
102 14/06/2011 269
101 28/06/2011 505
6 rows selected.
SQL> select * from table2
2 /
SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
101 255
102 648
103 475
SQL> update table2
2 set (last_paymt_dt,last_paymt_amt) = (
3 select max(payment_date),
4 max(payment_amt) keep(dense_rank last order by payment_date)
5 from table1
6 where table1.serial_no = table2.serial_no
7 )
8 /
3 rows updated.
SQL> select * from table2
2 /
SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
101 255 28/06/2011 505
102 648 14/06/2011 269
103 475 20/05/2011 178
SQL> SY. -
Since updating my iPad 3rd generation to ios 6 I am having trouble connecting with FaceTime and messaging. Anyone have any suggestions?
They've changed it in iOS and updates (and updates ONLY) do not require a password since it is really unnecessary as they have it on record that you were the one who bought the app. Why is more security needed, you aren't going to be charged for anything?
Next time you update and app go to the App Store and try to buy something. You will be asked for your password. -
How to update a column with different values but all other row values r sam
Hi,
I have a table like this.
Col1 col2 col3 col4
10 20 30
10 20 30
10 20 30
i need to update col4 with different values coming from other table like this
Col1 col2 col3 col4
10 20 30 xxxx
10 20 30 yyyy
10 20 30 zzzz
how can i update the table. pls let me know how to use the where condition in the update stmt.
thanks,
jay
Edited by: user2558790 on Nov 20, 2009 12:26 PMwhat is the logic for this kind of update...????
Greetings,
Sim -
Can an airport express be used to connect to things other than apple products?
I have not yet bought this product, but I was wondering if it will only connect to apple products or other products for example my PS3?
Yes, if you have an AirPort Express 802.11n. If you are not sure, look on the side of the device for the Model Number. You want to see # A1264.
This also assumes that the AirPort Express is located at a point where it can receive a strong signal from the Time Capsule. -
Why my ipad 4th gen doesnt update apps using wifi connection instead works on 3G?
MY ipad 4th gen is updating apps only using 3g connection whereas my wifi is working fine with chrome and other softwares, but it doesnt update softwares using wifi connection whic. Is unlimited data for me.
The WiFi only iPad does not have a GPS chip and does location through WiFi routers. Tethering to your iPhone will allow you to use the GPS chip on it and utilize Apple and Google Maps.
-
What's the difference between using a connection pool and a datasource
Howdy. I figure this is a newbie question, but I can't seem to find an
answer.
In the docs at bea, the datasource docs say
"DataSource objects provide a way for JDBC clients to obtain a DBMS
connection. A DataSource is an interface between the client program and the
connection pool. Each data source requires a separate DataSource object,
which may be implemented as a DataSource class that supports either
connection pooling or distributed transactions."
In there it says the datasource uses the connection pool, but other than
that, what is the difference between a connection pool and a datasource?Thanks for the info. I think it makes some sense. But it's a bit greek.
I'm sure it'll make more sense the more I work with it. Thanks.
"Chuck Nelson" <[email protected]> wrote in message
news:3dcac1f5$[email protected]..
>
Peter,
Here is a more formal definition of a DataSource from the Sun site
"A factory for connections to the physical data source that thisDataSource object
represents. An alternative to the DriverManager facility, a DataSourceobject
is the preferred means of getting a connection. An object that implementsthe
DataSource interface will typically be registered with a naming servicebased
on the JavaTM Naming and Directory (JNDI) API.
The DataSource interface is implemented by a driver vendor. There arethree types
of implementations:
Basic implementation -- produces a standard Connection object
Connection pooling implementation -- produces a Connection object thatwill automatically
participate in connection pooling. This implementation works with amiddle-tier
connection pooling manager.
Distributed transaction implementation -- produces a Connection objectthat may
be used for distributed transactions and almost always participates inconnection
pooling. This implementation works with a middle-tier transaction managerand
almost always with a connection pooling manager.
Does that help clarify the distinction?
Chuck Nelson
DRE
BEA Technical Support -
Using Adobe Connect for Tutoring Business
Hello,
I am starting an online tutoring business, and i would like to use Adobe Connect as the platform for tutoring service. I would like what are the difference between using Adobe Connect (Enterprise) or Adobe Connect (Individual). I would like to input my company's logo in the Adobe Connect, but all i really need for my business is the webcam and whiteboard interface.
In addition,will there be legal problmes if i use Adobe Connect Individual for my business?
Your comments will be much appreciated!
Thank you so much!I'm not sure about the legal concerns around this (I would contact Adobe Enterprise Sales for this), but the major differences are that the individual site has are no customizations and you of course have smaller license limits (one meeting host).
Maybe you are looking for
-
Why can't I find Painter X3 in the bridge CS5 "open with " command list?
I just installed Painter X3 and can't find it in the "open with" list. Painter X was there along with Firefox for PSD files, so how do I add it?
-
Is it possible to restore a datafile after opening the db using resetlogs?
Hi Experts, We have cloned the db and after opening the db with resetlog option we came to know that one of the user db file is not part of the db and is showing the below error while checking the status and attempting to online it. When checking the
-
ESS Claims: Reimbursement types not appearing in portal
Hi ESS Experts, I have done al the configuration required for Claims functionality and it was working fine also. Now I am not able to see cliam list in ESS application. I using Java Application. T7INT9 and A9 tables are cofigured and eligibility is s
-
When I first got started with Mac, I had a different e-mail address. I have a new e-dress and new passwords, but much of what I bought was with that old e-dress. Now, I'm trying to migrate my i-tunes library to a new computer, and I can't get authori
-
Confirmation for closing other tabs
the issue was opened for v.16 "Firefox 16 asks for confirmation for closing other tabs" and reported as "fixed" but i have the version 20.0.1 and the issue is still not solved. I mention that the checkbox "Options/Tabs/Warn me when closing mutiple ta