was doing a school project but then came across this error when I was trying to create a table.
CREATE TABLE SSV_PASSENGERS ( PASS_ID# CHAR(6),
PASS_FNAME VARCHAR(15),
PASS_LNAME VARCHAR(15),
PASS_ADDRESS VARCHAR(30),
PASS_NATION VARCHAR(20),
PASS_DOB DATE(yyyy-mm-dd),
PASS SATRATE VARCHAR(2),
PASS_CAB# CHAR(4),
PASS_CABFARE NUMBER(6,2),
PASS_TOTALEX NUMBER(7,2),
PASS_MEDINFO VARCHAR(30),
PASS_DIET VARCHAR(30),
PASS_EMNAME VARCHAR(20),
PASS_EMPHONE# CHAR(10),
PASS_ALTID CHAR(5),
CONSTRAINT SSV_PASSENGERS_PK PRIMARY KEY (PASS_ID#) )
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
Could anyone tell me what's wrong with the script?
The error message ORA-00907: missing right parenthesis indicates a syntax error. Sometimes it means we do actually have a unpaired left bracket. But often it means the compiler has come across an unexpected character, which might be a hanging comma or an unexpected identifier, that the compiler interprets as an attempt to start a new statement without properly closing the current CREATE TABLE statement.
This is not intuitive. However, now you know what the error message really means, the next time you get it you should think to yourself: ah, I have made a typo in my code, I must pore over it until I find my bloomer.
In this case I think the problem is this: PASS_DOB DATE(yyyy-mm-dd).
Oracle stores dates in a standard structure: format masks are just for displaying as or casting from strings.
The way to declare DATE columns is simply: PASS_DOB DATE.
Also, you're missing an underscore from one of your column names: it should be PASS_SATRATE VARCHAR(2).
As far as I see, the parentheses in that statement are balanced. Is it possible the error is reported regarding some different statement?
Oracle allows # as part of column identifiers, but discourages it.
Oracle Database Online Documentation, 10g Release 2 (10.2) / Administration: Schema Object Names and Qualifiers says:
Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Database links can also contain periods (.) and "at" signs (#). Oracle strongly discourages you from using $ and # in nonquoted identifiers.
(emphasis mine)
Interesting that the same paragraph in the Oracle 12c docs does not include the same warning.
Is it possible that you are executing that create table statement in some environment that treats # as a comment character (like shell or Ruby code) and ignores all the text following the #?
I found a few problems.
DATE (PASS_DOB DATE(yyyy-mm-dd) - you just need DATE
PASS SATRATE VARCHAR(2) - you need an underscore
VARCHAR vs VARCHAR2 - VARCHAR is there to support ANSI - always use VARCHAR2
VARCHAR Datatype 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.
(Docs)
The working code:
create table SSV_PASSENGERS (
PASS_ID# char(6),
PASS_FNAME varchar2(15),
PASS_LNAME varchar2(15),
PASS_ADDRESS varchar2(30),
PASS_NATION varchar2(20),
PASS_DOB date,
PASS_SATRATE varchar(2),
PASS_CAB# char(4),
PASS_CABFARE number(6,2),
PASS_TOTALEX number(7,2),
PASS_MEDINFO varchar(30),
PASS_DIET varchar(30),
PASS_EMNAME varchar(20),
PASS_EMPHONE# char(10),
PASS_ALTID char(5),
constraint SSV_PASSENGERS_PK primary key ( PASS_ID# )
);
And since you're using and tagged SQL Developer, we try to show you where your problems are, look for the pink squiggles near the offending bad SQL.
Related
I am creating a simple table but there is an error:
[Error] Execution (23: 29): ORA-00907: missing right parenthesis
I am not missing any parenthesis. This errors refers to the line with
DEPARTMENTURL NCHAR(10 BYTE),
I was able to create the table removing this line, I'm not sure what is the issue. I am using TOAD and I've restarted it.
Please see code below:
CREATE TABLE HR.DEPARTMENT(
DEPARTMENTID NUMBER(10),
NAME NUMBER(10),
ABBREVIATION NUMBER(10),
URL VARCHAR2(200 BYTE),
DEPARTMENTURL NCHAR(10 BYTE),
BANNERDEPTCODE VARCHAR2(50 BYTE),
UPAYURL TIMESTAMP
);
The length of NCHAR and NVARCHAR2 columns can only be specified in characters, never in bytes, and you can only specify the length (in characters), you can't even use the word CHAR in the length specification.
https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1825
To understand the error message, put yourself in the parser's shoes (and remember that parsers, optimizers etc. are not "intelligent" beings). The parser sees NCHAR, so it knows that it should see the length next. It sees the opening parenthesis, the number 10, and then another token that is not the closing parenthesis, which is the only valid "next token" at that point. Whence the error message.
I want column names with symbols
i.e. {ImportId:week}
I tried placing a " on either side of each symbol and string
i.e. "{""ImportId"":""week""}" like this`
CREATE TABLE EXAMPLE
(
"{""ImportId"":""week""}" VARCHAR2(100)
)
but I get the error:
ORA-03001: unimplemented feature
A pair of double-quotes bounds an identifier. A column can have only one identifier. So just strip out all the unnecessary double-quotes and make the whole piece a single identifier:
CREATE TABLE EXAMPLE
(
"{ImportId:week}" VARCHAR(100)
)
Incidentally, are you really sure you want to do this. Using unapproved symbols in column names is really not necessary and it's not idiomatic. The long term consequence of this naming convention will most likely be a continual low-grade annoyance experienced by everybody who has to work with this table.
I'm getting an
ORA-00907 error, missing right parenthesis
when attempting to create a table w MySQL.
I have looked extensively on the web but found nothing that could help me here..
Here is my CREATE TABLE statement:
CREATE TABLE station
(
nomStation varchar2(255),
capacite number(15) NOT NULL,
lieu varchar2(255) NOT NULL,
region ENUM('Quebec', 'Ontario', 'NewBrunswick', 'NovaScotia'),
tarif number(10) DEFAULT 0,
CONSTRAINT station_nomStation_pk PRIMARY KEY(nomStation)
);
In my experience, "ORA-00907 error, missing right parenthesis" is usually triggered by a wrong number of commas, like adding an extra comma after your final column or constraint.
However, in your case some googling seems to indicate that Oracle doesn't support the ENUM syntax you're using. Instead, you should use a CHECK, like described in this blog post.
I am running following query in SQL*Plus
CREATE TABLE tbl_audit_trail (
id NUMBER(11) NOT NULL,
old_value varchar2(255) NOT NULL,
new_value varchar2(255) NOT NULL,
action varchar2(20) CHARACTER SET latin1 NOT NULL,
model varchar2(255) CHARACTER SET latin1 NOT NULL,
field varchar2(64) CHARACTER SET latin1 NOT NULL,
stamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
user_id NUMBER(11) NOT NULL,
model_id varchar2(65) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (id),
KEY idx_action (action)
);
I am getting following error:
action varchar2(20) CHARACTER SET latin1 NOT NULL,
*
ERROR at line 5:
ORA-00907: missing right parenthesis
Can you suggest what am I missing?
The simple answer is that, unlike MySQL, character sets can't be defined at column (or table) level. Latin1 is not a valid Oracle character set either.
Character sets are consistent across the database and will have been specified when you created the database. You can find your character by querying NLS_DATABASE_PARAMETERS,
select value
from nls_database_parameters
where parameter = 'NLS_CHARACTERSET'
The full list of possible character sets is available for 11g r2 and for 9i or you can query V$NLS_VALID_VALUES.
It is possible to use the ALTER SESSION statement to set the NLS_LANGUAGE or the NLS_TERRITORY, but unfortunately you can't do this for the character set. I believe this is because altering the language changes how Oracle would display the stored data whereas changing the character set would change how Oracle stores the data.
When displaying the data, you can of course specify the required character set in whichever client you're using.
Character set migration is not a trivial task and should not be done lightly.
On a slight side note why are you trying to use Latin 1? It would be more normal to set up a new database in something like UTF-8 (otherwise known as AL32UTF8 - don't use UTF8) or UTF-16 so that you can store multi-byte data effectively. Even if you don't need it now it's wise to attempt - no guarantees in life - to future proof your database with no need to migrate in the future.
If you're looking to specify differing character sets for different columns in a database then the better option would be to determine if this requirement is really necessary and to try to remove it. If it is definitely necessary1 then your best bet might be to use a character set that is a superset of all potential character sets. Then, have some sort of check constraint that limits the column to specific hex values. I would not recommend doing this at all, the potential for mistakes to creep in is massive and it's extremely complex. Furthermore, different character sets render different hex values differently. This, in turn, means that you need to enforce that a column is rendered in a specific character, which is impossible as it falls outside the scope of the database.
1. I'd be interested to know the situation
According to provided DDL statement it's some need to use 2 character sets. The implementation of this functionality in Oracle is different from MySQL and done with n* data types like nvarchar2, nchar... Latin1 is similar to some Western European character set that might be default. So you able to define for example "Latin1" (WE**) and some Unicode (UTF8..).
The NVARCHAR2 datatype was introduced by Oracle for databases that want to use Unicode for some columns while keeping another character set for the rest of the database (which uses VARCHAR2). The NVARCHAR2 is a Unicode-only datatype.
The reason you want to use NVARCHAR2 might be that your DB uses a non-Unicode character and you still want to be able to store Unicode data for some columns.
Columns in your example would be able to store the same data, however the byte storage will be different.
I haven't used Oracle for a while so I'm a bit rusty.
This is my table:
create table calendar(
username VARCHAR2(12),
content VARCHAR2(100),
dateContent DATE,
type CHAR(3) CHECK (type IN ('PUB', 'PRV')));
But when I try to insert a value like this:
insert into calendar
(username, content, dateContent, type)
values
(chris, assignment due, to_date('01-OCT-2010 13:00','DD-MON-YYYY HH24:MI'), PUB)
/
I am getting:
ORA-00984: column not allowed here
pointing to the type column at the end. I have a feeling I'm not getting something right with the DATE field as I've never really used it.
What have I done wrong?
You need to put quotes round the varchar2 values
Something like
insert into calendar(username,
content,
dateContent,
type)
values('chris',
'assignment due',
to_date('01-OCT-2010 13:00','DD-MON-YYYY HH24:MI'),
'PUB');
Could it be because type is a Oracle reserved word ?
Looks like this is not an issue. Read the comment by APC.
I'm not deleting this answer because I find the comment useful.