Solved

Insert Query in Oracle 8i

Posted on 2002-03-12
8
11,877 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
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
Technology Partners: 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!

 
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

Technology Partners: 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

Suggested Solutions

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

679 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