Update data in an Oracle view - oracle

I just started developing on Oracle.
Is there a way to populate data in a view? I found nothing concrete on the web. My SQL Developer says:
SQL Error: ORA-01747: invalid user.table.column, table.column, or column specification
01747. 00000 - "invalid user.table.column, table.column, or column specification"
*Cause:
*Action:
when I want to update the view with a simple update query:
update admin.table1 SET COLUMN1 = '50', SET COLUMN1 = '50'
WHERE COLUMN3 = 'Test'

Why twice SET COLUMN1 = '50'?
Check Syntax, you need to separate columns with comma without the SET keyword, you use SET only once once:
UPDATE TABLE1 SET col1= 'X', col2='Y' WHERE ...

You can't update data in views, only tables.

Related

Oracle - ORA-00907: missing right parenthesis in query generated by Odata query generator

this is the query generated by an Odata Sql query generator and I am on Oracle 12c
SELECT ID
FROM MY_TABLE
WHERE (
NAME LIKE 'abc' = true
)
;
and the error it generates is
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 14
Any ideas on how to fix the query ?
Thanks in advance
I know nothing about "Odata Sql query generator", but - if you want to fix this query, then it would be
select id from my_table where name like 'abc'
On the other hand, that's same as
select id from my_table where name = 'abc'
so perhaps you actually meant to use wildcards:
select id from my_table where name like '%abc%'

EFCore error:- ORA-00904: "m"."Id": invalid identifier

I am working with an application using asp.net core 2.2 and efcore database first approach with Oracle database. I am using Oracle.EntityFrameworkCore (2.19.60) nuget package, successfully mapped db model, but when I try to fetch data from DBContext , getting error
ORA-00904: "m"."Id": invalid identifier
Oracle Database version: Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production
code:
var fetched = await myDatabaseContext.MyTableVersions.ToListAsync();
LinQ is generating following query :
SELECT "m"."Id", "m"."MAJORVERSION" FROM "MyTableVersions" "m"
Since It's not a correct syntax for PL/Sql query so getting error ORA-00904: "m"."Id": invalid identifier.
Is there any way to fix this error? Thanks.
I have searched on the web and found
Bug 30352492 - EFCORE: ORA-00904: INVALID IDENTIFIER
but that issue is related to schema.
The query is perfectly valid (db<>fiddle here), assuming your table looks something like
CREATE TABLE "MyTableVersions"
("Id" NUMBER,
MAJORVERSION NUMBER)
However, I suspect your table looks like
CREATE TABLE "MyTableVersions"
(ID NUMBER,
MAJORVERSION NUMBER)
I don't know what the class looks like that you're trying to fetch into, but I suspect it has a field named Id. If you can change the name of that field to ID (in other words, so that its capitalization matches the capitalization of the related database column) you might find it works then.
Double quotes are something you should avoid in Oracle world.
Your query:
SELECT "m"."Id", "m"."MAJORVERSION" FROM "MyTableVersions" "m"
means that column name is exactly Id (capital I followed by d). Only if that's really so, you should use double quotes. Otherwise, simply remove them:
SELECT m.id, m.MAJORVERSION FROM MyTableVersions m
The same goes for the table name - if it was created using mixed case (and you can't do that without double quotes), you'll have to use double quotes and exactly same letter case always. Otherwise, don't use them.
Oracle is case-insensitive regarding object and column names and are UPPERCASE by default:
SQL> create table test (id number);
Table created.
SQL> desc test
Name Null? Type
----------------------------------------- -------- -----------------
ID NUMBER
SQL> select table_name, column_name
2 from user_tab_columns
3 where table_name = 'TEST';
TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------
TEST ID
SQL> insert into test (id) values (1);
1 row created.
SQL>
But, if you use mixed case with double quotes, then use them always:
SQL> create table "teST" ("Id" number);
Table created.
SQL> insert into test (id) values (1);
insert into test (id) values (1)
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> insert into "test" (id) values (1);
insert into "test" (id) values (1)
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> insert into "teST" (id) values (1);
insert into "teST" (id) values (1)
*
ERROR at line 1:
ORA-00904: "ID": invalid identifier
SQL> insert into "teST" ("Id") values (1);
1 row created.
SQL>
So: first make sure what table and column names really are, then use them appropriately.
To avoid problems with case-sensitivity, add the option to eliminate EF to add quotes to the generated queries. For instance, if you are using Devart Oracle provider, this is done in the following way:
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpDbContextOptions>(options =>
{
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.Workarounds.DisableQuoting = true;
...
}
}
If you are using official provider - just inherit from DbCommandInterceptor (do quotes replacement with empty character in dbCommand in ...Executing methods), add this interceptor to DbContextOptionsBuilder instance.

oracle cannot insert values into a nested table field

I have the sample CUSTOMERS table.
I exported the values from table as INSERT script.
I took one row, modified the value from PK and re-executed the insert.
Insert into oe.customers (CUSTOMER_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
CUST_ADDRESS,
PHONE_NUMBERS,
NLS_LANGUAGE,
NLS_TERRITORY,
CREDIT_LIMIT,
CUST_EMAIL,
ACCOUNT_MGR_ID,
CUST_GEO_LOCATION,
DATE_OF_BIRTH,
MARITAL_STATUS,
GENDER,
INCOME_LEVEL,
CREDIT_CARDS)
values ( oe.customer_seq.nextval,
'Donald',
'Hunter',
OE.CUST_ADDRESS_TYP('5122 Sinclair Ln','21206','Baltimore','MD','US'),
OE.PHONE_LIST_TYP('+1 410 123 4795'),
'us',
'AMERICA',
2600,
'Donald.Hunter#CHACHALACA.EXAMPLE.COM',
145,
MDSYS.SDO_GEOMETRY(2001,8307,MDSYS.SDO_POINT_TYPE(-76.545732,39.322775,NULL),NULL,NULL),
to_date('20-JAN-60','DD-MON-RR'),
'married',
'M',
'G: 130,000 - 149,999',
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
and I have the following error message:
Error at Command Line : 32 Column : 29 Error report - SQL Error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
which refers to line:
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
The definition of types are:
create or replace type typ_cr_card as object
( card_type VARCHAR2(25)
, card_num NUMBER);
create or replace type typ_cr_card_nst as table of typ_cr_card;
Can someone tell me, please, what is wrong with this insert line as it is the one provided by SQL DEVELOPER?
NOTE: Also, I tried to use a procedure which inserts values in this table and the error refers to TYP_CR_CARD_NST datatype.

Leave column out of Oracle insert statement

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).

SELECT a table from oracle data dictionary

I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.

Resources