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

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%'

Related

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.

The mystic getClobVal()

I have a table (AKADMIN) with an XMLTYPE column which name is XML.
I would like to use the getClobVal() with this column.
select t.xml.getClobVal() /**/
, t.xml.getClobVal() --
, t.xml.getClobVal() as clobval
, t.xml.getClobVal()
from akadmin t where ROWID = 'AAAQc6AAIAAAADDAAA' ;
In the resultset the first 4 column give CLOB type, but the fifth column XMLTYPE. I have to type any comment or alias after getClobVal() to correct (CLOB) type of the result. Why?
Another issue, when I leave the alias of tablename:
select xml.getClobVal()
from akadmin t where ROWID = 'AAAQc6AAIAAAADDAAA' ;
It throws an ORA-00904 string: invalid identifier
Hmmm...
Does anybody have any idea?
Addition info about environment:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0;
PL/SQL Developer 10.0.5.1710
But a tried this in our Java apllication via OJDBC6 with same results
You should put xml in a brackets:
select (xml).getClobVal() from akadmin;
works for me

Oracle: Selecting * and aggregate column

Is it possible to select fields using the method below?
SELECT *, count(FIELD) FROM TABLE GROUP BY TABLE
I get the following error
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Error at Line: 1 Column: 9
Is it a syntax error or do you have to explicitly define each column rather than using *?
You can't use * and other columns. If you use an alias, then you can:
SELECT t.*
, count(FIELD)
FROM TABLE t
Also, your GROUP BY TABLE is wrong. You can't group by the table name, you must specify some columns, like this:
SELECT t.customer
, count(FIELD)
FROM TABLE t
GROUP BY t.customer
The columns that are selected in the field should be
an expression used as one of the group by criteria , or
an aggregate function , or
a literal value
For this, you need to indicate the fields you needed and should fit in the following criteria mentioned above.
SELECT FIELD1,FIELD2, COUNT(*) FROM TABLE1 GROUP BY FIELD1, FIELD2
If you insist to use the logic of your query, the use of subquery should be helpful.
For example,
SELECT * FROM TABLE1 T1 INNER JOIN (SELECT FIELD1, COUNT(FIELD1) AS [CountOfFIELD1] FROM TABLE1 T2 GROUP BY FIELD1)T3 ON T1.FIELD1=T3.FIELD1
Instead of * you need to give the column names:
SELECT a, b, COUNT(FIELD)
FROM TABLE
GROUP BY a, b;

Ora-00905 missing keyword error

Im getting below error while executing below line,
SELECT * INTO employee_Backup FROM employee
Error:
Ora-00905 missing keyword error
Your query should be
INSERT INTO employee_backup
SELECT *
FROM employee
Discussed here
And the syntax is
INSERT INTO table_name
SELECT *
FROM table_name
This is sql-server syntax you're trying to use.
The Oracle equivalent would be:
INSERT INTO employee_backup
(SELECT * FROM employee)

Update data in an Oracle view

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.

Resources