I have a column name in one of my tables called: 3RD_DIAG_CODE - VARCHAR2 (10 Byte)
When I try to run a query, it gives me the following error highlighting 3RD_DIAG_CODE.
ORA-00923: FROM keyword not found where expected.
How can I bring this field in without it throwing an error every time I bring this field in?
If you are using column names that start with a number then you need to use double quotes. For example:
create table foo (
"3RD_DIAG_CODE" varchar2(10 byte) --make sure you use uppercase for variable name
);
insert into foo values ('abc');
insert into foo values ('def');
insert into foo values ('ghi');
insert into foo values ('jkl');
insert into foo values ('mno');
commit;
select * from foo;
3RD_DIAG_C
----------
abc
def
ghi
jkl
mno
select 3RD_DIAG_CODE from foo;
RD_DIAG_CODE
------------
3
3
3
3
3
select "3RD_DIAG_CODE" from foo;
3RD_DIAG_C
----------
abc
def
ghi
jkl
mno
Edit: As for the error message itself, you are probably (as BQ wrote) missing a comma from the select clause.
Check your specification, but in SQL Server we would have to enclose that column name in square brackets: [3RD_DIAG_CODE]
You probably have two columns listed without a comma between them.
create table t (id number primary key, 3d varchar2(30))
Error at Command Line:1 Column:39
Error report:
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
create table t (id number primary key, "3d" varchar2(30));
table T created.
desc t
Name Null Type
---- -------- ------------
ID NOT NULL NUMBER
3d VARCHAR2(30)
> select id, 3d from t --[as #gsiem mentions: THIS IS BAD]
ID 3D
---------------------- --------
> select id, "3d" from t
ID 3d
---------------------- ------------------------------
> select id, [3d] from t
Error starting at line 7 in command:
select id, [3d] from t
Error at Command Line:7 Column:11
Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
> select id 3d from t
Error starting at line 8 in command:
select id 3d from t
Error at Command Line:8 Column:10
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Related
I have a Data
create or replace NONEDITIONABLE type TST_OBJ force
as table of varchar2(128)
And a table APPS that has a column 'Tst' of TST_OBJ type, as follows:
Column_Name
Type of data
Name
varchar
Tst
TST_OBJ
Offs
number
The issue comes when I try to SELECT and Group By the results as shown next:
select Tst, Offs from APPS group by Tst;
I'm getting error ORA-00932:
ORA-00932: inconsistent datatypes: expected - got TST_OBJ
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Is it possible that Group By does not work with this Type of Data or is there a way to achieve it?
Documentation says:
Restrictions on the GROUP BY Clause
This clause is subject to the following restrictions:
You cannot specify LOB columns, nested tables, or varrays as part of expr.
The expressions can be of any form except scalar subquery expressions.
If the group_by_clause references any object type columns, then the query will not be parallelized.
I guess bold part answers your question.
SQL> create or replace type TST_OBJ force
2 as table of varchar2(128);
3 /
Type created.
SQL> create table apps
2 (name varchar2(20),
3 tst tst_obj, --> here it is
4 offs number)
5 nested table tst store as tst_obj_tab;
Table created.
SQL> insert into apps values ('Little', tst_obj('A'), 1);
1 row created.
SQL> insert into apps values ('Foot' , tst_obj('A', 'B', 'C'), 2);
1 row created.
Queries:
SQL> select tst, offs
2 from apps;
TST OFFS
---------------------------------------- ----------
TST_OBJ('A') 1
TST_OBJ('A', 'B', 'C') 2
SQL> select tst, offs, count(*)
2 from apps
3 group by tst, offs;
group by tst, offs
*
ERROR at line 3:
ORA-00932: inconsistent datatypes: expected - got SCOTT.TST_OBJ
SQL>
I created sequence for manager first.
CREATE SEQUENCE manager_seq
START WITH 200
MAXVALUE 299
CYCLE
CACHE 10;
Then I inserted some values using .NEXTVAL
INSERT INTO manager
VALUES (manager_seq.NEXTVAL,'')
When I try to query with where statement it says ORA-00936: missing expression
select * from manager where number = 201;
Why it isn't working with sequnce numbers how can I use them?
Column name can't be number, that's a reserved word - reserved for datatype. For example:
SQL> create table manager (id number,
2 number number); --> this
number number)
*
ERROR at line 2:
ORA-00904: : invalid identifier
Therefore, post table description (so that we could suggest what to do) or use valid query.
If you use a reserved word as an identifier then you need to quote it everywhere you use it. So, if you have the table:
CREATE TABLE manager (
"NUMBER" NUMBER,
something VARCHAR2(10)
);
Then you insert rows:
INSERT INTO manager VALUES (manager_seq.NEXTVAL,'');
INSERT INTO manager VALUES (manager_seq.NEXTVAL,'');
Then, if you use an unquoted identifier:
select * from manager where number = 201;
You get the error:
ORA-00936: missing expression
But, if you use a quoted identifier with the correct case then you can query the table:
select * from manager where "NUMBER" = 201;
Which outputs:
NUMBER
SOMETHING
201
null
Note: In Oracle, '' and NULL are identical.
db<>fiddle here
I have created new table by:
CREATE TABLE DIFF_ODATE_PERIOD AS
select test_3.odate - test_3.max_period from test_3;
And it gave me column name: ?column?
And when I am trying to change the name it gives me error:
ALTER TABLE DIFF_ODATE_PERIOD
RENAME COLUMN ?column? TO test;
ERROR: syntax error at or near "?" LINE 71: RENAME COLUMN ?column?
TO test;
Can I define the name while creating or after?
You would need to alias that column directly in the create table ... as select statement:
create table diff_odate_period as
select odate - max_period as test from test_3;
I am trying to use range partition on a table for a column of type number. However, Oracle 12c throws an error saying it is an invalid data-type. I don't understand why/what is invalid in the command.
create table partition_tester (
some_column number not null,
another_column varchar2(10),
partition by range(some_column) interval(10)
);
I am connecting to the database using SQL developer. It seems to have issue with the range function. On executing above script it throws:
Error report -
ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Any help is appreciated.
remove the comma after " another_column varchar2(10)," and specify at least one partition.
create table partition_tester (
some_column number not null,
another_column varchar2(10))
partition by range(some_column) interval(10)
(
partition p0 values less than (10)
)
This is my table...it has Number as a column name
CREATE TABLE pwc_it_service (
"SEQ" NUMBER,
"NUMBER" VARCHAR2(10),
"CI_NAME" VARCHAR2(200),
"CI_CLASS" VARCHAR2(200),
"OWNED_BY_PRIMARY" VARCHAR2(200),
"OWNED_BY_SECONDARY" VARCHAR2(200),
"MANAGING_TERRITORY" VARCHAR2(200),
"LOS" VARCHAR2(100),
"BUSINESS_UNIT" VARCHAR2(100),
"IMPORTED" DATE,
"LAST_UPDATED" DATE
)
When i run my ctl file, i get the below error:
Record 1: Rejected - Error on table PWC_IT_SERVICE, column NUMBER.
ORA-01747: invalid user.table.column, table.column, or column specification
how can i insert the values without changing column name
It was really a bad idea naming the column "NUMBER" (yes, double quotes and uppercase included). The fact that you can do it doesn't mean that you should do it. Now you have to deal with it and use the same syntax all the time - double quotes and uppercase. Have a look:
SQL> create table test ("NUMBER" varchar2(10));
Table created.
SQL> insert into test (number) values ('A');
insert into test (number) values ('A')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword
SQL> insert into test ("number") values ('A');
insert into test ("number") values ('A')
*
ERROR at line 1:
ORA-00904: "number": invalid identifier
SQL> insert into test ("NUMBER") values ('A');
1 row created.
SQL>
Do the same in the control file.
load data
infile *
replace
into table test
(
"NUMBER" terminated by whitespace
)
begindata
Little
Foot
How it works?
SQL> desc test
Name Null? Type
----------------------------- -------- --------------------
NUMBER VARCHAR2(10)
SQL> $sqlldr scott/tiger#xe control=test02.ctl log=test02.log
SQL*Loader: Release 11.2.0.2.0 - Production on Sri Svi 23 22:23:07 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
Commit point reached - logical record count 2
SQL> select * From test;
NUMBER
----------
Little
Foot
SQL>
Works fine.
However, I'd suggest you to rename that unforunate column. Get rid of double quotes, now and forever.