SQL keeps throwing "missing left parenthesis" - sql

I don't understand what I am doing here but I keep getting a "missing left parenthesis" error in the following SQL code. Can anyone please tell me what I am doing wrong? Newbie here.
CREATE TABLE AGENT_INFO
(AgentID SMALLINT PRIMARY KEY, AgentName VARCHAR, PhoneNumber VARCHAR);

The VARCHAR data type needs a size (and should probably be VARCHAR2 in Oracle and SMALLINT is an alias for NUMBER(38)):
CREATE TABLE AGENT_INFO(
AgentID SMALLINT PRIMARY KEY,
AgentName VARCHAR2(10),
PhoneNumber VARCHAR2(10)
);
If you want a string column that can accept text without specifying a maximum size then use CLOB:
CREATE TABLE AGENT_INFO(
AgentID NUMBER(38) PRIMARY KEY,
AgentName CLOB,
PhoneNumber CLOB
);
db<>fiddle here

varchar datatype requires size:
SQL> CREATE TABLE AGENT_INFO
2 (AgentID SMALLINT PRIMARY KEY,
3 AgentName VARCHAR2(20),
4 PhoneNumber VARCHAR2(20));
Table created.
SQL>
(Note that Oracle recommends varchar2 instead of varchar.)

Related

Creating a table and getting error as ora 00907 missing right parenthesis

I am trying to create a table and getting error as ora 00907 missing right parenthesis. What went wrong?
This is my query:
CREATE TABLE College (
ID int,
NAME varchar(255),
Branch var char(255) NOT NULL,
Percentage int,
Address varchar,
City varchar(255),
PRIMARY KEY (ID)
);
You have multiple errors. Presumably, you want something like this:
CREATE TABLE Colleges (
CollegeID int PRIMARY KEY,
Name varchar2(255),
Branch varchar2(255) NOT NULL,
Percentage int,
Address varchar2(255),
City varchar2(255)
);
Notes:
Your syntax problem is the space in var char.
Oracle recommends varchar2() over varchar.
You should always include a length in the definition.
You can inline the primary key definition.
I prefer that the primary key include the entity name, rather than the generic id.
Similarly, I prefer that the table be in the plural, because it contains multiple colleges.
A column called percentage with a type of int is suspicious.

ORA-00904: : invalid identifier - very simple table

