Home > Back-end >  what does the error "ORA-00933:" mean in my situation
what does the error "ORA-00933:" mean in my situation

Time:09-22

I am just a student and I am trying to get a table working but have tried everything I could only to end up with an error.

ORA-00933: SQL command not properly ended

Could anyone please help me understand what I'm doing wrong?

CREATE TABLE student
(
    idnumber VARCHAR2(8),
    firstname VARCHAR2(20),
    lastname VARCHAR2(20),
    dateofbirth DATE,
    address VARCHAR2(20),
    email VARCHAR2(20),
    programme VARCHAR2(5),
    points number(3),

    PRIMARY KEY (idnumber)
);

INSERT INTO student 
VALUES ('D1234567', 'Student ONE', 'TWO THREE', DATE '2000-05-10',
        'Thetown, the address', '[email protected]', 'DT228', '380'),
       ('D2345678', 'Student TWO', 'FOUR FIVE', DATE '2000-04-10',
        'Thetown, the address', '[email protected]', 'DT228', '280');

SELECT 
    firstname, lastname
FROM 
    student
WHERE 
    points > 300;

CodePudding user response:

That is not valid insert syntax. You can only insert one row at a time that way, separating by comma will not work. To do multi-row inserts, use the syntax:

INSERT ALL
   INTO tbl (col1, col2) VALUES ('value', 'another value')
   INTO tbl (col1, col2) VALUES ('value', 'another value')
   INTO tbl (col1, col2) VALUES ('value', 'another value')
SELECT 1 FROM DUAL;

The select 1 from dual is required for the subquery needing a select statement. It's no different than doing multiple insert statements, so you might as well just break this into multiple statements unless you are doing thousands of inserts at once.

CodePudding user response:

Run each of the statements one by one:

Create your table

CREATE TABLE student
(
idnumber VARCHAR2(8),
firstname VARCHAR2(20),
lastname VARCHAR2(20),
dateofbirth DATE,
address VARCHAR2(20),
email VARCHAR2(20),
programme VARCHAR2(5),
points number(3),
PRIMARY KEY (idnumber)
);

Insert the 1st row

INSERT INTO student VALUES
(  
'D1234567',
'Student ONE',
'TWO THREE',
DATE '2000-05-10',
'Thetown,thedress',
'[email protected]',
'DT228',
'380'
);

Insert the 2nd row

INSERT INTO student VALUES 
(
'D2345678',
'Student TWO',
'FOUR FIVE',
DATE '2000-04-10',
'Thetown,the adress',
'[email protected]',
'DT228',
'280'
);

Run the select

SELECT firstname, lastname
FROM student
WHERE points > 300;

Examples:

  1. https://dbfiddle.uk/?rdbms=oracle_18&fiddle=d01055a94dce5ed7919a3d26c8a9f73c
  2. https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=d01055a94dce5ed7919a3d26c8a9f73c

CodePudding user response:

semicolon (;) is the problem, remove semicolon from last statement and you can get rid of this error, your code's last statement will become

SELECT firstname, lastname
FROM student
WHERE points > 300

Hope this will work

  • Related