| Help with insert [message #645551] |
Tue, 08 December 2015 10:19  |
 |
sant_new1
Messages: 46 Registered: June 2014
|
Member |
|
|
Hi friends,
Below insert fails with ora-00907 when I use order by in the sub query... Table tab1 has 28 columns to be inserted so I did not post
the entire script..
Insert into tab1 (sign_no,...,s_type,...)
select
's' || cs.content_no,
...,
(select s.sign_type from s_det s
where s.curr_type = (select min(v.curr_type) from v_det v order by v.content_no)) S_TYPE,
...
from content_sales cs;
ERROR at line 16:
ORA-00907: missing right parenthesis
Below are few records from v_det table. For each content_no, we need to compare with min(v.curr_type) and s.curr_type
in the above where clause.
SQL> select * from v_det;
CONTENT_NO CURR_TYPE
-------------------- --------------------
J23 235541231
J23 235541234
A35 6712343
A34 6712343
Please help.. Thank you all so much.
|
|
|
|
|
|
| Re: Help with insert [message #645553 is a reply to message #645552] |
Tue, 08 December 2015 11:32   |
 |
sant_new1
Messages: 46 Registered: June 2014
|
Member |
|
|
If I remove order by and use just '(select min(v.curr_type) from v_det v) , there are no errors when I run the insert but then tab1.stype is all null values because the inner select query returns multiple rows for min(v.curr_type). Here is the business logic we need to use for inserting into tab1..
most of the values for columns in tab1 will be from table CS.
Logic For tab1.s_type = " s_det.sign_type where s.curr_type = v.curr_type" ( If there are multiple v.curr_type for each v.content_no, then take min(v.curr_type)"
Below are the tables with just the columns needed for this insert of s_type value.
SQL> select * from v_det;
CONTENT_NO CURR_TYPE
-------------------- -------------
A34 6712343
J23 235541231
J23 235541234
A35 6712343
SQL> select * from s_det;
SIGN_TYPE CURR_TYPE
-------------------- --------------------
TKT1 235541231
TKT9 6712343
SQL> select * from content_sales;
CONTENT_NO
--------------------
A34
A35
J23
I removed the insert of other columns in tab1 for ease..
Insert into tab1 (sign_no,s_type)
select
's' || cs.content_no,
(select s.sign_type from s_det s
where s.curr_type = (select min(v.curr_type) from v_det v)) S_TYPE
from content_sales cs;
Result of tab1 should be
SQL> select * from tab1;
SIGN_NO S_TYPE
-------------------- --------------------
sA34 TKT9
sA35 TKT9
sJ23 TKT1
Thanks for all your help..Appreciate it a lot.
[Updated on: Tue, 08 December 2015 11:33] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|