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

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

Related

Oracle SQL Developer - Create View with parameters

I'm new to Oracle SQL and I'm currently working on an Oracle SQL view in Oracle SQL Developer.
I need two parameters in my View
fruitType (string)
fruitNumber (int)
I tried the following (simplified) statement in Oracle SQL Developer:
CREATE VIEW FRUITSRESULT (fruitType, fruitNumber) AS
SELECT
fruit_col1 as FruitType,
fruit_col2 as FruitNumber
fruit_col3 as FruitInfo
FROM
FRUITGARDEN
WHERE
fruit_col1 = fruitType
fruit_col2 = fruitNumber
;
Unfortunately this does not work, I always get the following error:
Error starting at line : 1 in command -
...
ORA-00904: "FRUITNUMBER": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Do you know how to solve this error?
Is it actually possible to create a parameterized View in Oracle SQL?
Is it actually possible to create a parameterized View in Oracle SQL?
No, that is not possible.
What you are thinking of as parameters are the column aliases for the output:
CREATE VIEW FRUITSRESULT (fruitType, fruitNumber, FruitInfo) AS
SELECT fruit_col1,
fruit_col2,
fruit_col3
FROM FRUITGARDEN;
Will output the values fruit_col1, fruit_col2 and fruit_col3 with the columns aliased to fruitType, fruitNumber, and FruitInfo (respectively). They are not, as you assumed, input parameters.

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

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

I'm trying to search through db and count all data items under specific column name

I'm trying to do a count of data items under the column name 'TXN'
Trying to search through all the tables in the database
I have tried:
SELECT COUNT (*) FROM all_tab_columns WHERE OWNER='RGSWKF_PRGM' where COLUMN_NAME like '%TXN%';
But I get the error:
ORA-00904: "COLUMN_NAME": invalid identifier
00904. 00000 - "%s: invalid identifier"
After seraching online for other ways, I came accross setting a case:
SELECT COUNT (case when COLUMN_NAME like '%TXN%') FROM all_tab_columns WHERE OWNER='RGSWKF_PRGM';
But I'm getting:
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
Would you know where I'm going wrong on the above statements? Or am I approaching this completeley wrong?
Fairly new to SQL, I'm trying to browse through the oracle data dictionary but not finding anything.
In the first query you have two WHERE keywords. Replace the second WHERE with AND:
SELECT COUNT (*)
FROM all_tab_columns
WHERE owner='RGSWKF_PRGM' AND column_name LIKE '%TXN%';

Bringing the other column , along all with all the other columns of the table (Oracle)

I am trying to Bringing the other column , along all with all the other columns of the table (Oracle)
As shown below
select order_id,person_id,col4,col5,* from orders
It is giving the below error :
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 1 Column: 66
Any inputs would be helpful !!
Use an alias:
select col1, col2, c.*
from my_table c
You can't specify columns together * wild card in Oracle, try if possible with alias
select order_id as A,person_id as B,col4 as C,col5 as D,* from orders
You cannot specify columns and the use a wildcard on the same query when doing a SQL SELECT.
This is due to projections and (as in relational algebra) projections requires that you specify attributes for selection.
In order to fully use projections, you either set attribute names and use alias (if you want to use wildcards).

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