i cant create a table because name is invalid [duplicate] - sql

This question already has answers here:
ORA-00904: : invalid identifier Oracle sql [closed]
(2 answers)
Closed 1 year ago.
Im trying to create a table with the name " Order " and these datatypes (Note: i dont have a table named Order and I tried to create other tables and it worked ) and the names are:
create table Order(
Onum Number(8) PRIMARY KEY,
Odate Date,
Otime Time(7),
Delivered_on_time char(1));
and the error was:
invalid table name
so I tried to name it Ordeer and try again and it gave me this error:
ORA-00907: missing right parenthesis
Otime Time(7),
Delivered_on_time char(1)
);
what to do? help please

First, you can't call the table order because order is a reserved word. (There's a tricky way to get around this, but it's a bad idea to do so.)
Second, the DATE type also includes the time, so you don't need to have separate date and time columns.
CREATE TABLE orders (
onum NUMBER(8) PRIMARY KEY,
odate DATE,
delivered_on_time CHAR(1)
);

Related

error: You have an error in your SQL syntax when creating table in mysql [duplicate]

This question already has an answer here:
Create a table with a space in the name
(1 answer)
Closed 9 months ago.
I know what a syntax error is but cannot find any error when creating this table:
my code
CREATE TABLE branch supplier (
branch_id INT,
supplier_name VARCHAR(40),
supply_type VARCHAR(40),
PRIMARY KEY (branch_id, supplier_name),
FOREIGN KEY (branch_id) REFERENCES branch(branch_id) ON DELETE CASCADE
);
and the error I'm getting
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'supplier ( branch_id INT, supplier_name VARCHAR(40), supply_type ' at line 1
It is not allowed to use table names with space(s) unless you use `. This means you need to change this to...
CREATE TABLE `branch supplier`...
or to something without space, as example
CREATE TABLE branch_supplier...

Is there a way to declare Status and Level in Oracle? [duplicate]

This question already has answers here:
getting error while creating table as ORA-00904: : invalid identifier in oracle database sql
(2 answers)
Closed 9 months ago.
I usually use SQL Server so declare variables in Oracle seem different a little.
Here is the table Im trying to create:
CREATE TABLE EMPLOYEE(
EmpNo char(10) CONSTRAINT PK_EmpNo PRIMARY KEY,
EmpName varchar2(30),
Birthday DATE not null,
DeptNo number,
MgrNo varchar2(30) not null,
StartDate DATE not null,
Salary number(7,2) not null,
Level number CONSTRAINT Level_ck check (Level > 0 AND Level < 8) not null,
Status number CONSTRAINT Status_ck check (Status >= 0 AND Status <= 2) not null,
Note varchar2(4000));
This is the error:
I think I declare Level and Status wrong because when I remove them out of the Table, the table can be created.Any suggestion?
LEVEL is a reserved word that cannot be used as an identifier. Every database has them; the complete list of reserved words for Oracle is here: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Oracle-SQL-Reserved-Words.html#GUID-55C49D1E-BE08-4C50-A9DD-8593EB925612
STATUS is not a reserved word, and you should be able to create a column with that name.
Also note that table and column names in Oracle are not case-sensitive by default, so using camelCase isn't really appropriate (it will only be visible in your CREATE TABLE DDL command). A more standard naming convention is to use underscores to separate components of a label, such as START_DATE or DEPT_NR or TABLE_A.

Oracle Live SQL : ORA-00907: missing right parenthesis -

I saw many others opened a question related to same problem however none of the answer addresses to the problem I have.
I am running below code on Oracle Live SQL and getting the error
ORA-00907: missing right parenthesis
create table CUST_ORDER (
ord_id NUMBER(38) CONSTRAINT cusordtb_ordid_pk PRIMARY KEY,
cust_id NUMBER(38) NOT NULL,
order_date DATE(12) NOT NULL
);
I am pretty sure I am not missing any parenthesis. Does anyone have the solution?
The Oracle date datatype does not take a length.
Consider:
create table CUST_ORDER (
ord_id NUMBER(38) CONSTRAINT cusordtb_ordid_pk PRIMARY KEY,
cust_id NUMBER(38) NOT NULL,
order_date DATE NOT NULL
);
Date doenot take a length. So you need not specify the same

creating a table with Foreign key in it gives error ORA-00904: : invalid identifier in oracle 10g [duplicate]

This question already has answers here:
Creating table via SQL Command Line, invalid identifier
(3 answers)
Closed 3 years ago.
Image of the code with table, query and error
I have oracle 10g installed on my computer. I have created a table in it named STUDENT and this STUDENT table has a primary key called RNO and now I want to create another table named FEE and make this RNO key into a foreign key in FEE table with the following query:
CREATE TABLE FEE ( RNO NUMBER(2), Amount number(20) Not Null, Date varchar2(10) Not Null, Receipt Number(10) Not Null, CONSTRAINT FEEFK FOREIGN KEY (RNO) REFERENCES STUDENT (RNO));
Now I have done all I could to correct it but just can't seem to find any problem or error with this query above. The Query gives the following error in Oracle 10g:
ORA-00904: : invalid identifier
Column name can't be DATE, it is reserved for datatype. Rename it to, say, CDATE.
SQL> CREATE TABLE student (rno NUMBER (2) PRIMARY KEY);
Table created.
SQL> CREATE TABLE FEE
2 (
3 RNO NUMBER (2),
4 Amount NUMBER (20) NOT NULL,
5 cDate VARCHAR2 (10) NOT NULL,
6 Receipt NUMBER (10) NOT NULL,
7 CONSTRAINT FEEFK FOREIGN KEY (RNO) REFERENCES STUDENT (RNO)
8 );
Table created.
SQL>
Use double qoutes "Date" or rename your column Date as some other name like DateColumn as Date is a reserved name fpr date types in oracle

Creating table in Oracle yields a "Missing right parenthesis" error [duplicate]

This question already has answers here:
How to create id with AUTO_INCREMENT on Oracle?
(18 answers)
Closed 8 years ago.
I am trying to create a table, but keep getting the following error message: Warning: oci_execute(): ORA-00907: missing right parenthesis in ... on line 14
The following is the code that deals with this issue:
$stid = oci_parse($conn, 'CREATE TABLE tags (
id INT NOT NULL auto_increment,
PRIMARY KEY(id),
name VARCHAR2(64) NOT NULL)')
or die(oci_error($conn));
oci_execute($stid) or die(oci_error($conn));
Line 14 is oci_execute($stid) or die(oci_error($conn));.
I am new to Oracle and don't understand this error. I used Google and found numerous posts on StackOverflow too, but none of those answers were able to solve this problem and properly create a new table.
What am I doing wrong here?
I believe your used to creating table in MySQL.
Oracle don't have an auto_increment as MySQL.
$stid = oci_parse($conn, 'CREATE TABLE tags (
id INT NOT NULL,
name VARCHAR2(64) NOT NULL),
PRIMARY KEY(id)')
Oracle used object Sequence to create an auto_increment value.
Example on how to create sequence assuming you have the right permission.
CREATE SEQUENCE "CCAD"."AUTH_GROUP_SQ"
MINVALUE 1
MAXVALUE 999999999999
INCREMENT BY 1
START WITH 91
CACHE 20
NOORDER NOCYCLE;
Together with Insert trigger.
create or replace TRIGGER "AUTH_GROUP_TR"
BEFORE INSERT ON "AUTH_GROUP"
FOR EACH ROW
WHEN (new."ID" IS NULL)
BEGIN
SELECT "AUTH_GROUP_SQ".nextval
INTO :new."ID" FROM dual;
END;