I got this error:
Error report -
ORA-00984: column not allowed here
ORA-06512: at line 14
00984. 00000 - "column not allowed here"
here is the code. I copy and paste the field name (all in cap). The field name should be correct
set serveroutput on
DECLARE
my_creation_dt date;
mysql varchar2(6000) := '';
BEGIN
select creation_dt into my_creation_dt from role_table where security_role = 'admin';
mysql := 'insert into role_grant_table (PERSON_ID, CREATION_DT, SECURITY_ROLE,
SSS_CREATE_DT, UPDATE_WHO, UPDATE_ON) values (1234, SYSDATE,
"ADMIN",
:my_creation_dt,
"myname",
SYSDATE)'; -- line 14, column not allowed here
execute immediate mysql using (my_creation_dt);
END;
Double-quotes are used to enclose identifiers (usually when they have mixed case or punctuation characters). So Oracle is interpreting "ADMIN" and "myname" as identifiers, which in this context the parser takes to be column names. The error is telling you that referencing a column here is not allowed.
Presumably, you intended those to be the string values to be inserted. Use
single-quotes to enclose string literals, i.e. 'ADMIN' and 'myname'.
Related
create or replace procedure Cancel_Reservation(resid in number)
as
Begin
Update Reservation
set Res_cancel = 'yes'
where resid = reserve_id;
end;
Here is a picture of the table I'm working with
My goal is to cancel a reservation by inputting a reserve_id and changing res_cancel to 'yes' from 'no'. My plan is to not delete the reservation.
Here are the errors:
Error(3,1): PL/SQL: SQL Statement ignored
Error(4,5): PL/SQL: ORA-00904: "RES_CANCEL": invalid identifier
Whoever created a table using columns with mixed case ... well, didn't think twice. In Oracle, never do that; causes nothing but problems. I suggest you rename the column with
alter table reservation rename column "Res_cancel" to res_cancel;
Because, as it is, you must reference that table using double quotes and exactly match letter case. So:
Update Reservation
set "Res_cancel" = 'yes' --> this
In my main table having table structure column without double quotes but when in View column with double quotes. While inserting data from view into table then getting error.
Here is the table structure of tbl
create table tbl (ID number(10),
name varchar2(50),
addr varchar2(200));
While View is-
create or replace view t_view as
select "ID", "name", "addr" from tbl;
While inserting data into tbl from t_view -
insert into tbl
select * from t_view;
Then getting error ORA- 00904: "addr": Invalid identifier.
So how to resolve this issue, can i remove the double quotes from creation of view.
Remove all double quotes from everywhere in your code.
If you use them while creating objects, you'll have to use them always, specifying exactly same letter case.
Get rid of those, Oracle is - by default - case insensitive and treats all names as uppercase (but you can reference them any way you want, just don't use double quotes!).
Oracle stores the name of any object in UPPERCASE by default. If you have provided double quotes then only Oracle stores the name of the object as it is.
Double quotes - Case sensitive
No quotes - Case insensitive - Stores the name in UPPERCASE
In your case, While writing the DDL of the table, you have not provided the name of the column in double quotes so your table name and column names are stored in UPPERCASE in the metadata.
You can see the same using the following query
select table_name, column_name from user_tab_columns where table_name = 'TBL';
For giving your answer, create the view either of the following syntaxes:
create or replace view t_view as
select ID, name, addr from tbl; -- no double quotes
create or replace view t_view as
select "ID", "NAME", "ADDR" from tbl; -- UPPERCASE column names in double quotes
See the demo here
Cheers!!
What is it you are trying to accomplish. Your request just doesn't make sense. Your intended statement
insert into tbl select * from t_view;
accomplishes exactly the same thing as
insert into tbl select * from tbl;
It's not that you cann't do this (you can), but it can only cause massive duplicate data issues or (hopefully) unique constraint violations.
Why am I getting invalid month when I test this code? How does PLSQL and XML handle data types?
CURSOR c_DATA_INF is
select * from xmltable ('/' PASSING i_XML COLUMNS READING_DT DATE PATH 'DATE',
Actual NUMBER PATH 'ACTUAL',
Eligible NUMBER PATH 'ELIGIBLE'
);
begin
for d in c_DATA_INF loop
insert into table_name(READING_DT, actual, eligible)
values (to_date('d.READING_DT', 'MM/DD/YYYY'), d.ACTUAL, d.ELIGIBLE);
end loop;
end;
I'm not sure if it's incorrect in my insert statement or in my cursor.
Thanks!
You are passing d.READING_DT as string. within quotes. Please remove the quotes and try
The parameter types are invalid in to_date(DATE, "DATE FORMAT STRING");
Link to Example
Instead of passing 'd.READING_DT', remove the quotes. Pass: d.READING_DT
The error is thrown becasue Oracle does not recognize 'd.READING_DT' as a valid date/ or date string.
I have an insert statement that I am trying to run against an Oracle database. The insert statement is very simple, and I only want to insert a value into one column. The table itself has more than one column, but I am only interested in filling one of the columns with data. The format of my query is similar to the one below:
insert into myTable (col1) Values (val1)
However, this throws the following error:
ORA-00904: "col1": invalid identifier
I've checked to make sure that the column is named correctly, and my only other thought is that something is wrong with my syntax. There are no constraints on the table such as primary keys. Is it possible to only insert values into certain columns when executing an insert statement in Oracle?
Check that you didn't quote the column name on creation of the table. If you did, the column name is stored as you quoted it. For example:
create table table1 (
id number(2)
)
has a different column name to this
create table table2 (
"id" number(2)
)
Oracle by default stores the (unquoted) column names in uppercase. Quoted are stored as is.
You can use a DESC table_name to see how the columns are stored.
The following
select id from table1
select iD from table1
select ID from table1
fetch the records, while only
select "id" from table2
will fetch records.
select id from table2
will throw the ORA-00904 : "ID" : invalid identifier error.
You may have inadvertently done the quoting during creation while using tools as established below:
https://community.oracle.com/thread/2349926
Btw: Yes it is possible to insert records for only one column, as long as the other columns do not have a NOT NULL constraint on them.
Actually, I think you may be double quoting the column in the insert statement (not on table creation), although your example is misleading. I guess this because of your error, which says "col1" is invalid, not "COL1" is invalid. Consider this simple test:
SQL> create table mytable
(
col1 varchar2(10)
)
Table created.
SQL> -- incorrect column name, without double quotes
SQL> insert into mytable(col2) values ('abc')
insert into mytable(col2) values ('abc')
Error at line 9
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 11
ORA-00904: "COL2": invalid identifier
SQL> -- incorrect column name, with double quotes
SQL> insert into mytable("col2") values ('abc')
insert into mytable("col2") values ('abc')
Error at line 12
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 11
ORA-00904: "col2": invalid identifier
SQL> -- correct column name, without double quotes (works)
SQL> insert into mytable(col1) values ('abc')
1 row created.
SQL> -- correct column name, with double quotes (fails)
SQL> insert into mytable("col1") values ('abc')
insert into mytable("col1") values ('abc')
Error at line 18
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 11
ORA-00904: "col1": invalid identifier
The last failed insert attempt is what I think you may be doing:
insert into mytable("col1") values ...
based on the error message:
ORA-00904: "col1": invalid identifier
So the solution would simply be remove the double quoting around the column name in the insert.
It's most probably a syntax error
Desc myTable;
insert into myTable (col1) Values ('val1')
Ensure col1 is a valid column in the table, and you're simply not trying to say 'select the left-most column.
edit: Is it possible to only insert values into certain columns when executing an insert statement in Oracle?
Yes if you want to only insert into certain columns then simply specify it
e.g.
insert into myTable (col1, col2, col6) Values ('val1', 'val2', 'val3');
This will only work if the column itself doesn't have a NOT NULL constraint - in which case it will not allow a value to be enetered (unless again there's a default value).
I read this script that assigns of a data column info into 2 binding variables.
something like this:
EXEC SQL SELECT
var1
into :v.v1:v2
from table
Shouldn't there be a comma in there? Or is this like assigning var1 into v.v1 and also into v2 with the same values?
The above script would give error only. if you want to assign value comma is required for the same.
The syntax would be :- Ex if you want to fetch Empno,Ename,Deptno,salary from
EMPLOYEES.The plsql block would be as given below.
DECLARE
L_EMPNO NUMBER;
L_ENAME VARCHAR2(1000);
L_DEPTNO NUMBER;
L_SALARY NUMBER;
BEGIN
SELECT EMPNO, ENAME, DEPTNO, SALARY
INTO L_EMPNO, L_ENAME, L_DEPTNO, L_SALARY
FROM EMPLOYEES
WHERE EMPNO=100;
END;
This code is a snippet from a PRO*C program, a C program with embedded SQL.
v2 is an indicator variable. See here for info: https://docs.oracle.com/cd/B28359_01/appdev.111/b28427/pc_04dat.htm#i12463
An indicator variable will contain a value that relates to it's associated variable which in this case is v.v1 and is set after the operation in which it is used. In this case, after the select, you can test v2 and based on it's value it will tell you info about v.v1:
From the link above, if v2 equals:
0 - The operation was successful
-1 - A NULL was returned, inserted, or updated.
-2 - Output to a character host variable from a "long" type was truncated, but the original column length cannot be determined.
>0 - The result of a SELECT or FETCH into a character host variable was truncated. In this case, if the host variable is a multibyte character variable, the indicator value is the original column length in characters. If the host variable is not a multibye character variable, then the indicator length is the original column length in bytes.
I would suggest using it's other form, which would make things clear for the person that will maintain this after you (at least do that person a favor and comment this when you get your head around it). Always code for the person that will maintain after you. Don't you wish the person before you did that?!:
EXEC SQL SELECT
var1
into :v.v1 INDICATOR :v2
from table