In Oracle SQL , how do you select columns by ordinal position? - sql

I'm trying to study this database , and I want to look for column data based on its position , like so:
select * from V$RESERVED_WORDS where COLUMNS.FIRST like '%'
However, this doesn't seem to work. I get this error:
select * from V$RESERVED_WORDS where COLUMNS.FIRST like "%"
Error at Command Line:10 Column:57
Error report:
SQL Error: ORA-00904: "%": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I'm using Oracle SQL . Any tips appreciated.

You cant use ordinal, but you need to specify column name. Your query:
SELECT * FROM V$RESERVED_WORDS
WHERE KEYWORD LIKE '%';

Related

Contains condition over clob in sybase db

Can someone help me with the syntax of CONTAINS in Sybase, I have tried below two, and both didn't work :
Query1:
select * from test where column_1 CONTAINS('Set');
Exception:
[Code: 102, SQL State: 37000] Incorrect syntax near 'CONTAINS'.
Query2:
select * from test where CONTAINS(column_1, 'Set');
Exception:
[Code: 102, SQL State: 37000] Incorrect syntax near ')'.
Please help
you have to remove where from your statement and that will be like below
select * from test CONTAINS(column_1, 'Set');
more about contains in sybase read documentation

Invalid table name while bulk insert in oracle

I am trying to insert values into Oracle table using Bulk Insert query but getting below error
ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:
Error at Line: 4 Column: 5
Here is my query
BULK INSERT TEST1.STUDENT
FROM 'C:\Users\Alan\Desktop\STUDENT.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
);
Why is this error coming. Is there some issue with query? Please help. Thanks
Update
I changed by file format to CSV and wrote below query
LOAD DATA
INFILE 'C:\Users\Alan\Desktop\STUDENT.csv'
INTO TABLE TEST1.STUDENT
FIELDS TERMINATED BY ","
(ID,
NAME);
but above query is giving
ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
Error at Line: 16 Column: 2
What is wrong in the above syntax?
This is not Oracle syntax at all. If you need to load data from file to table please use either SQLoader or External table
Some documentation about External table and SQLoader
If you're using SQLDeveloper you can also use import facility.
Please also have a look on that thread.
[EDIT}
LOAD DATA
INFILE 'C:\Users\Alan\Desktop\STUDENT.csv'
INTO TABLE TEST1.STUDENT
FIELDS TERMINATED BY ","
(ID,
NAME);
This is not a query. This is content of control file. Please save it to file load.csv then run cmd (or shell if yuo're on Linux) and type:
sqlldr user/pass control=load.ctl
Some examples you can find here.

SQL Error: 904, SQLState: 42000 ORA-00904: : invalid identifier

Can below scenario of duplicate alias lead to an error when executed from JDBC or hibernate:
SQL Error: 904, SQLState: 42000 ORA-00904: : invalid identifier
select * From table_master VW
LEFT OUTER JOIN TABLE(test_func(1, 300)) vw
ON VW.table_key = vw.function_key
Facing this in production only. It works fine in test environment.
In my case the DB field didn't exist, and it was returning
SQL Error: 904, SQLState: 42000 ORA-00904: : invalid identifier
After Creating the field, of course it worked,
Double check those fields and make sure they are matching...
Hope it may give you a clue to find the issue
In my case I missed #ManyToOne(fetch = FetchType.EAGER) on that #JoinColumn
Verify that the user with which you are executing the query has the necessary grants for the test_func() function.

sql Error in derby - ERROR 42X01: Syntax error: Encountered "KEY"

following query gives error like ERROR 42X01: Syntax error: Encountered "KEY" at line 1, column 48.
I am not able to understand what is the exact issue. column KEY is exist and datatype is integer.
Insert into UOM_TYPE
(UNITS_OF_MEASURE_NO,TYPE,KEY,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,VERSION)
values
(79,'Clinical Property',32,'JRL',DATE('2007-05-04'),'JRL',DATE('2007-05-04'),2);
Please help me to resolve the issue
KEY is a Keyword in derby db. you have to escape it :
Insert into UOM_TYPE
(UNITS_OF_MEASURE_NO,TYPE,"KEY",CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,VERSION)
values
(79,'Clinical Property',32,'JRL',DATE('2007-05-04'),'JRL',DATE('2007-05-04'),2);

update table column with Cursor value

Hello I have a problem with cursors here I have this code in my PL/SQL
update CAND_ORDER SET SOURCE_SITE_ID = i.SITE_ID WHERE CAND_ORDER_ID IN
(select CAND_ORDER_ID from CAND_ORDER where SOURCE_SITE_ID is null and SP_TRIAL_MATERIAL_ID in
(select SP_TRIAL_MATERIAL_ID from SP_TRIAL_MATERIAL where SP_RESEARCH_STATION_ID_SOURCE IN
(select SP_RESEARCH_STATION_ID from SP_RESEARCH_STATION where SP_RESEARCH_STATION.CODE IN
(SELECT SITE_CODE from SITE WHERE SITE.SITE_CODE=i.SITE_CODE))));
it gives an error saying:
PLS-00302: component 'SITE_ID' must be declared
ORA-06550: line 17, column 44:
PL/SQL: ORA-00904: "I"."SITE_ID": invalid identifier
which I totally do not understand would you please help pointing what is the problem
I think that the error was in the cursor itself as SITE_ID was not added in the cursor as column. I added it and the problem was solved.