Complete noob, only just figured what a sequence is.
CREATE SEQUENCE volunteer_id_seq
START WITH 1;
CREATE TABLE volunteer (
volunteer_id VARCHAR(20) PRIMARY KEY,
title VARCHAR2(5),
);
Returns 4 0.00 CREATE TABLE volunteer_t ( volunteer_id VARCHAR(20) PRIMA ORA-00904: : invalid identifier -
As Gordon Linoff states in his comment, you have a comma after you declare the second column in your table. Instead, it should look like this:
CREATE TABLE volunteer (
volunteer_id VARCHAR(20) PRIMARY KEY,
title VARCHAR2(5)
);

Error while creating TABLE in database

I am using oracle 10g ex to learn so here is my code
CREATE TABLE MINE
(
NAME VARCHAR(10),
ID INT(3) PRIMARY KEY
);
and my error is
ORA-00907: missing right parenthesis.
but I don't where I missed the right parenthesis. There is any other chance or something I have to know to solve this issue.
INT does not need a size - it is an alias for NUMBER(38).
CREATE TABLE MINE
(
NAME VARCHAR(10),
ID INT PRIMARY KEY
);
However, what you probably want is to use VARCHAR2 and NUMBER types:
CREATE TABLE MINE
(
NAME VARCHAR2(10),
ID NUMBER(3,0) PRIMARY KEY
);
And now is the time to get into good habits - you probably also want to name your constraints:
CREATE TABLE MINE
(
NAME VARCHAR2(10),
ID NUMBER(3,0) CONSTRAINT mine__id__pk PRIMARY KEY
);
The int datatype doesn't take a size argument:
CREATE TABLE MINE
(
NAME VARCHAR(10),
ID INT PRIMARY KEY -- Here!
);
create table Mine(name varchar(10),Id number(20) PRIMARY KEY);

create table in Oracle BD but gives error

CREATE TABLE employees (
id INT NOT NULL auto_increment PRIMARY KEY (ID),
first_name VARCHAR(20) DEFAULT NULL,
last_name VARCHAR(20) DEFAULT NULL,
salary INT DEFAULT NULL);
I think this is correct query to create table in Oracle database.. but it gives the following error:
ORA-00907: missing right parenthesis
How to correct the statement?
You can validate your SQL using formatting tools such as http://www.dpriver.com/pp/sqlformat.htm
auto_increment seems like a proprietary MySQL extension, so it's not valid for Oracle.
also, "id int not null auto_increment primary key (id)" does not need the last "(id)"
Using Oracle, you shoud try something like this
CREATE SEQUENCE seq;
CREATE TABLE employees
(
id INTEGER NOT NULL PRIMARY KEY,
first_name VARCHAR2(20) DEFAULT NULL,
last_name VARCHAR2(20) DEFAULT NULL,
salary INTEGER DEFAULT NULL
);
INSERT INTO employees
VALUES (seq.NEXTVAL,
'name',
'last name',
1);
Sometimes, SQL is fancy, because even having a standard (ANSI), most DBMS vendors add their proprietary extensions to the SQL creating their own languages, so it's rare the situation where you can port one SQL from one DB into another without any changes.
Also, it's a pretty useless error message. It could at least say which position. (also, there's no missing parenthesis, but an unexpected token)
EDITED : New feature 12c
CREATE TABLE employees(
id NUMBER GENERATED ALWAYS AS IDENTITY,
first_name VARCHAR2(30)
etc.
);
Why would you do default null?
The VARCHAR datatype is synonymous with the VARCHAR2 datatype. To avoid possible changes in behavior, always use the VARCHAR2 datatype to store variable-length character strings.
Replace
id INT NOT NULL auto_increment PRIMARY KEY (ID),
with
id INT NOT NULL auto_increment PRIMARY KEY,
this is more efficient
CREATE TABLE EMPLOYEES_T(
ID NUMBER,
FIRST_NAME VARCHAR2(20) DEFAULT NULL,
LAST_NAME VARCHAR2(20) DEFAULT NULL,
SALARY INTEGER DEFAULT NULL,
CONSTRAINT PK_EMPLOYEES_T PRIMARY KEY(ID)
);

Error at line 1: ORA-00907: missing right parenthesis

I believe I have the right syntax for SQL plus command, I have tried different ways to do it but I am getting the same error message. I don't know why i am getting this "missing right parenthesis error" any help will be appreciated thank you in advance.
here is my code:
create table PUBLISHERS (
NAME varchar2(50) primary key,
address varchar2(50), phone integer(10)
);
The integer data type does not use a length qualifier. integer is equivalent to number(38,0).
SQL> ed
Wrote file afiedt.buf
1 create table PUBLISHERS (
2 NAME varchar2(50) primary key,
3 address varchar2(50),
4 phone integer
5* )
SQL> /
Table created.
If you want to limit the size, use a number
SQL> ed
Wrote file afiedt.buf
1 create table PUBLISHERS (
2 NAME varchar2(50) primary key,
3 address varchar2(50),
4 phone number(10)
5* )
SQL> /
Table created.
Since you are never going to do numeric operations on a phone number, however, while it is generally likely that you will perform string manipulation on it to format phone numbers for display, it would generally make sense to store a phone number as a character string rather than as a number. You can add a CHECK constraint that ensures the format is correct.
SQL> ed
Wrote file afiedt.buf
1 create table PUBLISHERS (
2 NAME varchar2(50) primary key,
3 address varchar2(50),
4 phone varchar2(10)
5* )
SQL> /
Table created.
INTEGER is not a Oracle Built-In data type. It is just a ANSI format that is supported in oracle. The oracle representation of INTEGER is NUMBER (38). Use NUMBER datatype instead.
CREATE TABLE publishers(
name VARCHAR2(50) PRIMARY KEY,
address VARCHAR2(50),
phone NUMBER(10)
);
create table doctor_details(doctor_id number(10),
username varchar2(30) not null,
password varchar2(30) not null,
name varchar2(30) not null,
father_name varchar2(30) not null,
gender varchar2(6) not null check(gender in('male','female)),
email varchar2(50) not null,
contact_no number(10) not null,
qualification varchar2(50) not null,
specialization varchar2(5) not null,
date_of_birth date not null,
date_of_joining date not null,
primary key(doctor_id))
error is right parenthesis missing