开发者

Query using Oracle8i

How do I output the data from table1 into table2 using Oracle8I? I am using Aqua Data Studio 7.5 and the backend is Oracl8i.

Table1:

Name              Prods Cus_id
Mark              Rice  87311870
Judy              Rice  87364239
Judy              Bowl  87364239
Tom               Apple 87404026
Tom               Milk  87404026
Tom               Coffee    87404026
Smith             Peanut    87500245
Smith             Tea   87500245
Ortiz             Egg   87569724
Ortiz             Cheese    87569724
Ortiz             Pizza 87569724
Ortiz             Pepper    87569724
Hunt              Chips 87570092

Table2:

Name        Prod1       Prod2       Prod3       Prod4   Cus_id
Mark        Rice                            87311870
Judy        Rice        Bowl                    87364239
Tom Apple   Milk        Coffee          87404026
Smith       Peanut      Tea                 87500245
Ortiz       Egg    开发者_运维知识库 Cheese      Pizza       Pepper  87569724
Hunt        Chips                           87570092


See this example:

set feedback off;
set pagesize 0;

create table foo (a number, b varchar(10), c varchar(10));

insert into foo values ( 15, 'abc','def' );
insert into foo values (998, 'max','min' );
insert into foo values (  7, 'bla','bla' );
insert into foo values (632, 'now','then');

insert into foo 
  (a,b,c)
  (select                   AA,
                            BB,
                            CC 
  from
    (select max(a) +1       AA      from foo), 
    (select 'new'           BB,
            'old'           CC      from dual));

select * from foo where a = (select max(a) from foo);

drop table foo;

Source: Oracle SQL: Insert with Select

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