Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11886
  • Last Modified:

Insert Query in Oracle 8i

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
dylanone
Asked:
dylanone
1 Solution
 
Bigfam5Commented:
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
 
pennnnCommented:
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
 
pennnnCommented:
Is there a way to recall my stupid comment?! :)
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
Mark GeerlingsDatabase AdministratorCommented:
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
 
Mark GeerlingsDatabase AdministratorCommented:
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
 
pennnnCommented:
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
 
dylanoneAuthor Commented:
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
 
sidcapCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now