Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2003, 01:11 PM
Jorj Jorj is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 Jorj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Need help with complicated INSERT query!

Hi guys,

We're having trouble inserting into a table, using data from another table. We are using an Object-Relational DBS. The new table includes a REF, and two nested tables. the latest query that I have tried is:

INSERT INTO medical_visit_tab(mv_id, visit_date, charge, visit_coord_role_cui, problem, solution, person)
(SELECT ID, VISIT_DATE, CHARGE, VISIT_COORDINATOR_ROLE_CUI
FROM oraheal.medical_visit
WHERE p_chronic_cui is NULL
AND s_therapy_cui is NULL),
medicalProb_tableType((SELECT medicalProbType(p_problem_cui,p_acute_cui)
FROM oraheal.medical_visit
WHERE p_chronic_cui is NULL
AND s_therapy_cui is NULL),
medicalSolu_tableType((SELECT medicalSolutionType(s_carer_id, s_drug_cui, s_drug_cost, s_drug_targetchemical_cui1, s_drug_targetchemical_cui2)
FROM oraheal.medical_visit
WHERE s_therapy_cui is NULL
AND p_chronic_cui is NULL),
(SELECT TREAT(REF(a) as REF patientType)
FROM patient_tab a, oraheal.medical_visit o
WHERE a.name = o.name));

The error this gives in Oracle 9i is:

ERROR at line 5:
ORA-00933: SQL command not properly ended

line 5 is -->> AND s_therapy_cui is NULL),

The first SELECT is for 4 simple attributes, the second and third SELECT for the Nested Tables (called problem and solution), and the last SELECT is for the REF (person).

Is it wrong to use more than one SELECT statement when inserting into a new table? Or is the syntax that we are using at the moment wrong?

If anyone has any clue could you pleaaase reply.....have been stuck on this for hours!

Cheers

Reply With Quote
  #2  
Old October 16th, 2003, 04:48 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 22 h 25 m 53 sec
Reputation Power: 19
That syntax looks completely wrong to me, now it's possible they changed it between 8 and 9 but I doubt it, I am used to seeing something like this:

PHP Code:
 insert into tab (col1col2col3)
 
select a.col1b.col2c.col3
   from table1 a
table2 btable3 c
where a
.col1 b.col1
    
and a.col1 c.col1 


Maybe if you provide the table structures and an explanation of what you are trying to do it would help.

The only tip I can offer is that the select statement has to run on it's own, start with that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Need help with complicated INSERT query!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway