SQL Queries "00904. 00000 - "%s: invalid identifier" - sql

Hi I have the following code
SELECT entertainer_id,
entertainer_groupname
FROM casestudy_entertainer
INNER JOIN casestudy_availability ON
casestudy_entertainer.entertainer_id
= CASESTUDY_AVAILABILITY.AVAILABILITY_ENTERTAINERID
INNER JOIN casestudy_calendardates ON
CASESTUDY_AVAILABILITY.AVAILIBILITY_CALENDARDATEID
= casestudy_calendardates.calendar_Id
WHERE entertainer_type = '&Entertainer_TYPE'
AND casestudy_calendardates.calendar_date = '&Event_date'
And I don't seem to be able to figure out what its not liking when I run this.
It gives me the following error
ORA-00904: "CASESTUDY_AVAILIBILITY"."AVAILIBILITY_CALENDARDATEID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 7 Column: 4
I do have all the tables in place with all the correct rows.
The only thing is I have no data as of yet, Could this possibly be the issue?

You should try the lower case for the table/column identifiers(like in from/inner join clauses):
SELECT entertainer_id,
entertainer_groupname
FROM casestudy_entertainer
INNER JOIN casestudy_availability ON casestudy_entertainer.entertainer_id = casestudy_availability.availability_entertainerid
INNER JOIN casestudy_calendardates ON casestudy_availability.availibility_calendardateid = casestudy_calendardates.calendar_id
WHERE entertainer_type = '&Entertainer_TYPE'
AND casestudy_calendardates.calendar_date = '&Event_date'

This Error is caused by a special character in one of the columns of the database table. DBA will be able to help you.

You have same tablenames in your tables while left joining.
Change tablename of one , it will work.

no data is not the issue, you won't simply get a null result. ORA-00904 indicates, that you used a column that does not exist or does not comply to the Oracle specification.
Please check for correct naming. You might be better of with shorter names or at least table aliasses to get to code more readable.
Without knowing your table structure I cannot tell you where the error is. do a describe table_name;
It would also help to have the oracle version number SELECT * FROM V$VERSION or SELECT version FROM V$INSTANCE
and your client software you are using

