Oracle sql - ORA-00907 and my incorrect syntax - oracle

I cannot figure out the syntax issue with the following code. When I run it, I get error
ORA-00907: missing right parenthesis
Can anyone point out my flaw please?
CREATE OR REPLACE VIEW LATESTAPPLICATIONS AS
SELECT *
FROM application_history
WHERE entry_time IN
(SELECT entry_time
FROM application_history
GROUP BY application_number; )
ORDER BY entry_number;​
Here is the table definition for application_history. I ideally want to only view application numbers with the latest time-stamps.
CREATE TABLE "APPLICATION_HISTORY"
( "ENTRY_NUMBER" NUMBER(28,0),
"APPLICATION_NUMBER" NUMBER(16,0) CONSTRAINT "APP_NUM_NN" NOT NULL ENABLE,
"ACTIVE" CHAR(1) DEFAULT 0 CONSTRAINT "ACTIVE_NN" NOT NULL ENABLE,
"STATUS" VARCHAR2(40) DEFAULT 'APPLICATION ENTERED' CONSTRAINT "STATUS_NN" NOT NULL ENABLE,
"DATE_APPROVED" DATE,
"DATE_APPLIED" DATE DEFAULT SYSDATE CONSTRAINT "DATE_APPLIED_NN" NOT NULL ENABLE,
"ENTRY_TIME" TIMESTAMP (6) DEFAULT SYSDATE,
CONSTRAINT "ENTRY_NUM_PK" PRIMARY KEY ("ENTRY_NUMBER")
USING INDEX ENABLE
)

You have a semi-colon at the last but 1 line. GROUP BY application_number; ) Remove it and you should be fine.
Semi-colon acts as the query terminator in Oracle, as you had placed it before the ) Oracle could not find it.

Related

Why is Oracle giving me a missing right parentheses error when I am not missing a right parenthesis

