create new record from LAST record with SQL [message #609384] |
Thu, 06 March 2014 03:51 |
oralover2006
Messages: 144 Registered: January 2010 Location: India
|
Senior Member |
|
|
hi all gurus,
Just want to CREATE new record from LAST record fetched with SQL statement, is there any other simple and/or efficient way to achieve this? please help.
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> ed
Wrote file afiedt.buf
1 with data1 as (select deptno, dname, loc,
2 last_value (deptno)
3 over (order by deptno
4 rows between unbounded preceding
5 and unbounded following) last_dept
6 from dept
7 ),
8 data2 as (select 50 deptno, dname, loc
9 from data1
10 where data1.deptno = last_dept
11 )
12 select deptno, dname, loc
13 from data2
14 union all
15 select deptno, dname, loc
16 from data1
17* order by deptno
SQL> /
DEPTNO DNAME LOC
--------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 OPERATIONS BOSTON
5 rows selected.
regards.
[Updated on: Thu, 06 March 2014 04:04] Report message to a moderator
|
|
|
|
|
Re: create new record from LAST record with SQL [message #609396 is a reply to message #609384] |
Thu, 06 March 2014 05:01 |
oralover2006
Messages: 144 Registered: January 2010 Location: India
|
Senior Member |
|
|
dear Michel Cadot,
thanks very much for your reply & interest to educate us
yes, whole table required.
with your permission ...
SQL> ed
Wrote file afiedt.buf
1 select deptno, dname, loc
2 from dept
3 union all
4 select 50 deptno, dname, loc
5 from (select dname, loc from dept order by deptno desc)
6 where rownum = 1
7* order by deptno
SQL> /
DEPTNO DNAME LOC
--------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 OPERATIONS BOSTON
5 rows selected.
regards.
[Updated on: Thu, 06 March 2014 05:12] Report message to a moderator
|
|
|
|
|
|