What is interesting, Oracle gives that message not only if the name of the column is bad, but also if the name of the table/alias is bad - not defined alias, twice defined (as mentioned #PrajwalRai), error in the table name.

Old question, but maybe it helps:
sometimes you copy and paste text from a source that has a different character set ...
Type it over in sql-dev for instance and see if the error is gone

I was able to clear this error in an Oracle DB using Oracle SQL Developer by placing strings in single quotes instead of double quotes

Related

Oracle SQL Join Eror

This is my query. But I am getting following error.
Select customer_info.CUSTOMER_ID, customer_info.NAME, Customer_Hierarchy_API.Get_Description(Cust_Hierarchy_Struct_API.Get_Hierarchy_Id(CUSTOMER_ID))
from CUST_ORD_CUSTOMER_ENT
JOIN customer_info ON
customer_info.customer_id = cust_ord_customer_ent.customer_id;
ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action: Error at Line: 1 Column: 137
Cust_Hierarchy_Struct_API.Get_Hierarchy_Id(CUSTOMER_ID)
You need to specify which table to take the CUSTOMER_ID column from, as that column name exists in two differnt tables being used (Oracle won't do it for you, programming languages hate ambiguity, so should you).
In your case it doesn't matter which, but you have to choose one.
Cust_Hierarchy_Struct_API.Get_Hierarchy_Id(customer_info.CUSTOMER_ID)
As a principle, never refer to a column on its own, always fully qualify it with the table name or alias. If when you can, don't; it's sloppy and leads to problems as/when the code or database strucutre evolves.
Another solution is the USING clause:
Select ci.CUSTOMER_ID, ci.NAME,
Customer_Hierarchy_API.Get_Description(Cust_Hierarchy_Struct_API.Get_Hierarchy_Id(CUSTOMER_ID))
from CUST_ORD_CUSTOMER_ENT coc join
customer_info ci
using (customer_id);
USING allows you to mention the join keys without having to qualify the reference. After all, the value is the same regardless of which table the value comes from, based on the JOIN condition.

Compare two CLOB columns in Oracle SQL Developer

I am trying to compare two columns of CLOB datatype in Oracle SQL Developer. Below is the query used,
select *
from t1
join t2 on t1.reference_no = t2.reference_no
where dbms_lob.compare (t1.text, t2.t_col_clob) = 0;
Getting error message as
ORA-00904: : invalid identifier.
This means I don't have access to dbms_lob.compare
How comparison can be done with using dbms_lob.compare?
Please note raised this as separate because all the information available is using dbms_lob.compare, Found nothing how this can be done without using dbms_lob.compare and also I won't be getting access to dbms_lob.compare. Please suggest a SQL way to compare this.

Selecting variable_of_tablename.* from tablename gives 00904. 00000 - "%s: invalid identifier"

SELECT sur.* FROM table_name
Whenever I run this code in SQLDeveloper it it gives me the error
ORA-00904: "SUR": invalid identifier
00000 - "%s: invalid identifier"
I'm not sure how to fix this and haven't been able to find anything online. The reason I have to use this format is because it follows a format already being implemented by previous developers and I have to adhere to that standard.
Has anyone had any experience with this?
Try this
SELECT sur.* FROM table_name sur;
You have used a sur alias for referring all the columns of the table table_name but before you can use that you need to give table table_name an alias like sur
However the below query will work fine as you are using the actual table name instead of a different alias name.
select table_name.* from table_name;
Here, you ask to list columns from table "SUR" but since no such table exists in "from" clause, Oracle raises this error.
There are 2 options here:
Give an alias (a second name) to any of the table in from clause
For eg:
select sur.* from tablename1 sur, tablename2 foo where sur.col1=foo.col1
Use table name itself rather than using column alias "SUR"
For eg:
select tablename1.* from tablename1, tablename2 where tablename1.col1=tablename2.col1
Refer: http://www.techonthenet.com/oracle/alias.php

Postgresql confuses property as table

I'm trying to use a property that has a .(d0t) in the the propery name, but it seems like postgresql is confused and thinks that i'm trying to access a table property.
Here is the sql query i'm trying to run
select count(metadata.username), metadata.username from appointment join appointment_wrapper a on a.id=appointment_wrapper_id where property='state' and string_value='Kano' and timestamp > '2014-08-01' and timestamp < '2014-11-01' group by metadata.username;
When i run that query it says
ERROR: missing FROM-clause entry for table "metadata"
When i add quotes it says
ERROR: non-integer constant in GROUP BY
Any help on how to solve this?
Thank you
What you're looking for is a "quoted identifier" that you obtain by enclosing your column name in doublequotes to prevent it from being interpreted as a keyword:
SELECT count("metadata.username") from app group by "metadata.username";
Just a reminder that you really, really want to avoid the confusion that having reserved characters in your column or table names bring.

Oracle SQL Developer - Unable to run queries using varchar field as identifier

I'm new to using Oracle SQL Developer and to using an Oracle DB (have mainly used MySQL before)
I'm trying to do something like:
select * from content_definition where content_id = "hhhh233";
Where content_id is:
VARCHAR2(1000 BYTE)
But am getting:
ORA-00904: "hhhh233": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 1 Column: 52
I'm not really understanding why this isn't working as I used to do queries like this all the time with MySQL. I have been searching on this but nothing seems to be for my specific use case. I would appreciate if anyone can set me in the right direction on this. Thanks
You need to use single quotes for character data; double quotes signify identifiers and aliases:
select * from content_definition where content_id = 'hhhh233';
String delimiter in Oracle is a single quote ('), like this:
select * from content_definition where content_id = 'hhhh233';
Double quotes are only used for identifiers (e.g. column names and tables).