I am trying to create a script in Oracle and keep getting an error saying I am missing the right parentheses - when I am not. please help.
create table driver
(
d_id INT(1),
d_name VARCHAR(45),
d_contact CHAR(10),
constraint driver_d_id_PK Primary Key(d_id)
);
ORA-00907: missing right parenthesis
create table limo
(
l_id INT(1),
l_callsign VARCHAR(45),
l_type VARCHAR(45),
constraint limo_l_id_PK Primary key(l_id)
);
ORA-00907: missing right parenthesis
create table clients
(
c_id INT(1),
c_name VARCHAR(45),
c_contact CHAR(10),
c_methpmt VARCHAR(25),
constraint clients_c_id_PK Primary key(c_id)
);
ORA-00907: missing right parenthesis
create table qualify
(
q_id INT(1),
q_l_id INT(1),
q_d_id INT(1),
constraint qualify_q_id_PK Primary key(q_id),
constraint qualify_q_l_id_FK Foreign key(q_l_id) references LIMO(l_id),
constraint qualify_q_d_id_FK Foreign key(q_d_id) references DRIVER(d_id)
);
ORA-00907: missing right parenthesis
create table rental
(
r_id INT(1),
r_date DATE,
r_fee INT(4),
r_c_id INT(1),
r_q_id INT(1),
constraint rental_r_id_PK Primary key(r_id),
constraint rental_r_c_id_FK Foreign key(r_c_id) references CLIENTS(c_id),
constraint rental_r_q_id_FK Foreign key(r_q_id) references QUALIFY(q_id)
);
ORA-00907: missing right parenthesis
The error is misleading. You have a parenthesis where it doesn't belong and Oracle gets confused. There must be no parentheses after INT.
If you want a numeric with a specific length, use NUMBER instead.
(And in Oracle we use VARCHAR2 instead of VARCHAR, and we don't use CHAR either.)
CREATE TABLE driver
(
d_id NUMBER(1),
d_name VARCHAR2(45),
d_contact VARCHAR2(10),
CONSTRAINT driver_d_id_PK PRIMARY KEY (d_id)
);
NUMBER(1) allows single digits only, i.e. numbers from -9 to +9.

Unusable partition Oracle / datastage

I am facing an issue with my datastage job. I have to fill a table ttperiodeas in Oracle from a .csv file. The SQL query in Oracle connector is shown in this screenshot:
Oracle connector
And here is the oracle script
CREATE TABLE TTPERIODEAS
(
CDPARTITION VARCHAR2(5 BYTE) NOT NULL ENABLE,
CDCOMPAGNIE NUMBER(4,0) NOT NULL ENABLE,
CDAPPLI NUMBER(4,0) NOT NULL ENABLE,
NUCONTRA CHAR(15 BYTE) NOT NULL ENABLE,
DTDEBAS NUMBER(8,0) NOT NULL ENABLE,
DTFINAS NUMBER(8,0) NOT NULL ENABLE,
TAUXAS NUMBER(8,5) NOT NULL ENABLE,
CONSTRAINT PK_TTPERIODEAS
PRIMARY KEY (CDPARTITION, CDCOMPAGNIE, CDAPPLI, NUCONTRA, DTDEBAS)
)
PARTITION BY LIST(CDPARTITION)
(PARTITION P_PERIODEAS_13Q VALUES ('13Q'));
When running the job, I get the following message error and the table is not filled.:
The index 'USINODSD0.SYS_C00249007' its partition is unusable
Please I need help thanks
The index is global (i.e. not partitioned) because there is no using index local at the end of the definition. This is also true for the PK index shown above. (I'm assuming they are two different things, because by default the DDL above would create an index named PK_TTPERIODEAS, so I'm not sure what SYS_C00249007 is.) If you can drop and rebuild them as local indexes (i.e. partitioned to match the table) then truncating or dropping a partition will no longer invalidate indexes.
For example, you could rebuild the primary key as:
alter table ttperiodeas
drop primary key;
alter table ttperiodeas
add constraint pk_ttperiodeas primary key (cdpartition,cdcompagnie,cdappli,nucontra,dtdebas)
using index local;
I don't know how SYS_C00249007 is defined, but you could use something similar.
The create table command might be something like:
create table ttperiodeas
( cdpartition varchar2(5 byte) not null
, cdcompagnie number(4,0) not null
, cdappli number(4,0) not null
, nucontra varchar2(15 byte) not null
, dtdebas number(8,0) not null
, dtfinas number(8,0) not null
, tauxas number(8,5) not null
, constraint pk_ttperiodeas
primary key (cdpartition,cdcompagnie,cdappli,nucontra,dtdebas)
using index local
)
partition by list(cdpartition)
( partition p_periodeas_13q values ('13Q') );
Alternatively, you could add the update global indexes clause when dropping the partition:
alter table demo_temp drop partition p_periodeas_14q update global indexes;
(By the way, NUCONTRA should probably be a standard VARCHAR2 and not CHAR, which is intended for cross-platform compatibility and ANSI completeness, and in practice just wastes space and creates bugs.)
the message says that the index for the given partition is unusable: so you could try to rebuild the correponding index partition by the use of
create index [index_name] rebuild partition [partition_name]
(with the fitting values for [index_name] and [partition_nme].
Before you do that you should check the status of the index partitions in user_indexes - since your error message looks not like Oracle error messages usually do.
But since the index is global as William Robertson pointed out, this is not applicable for the given situation.

sql script not running

Here is a code snippet of a sql script which is giving me error,I have to generate a sequence on the primary_key of the table without using triggers in oracle:
CREATE SEQUENCE t1_seq START WITH 1 INCREMENT BY 1;
DROP TABLE CPR_SOURCE_SYSTEM_METADATA;
CREATE TABLE CPR_SOURCE_SYSTEM_METADATA
(
SYSTEM_ID NUMBER(4) NOT NULL t1_seq.nextval,
SYSTEM_NAME VARCHAR2(200),
DATE_FORMAT VARCHAR2(200),
CREATED_BY VARCHAR2(200),
MODIFIED_BY VARCHAR2(200),
CREATED_ON NUMBER(20),
MODIFIED_ON NUMBER(20),
IS_DELETED VARCHAR2(1),
CONSTRAINT "CPR_SOURCE_SYSTEM_PK" PRIMARY KEY ("SYSTEM_ID")
);
It is giving me the below error :
DROP TABLE CPR_SOURCE_SYSTEM_METADATA
* ERROR at line 1: ORA-00942: table or view does not exist
SYSTEM_ID NUMBER(4) NOT NULL t1_seq.nextval,
* ERROR at line 3: ORA-00907: missing right parenthesis
Not able to figure out the error,can anyone help??
SYSTEM_ID NUMBER(4) NOT NULL t1_seq.nextval,
The t1_seq.nextval segment is not valid - you cannot specify an auto-incrementing column like that.
The SQL parser is expecting to see:
SYSTEM_ID NUMBER(4) NOT NULL,
and throws the exception as the comma is not where it expects.
In Oracle 12c you can use an identity column but in earlier versions you will either need to:
Use the sequence in the SQL insert statement;
Use a trigger to insert the correct sequence value; or
Create a stored procedure to handle inserts and manage the sequence through that (disallowing direct inserts that could bypass this).

Missing parentheses in CREATE TABLE instruction

CREATE TABLE MAJEST_PROD_2015(
PRODUCT_ID CHAR(10) NOT NULL,
DESCRIPTION_PROD CHAR(30),
SEW_DATE DATE,
HARVEST_DATE DATE,
QUANTITY INT,
PROD_RATING INT(1),
PRIMARY KEY (PRODUCT_ID)
);
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Oracle is not MySQL so there is no INT(1) type:
CREATE TABLE MAJEST_PROD_2015(
PRODUCT_ID CHAR(10) NOT NULL,
DESCRIPTION_PROD CHAR(30),
SEW_DATE DATE,
HARVEST_DATE DATE,
QUANTITY INT,
PROD_RATING INT, -- here
PRIMARY KEY (PRODUCT_ID)
);
SqlFiddleDemo
If you don't need constant size of string, consider using VARCHAR2(30).
EDIT:
but i need those values to be between 1-5
So add check constraint:
CONSTRAINT chk_PROD_RATING CHECK (PROD_RATING BETWEEN 1 AND 5),
SqlFiddleDemo2
As already noted INT does not take a length constraint in Oracle - instead you could use NUMBER(1,0) which would restrict it to a single digit (-9 .. +9) and then you can further restrict it using a CHECK constraint.
CHAR(n) will also right pad the value with space (CHR(32)) characters so that it always contains the maximum number of characters. If you did not intend this then you should be using VARCHAR2(n) instead.
You also do not need a NOT NULL constraint on a column that is the PRIMARY KEY.
CREATE TABLE MAJEST_PROD_2015(
PRODUCT_ID VARCHAR2(10) CONSTRAINT MAJEST_PROD_2015__PROD_ID__PK PRIMARY KEY,
DESCRIPTION_PROD VARCHAR2(30),
SEW_DATE DATE,
HARVEST_DATE DATE,
QUANTITY INT,
PROD_RATING NUMBER(1,0) CONSTRAINT MAJEST_PROD_2015__PROD_RAT__CK CHECK ( PROD_RATING BETWEEN 1 AND 5 )
);
(also, should it be SEW_DATE or SOW_DATE? Since the next line talks about harvest then I would have thought "sow" was more apt.)

Insert query showing an error in oracle10g

I created a table in oracle10g using following query......
CREATE TABLE "EMPLOYEESTASKS"
( "EMPLOYEEID" NUMBER,
"TASKDATE" VARCHAR2(40),
"STATUS" NUMBER,
"CUSTOMERID" NUMBER,
"ADDRESS" VARCHAR2(400) NOT NULL ENABLE,
"TASKTIME" VARCHAR2(40) NOT NULL ENABLE,
"VISITDATE" VARCHAR2(40),
"VISITTIME" VARCHAR2(40),
CONSTRAINT "EMPLOYEESTASKS_PK" PRIMARY KEY ("EMPLOYEEID", "TASKDATE", "TASKTIME") ENABLE,
CONSTRAINT "EMPLOYEESTASKS_FK" FOREIGN KEY ("EMPLOYEEID")
REFERENCES "EMPLOYEES" ("ID") ON DELETE CASCADE ENABLE
)
Table was created successfully... but the problem is while iam trying to insert a row into the table it is showing the error
ORA-01722: invalid number
The query i used is ,
insert into employeestasks values(12305,'30-11-2011','09:00',0,45602,'Sarpavaram Junction ,kakinada',null,null)
What is that invalid number..??
It look like your columns in the table are ordered employeeid, taskdate, status, and you're trying to insert '09:00' into status, which is a number. This is no good. You need to use the same order of columns or specify which value is for which column.
Also, you really like capslock, huh?

Resources