Confusing error about missing left parenthesis in SQL statement - sql

SQLPLUS says I have missing left parenthesis with this statement in my sql script..
CREATE TABLE people(
id INT NOT NULL PRIMARY KEY,
name VARCHAR2
);
I had uploaded my script with sftp, could that have played around with the script?

VARCHAR2 is a type that needs a maximum size/length. Try something like...
varchar2(50)
Your missing left parenthesis is the parenthesis that surrounds the size.
CREATE TABLE people(
id INT NOT NULL PRIMARY KEY,
name VARCHAR2(50)
);

You need to specify a size for the VARCHAR2 data type.
E.g. VARCHAR2(30)
SQL*Plus is looking for the brackets around the VARCHAR2 size definition.

You are getting this error because you didn't specify the character with datatype varchar2.
Try something like this:
CREATE TABLE people(
id INT NOT NULL PRIMARY KEY,
name VARCHAR2(20) );

You need to specify the size of Varchar2.
For example:- Name Varchar2(50)
Note:- The maximum size of the Varchar2 is 4000.

Related

Using like for numeric in a constraint

I am creating a table which is like this:
CREATE TABLE Peeps
(
Name VARCHAR(255) NOT NULL,
PhoneNum BIGINT NOT NULL,
CONSTRAINT PhoneNum_Check CHECK (PhoneNum LIKE '08%')
)
Every phone number has to start with 08. However when I tried insert there's an error because LIKE can't be used for numeric (or that's what my friend said). The alternative would be using VARCHAR for PhoneNum, but this is an assignment and we have to use numeric for the phone number.
If a phone number can start with a 0 then you need to use a string:
CREATE TABLE Peeps (
Name VARCHAR(255) NOT NULL,
PhoneNum VARCHAR(255) NOT NULL,
CONSTRAINT PhoneNum_Check CHECK (PhoneNum LIKE '08%')
);
Although you can use LIKE on a number, it is highly not recommended. What happens is that the number is converted to a string. However, that string will never start with a 0 -- well, at least never when the value is greater than 1.

Missing right parenthesis Oracle Issue

I 'm using Oracle Application Express Edition 4.0.2.00.09
While creating the table I'm getting error "ORA-00907: missing right parenthesis", I have checked previously asked question on this however could not make it through.
Create table NewOne (
PersonId Int(10),
Hire_Date varchar(255),
Tenure number(255),
Review varchar(255),
Next_Day varchar(255),
Last_day varchar(255)
)
Make the changes below
Change int to number
Change number(255) to number(38) , as 38 is the max allowed for number
It should work fine.
Check out the db fiddle link - https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=d1fecc3e55708115d2326fdeec34243d
You can't specify a length for the INT subtype, it is what it is. You should use the NUMBER type instead.
Once you fix that you'll find that your tenure column is specified with 255 digits, I don't think that's close to reality and will also error.
You should be using VARCHAR2 not VARCHAR on Oracle.
int is a perfectly acceptable Oracle type. However, int(10) is not. Number itself is limited to a max of 38. And Oracle recommend varchar2() instead of varchar(). So I would recommend:
Create table NewOne (
PersonId Int,
Hire_Date varchar2(255),
Tenure number,
Review varchar2(255),
Next_Day varchar2(255),
Last_day varchar2(255)
);
Here is a db<>fiddle

Getting ORA-00904: : invalid identifier in oracle application express

I want to create this simple table in oracle application express but i keep getting the error
ORA-00904: : invalid identifier
and I have no idea why.
CREATE TABLE ArtWork (
ArtWorkId NUMBER (6,0) CONSTRAINT aw_pk PRIMARY KEY,
Name VARCHAR2 (20),
Desc VARCHAR2 (25)
);
desc is a reserved word (it is used to to specifiy the sort direction, for example in an order by clause).
You need to either surround it with double quotes, or better yet change your column name to something that does not clash with a language keyword, so you don't need to worry about it later on:
CREATE TABLE ArtWork (
ArtWorkId NUMBER (6,0) CONSTRAINT aw_pk PRIMARY KEY,
Name VARCHAR2 (20),
Description VARCHAR2 (25)
);
Reserved keywords shouldn't be used as identifiers as they are for implicit usages. Hence change desc to some other name like description

Missing Right Parenthesis in SQL

I'm new to learning SQL. When I create this table, it has an Asterix (*) under the first parenthesis of the "(dbClassID)" and says "missing right parenthesis"
Does anyone know why it does that and how I can fix it?
CREATE TABLE vod_classification (
dbClassId CHAR(4) NOT NULL,
dbDescription VARCHAR2(100)
CONSTRAINT vod_classification_PK PRIMARY KEY (dbClassId)
);
CONSTRAINT is part of table creation and need to be comma delimited as other column:
CREATE TABLE zz_classification (
dbClassId CHAR(4) NOT NULL,
dbDescription VARCHAR2(100),
CONSTRAINT vod_classification_PK PRIMARY KEY( dbClassId)
);
Tables contain columns and constraints
you are missing , here try this VARCHAR2(100),
For a single-column constraint, it's neater to define it inline as part of the column:
create table vod_classification
( dbclassid varchar2(4) not null constraint vod_classification_pk primary key
, dbdescription varchar2(100) not null constraint vod_classification_uk unique
);
I have corrected the CHAR column to the standard string type which is VARCHAR2 in Oracle.
(PK columns will be not null automatically, but I've left it in for completeness and in case you later create table as select.)
When using the "Create" code, you must use a comma in the line where you define each column of the table. Except the last column. You can read the oracle sql syntax link as follows: https://docs.oracle.com/cd/E11882_01/server.112/e41085/sqlqr01001.htm#SQLQR110

while creating table i got missing right parenthesis error in sql plus

I have tried to create below table.and getting above error,please correct the code.
CREATE TABLE HostelInfo
(
Hostelid NUM(20),
Hostelname VARCHAR2(10)
);
/
NUM(20) is an invalid data type; try NUMBER(20) instead:
CREATE TABLE HostelInfo
(
Hostelid NUMBER(20),
Hostelname VARCHAR2(10)
);
The correct data type is NUMBER:
CREATE TABLE HostelInfo
(
Hostelid NUMBER(20),
Hostelname VARCHAR2(10)
);
The SQL Fiddle is here.