Solved

Insert Query in Oracle 8i

Posted on 2002-03-12
8
11,879 Views
Last Modified: 2011-08-18
In Oracle 8i I keep getting ORA-00907 Missing right parenthesis and the cursor brings me to this line:
(Test, Testdata, Testmessage, Hello Testing),
anyone see anything wrong anywhere?

INSERT INTO MAIN
            (
               ID,
               NAME,
               FAMILY,
               SUBJECT,
               MESSAGE,
               MAINDATE,
               SUBJECTID,
               MSGTIME)
               VALUES
               (
               (select id_seq.nextval from dual),
               (Test, Testdata, Testmessage, Hello Testing),
               (select to_char(sysdate, 'mm/dd/yy') from dual),
               (select id_seq.currval from dual),
               (select to_char(sysdate, 'hh:mi a.m.') from dual)
               )
0
Comment
Question by:dylanone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 7

Expert Comment

by:Bigfam5
ID: 6857290
You cannot have a select inside a values list; and you cannot have multiple selects in one insert.

you this as a guid

insert into main
(ID, NAME, FAMILY,..MSGTIME)
(SELECT ID_SEQ.NEXTVAL, 'name','family',..., TO_CHAR(SYSDATE,'HH:MI A.M')
   from dual )
/
0
 
LVL 11

Expert Comment

by:pennnn
ID: 6857293
Try this:
INSERT INTO MAIN
           (
              ID,
              NAME,
              FAMILY,
              SUBJECT,
              MESSAGE,
              MAINDATE,
              SUBJECTID,
              MSGTIME)
              VALUES
              (
              (select id_seq.nextval from dual),
              Test, Testdata, Testmessage, Hello Testing,
              (select to_char(sysdate, 'mm/dd/yy') from dual),
              (select id_seq.currval from dual),
              (select to_char(sysdate, 'hh:mi a.m.') from dual)
              )

Hope that helps!
0
 
LVL 11

Expert Comment

by:pennnn
ID: 6857299
Is there a way to recall my stupid comment?! :)
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 80 total points
ID: 6857344
Trying to use both "nextval" and "currval" in the same SQL statement is something I've never attempted - I'm not sure if that will work or not, but it may.  If it does then this should work for you:
INSERT INTO MAIN
           (
              ID,
              NAME,
              FAMILY,
              SUBJECT,
              MESSAGE,
              MAINDATE,
              SUBJECTID,
              MSGTIME)
              VALUES
              (select id_seq.nextval,
              'Test', 'Testdata', 'Testmessage', 'Hello Testing',
              to_char(sysdate, 'mm/dd/yy'),
              id_seq.currval,
              to_char(sysdate, 'hh:mi a.m.')
              );
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 6857356
Oops!
You can't have both "values" and "select" in an insert statement, just one or the other, and if "select...", then no parenthesis.  Here's how it should be:

INSERT INTO MAIN
          (
             ID,
             NAME,
             FAMILY,
             SUBJECT,
             MESSAGE,
             MAINDATE,
             SUBJECTID,
             MSGTIME)
             select id_seq.nextval,
             'Test', 'Testdata', 'Testmessage', 'Hello Testing',
             to_char(sysdate, 'mm/dd/yy'),
             id_seq.currval,
             to_char(sysdate, 'hh:mi a.m.')
             ;

0
 
LVL 11

Expert Comment

by:pennnn
ID: 6857369
Let me add some more thoughts...
My initial version of the statement will not work, but only because the "Test, Testdata, Testmessage, Hello Testing" values are strings (or at least it seams so), and have to be enclosed in quotes. ((that's why I called myself stupid, because I posted it without looking into the details)
Bigfam5 is right that it would be better to have just one select from dual, but he's not right that you cannot have select into the values list and that you cannot have multiple selects.
So if you add the quotes on my version it will work:
INSERT INTO MAIN
          (
             ID,
             NAME,
             FAMILY,
             SUBJECT,
             MESSAGE,
             MAINDATE,
             SUBJECTID,
             MSGTIME)
             VALUES
             (
             (select id_seq.nextval from dual),
             'Test', 'Testdata', 'Testmessage', 'Hello Testing',
             (select to_char(sysdate, 'mm/dd/yy') from dual),
             (select id_seq.currval from dual),
             (select to_char(sysdate, 'hh:mi a.m.') from dual)
             )

0
 

Author Comment

by:dylanone
ID: 6857740
Actually this one worked for me - after I took out the select statement before the id_seq.nextval

This proves a few things to me as well as others maybe:
1) you can use nextval currval in the same insert statement
2) strings should always be put in ' ' - I always miss that :)
3) you need the values keyword

I'm glad I'm not the only one who had trouble with this :)

Thank you all
0
 
LVL 3

Expert Comment

by:sidcap
ID: 6857751
The simplest way cuold be as follows:

INSERT INTO MAIN
           (
              ID,
              NAME,
              FAMILY,
              SUBJECT,
              MESSAGE,
              MAINDATE,
              SUBJECTID,
              MSGTIME)
              VALUES
              (
              id_seq.nextval,
              'Test', 'Testdata', 'Testmessage', 'Hello Testing',
              to_char(sysdate, 'mm/dd/yy'),
              id_seq.currval,
              to_char(sysdate, 'hh:mi a.m.')
              )

Bye, sidcap.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question