oracle 8i question
I reformat the data here. Basically, I tried to output the data from table1 into table2 but not sure how to write it in oracle 8i. I am running Aqua Studio but the database backend is oracle.
Thanks alot!!!
Table1:
Name Prods Cus_id
-----------------------
Mark Rice 87311870
Judy Rice 87364239
-----------------------
Tom Coffee 87404026
Tom Apple 87404026
Tom Milk 87404026
Tom Source 87404026
-----------------------
Hunt Chips 87570092
-----------------------
Table2:
Name Prod1 Prod2 Prod3 Prod4 Cus_id
-----------------------------------------------------
Mark Rice 87311870
-----------------------------------------------------
Judy Rice 87364239
-----------------------------------------------------
Tom Coffee Apple Milk Source 87404026
-----------------------------------------------------
Hunt Chips 开发者_StackOverflow中文版 87570092
-----------------------------------------------------
If your intent is to transfer data from one table to another, use the insert..select
command:
insert into table2 (col1, col2) select col1, col2 from table1;
Beyond that, it's just a matter of morphing the data to the desired format. SO has a plethora of questions on turning rows into columns.
In my opinion, this is usually a bad idea. I'm all for presenting data like this since your users may desire it but that's something that should be done in the presentation layer, not in the database.
Creating a table of this style (non third normal form) is usually enough for our DBAs to either reject the change outright or, at a minimum, bring you in for a stern taking to, which may include some ridicule and questioning of your parentage depending on how much sleep they had the night before :-)
精彩评论