+4  A: 
SELECT *
FROM   ALL_TAB_COLS
WHERE  UPPER(COLUMN_NAME) = 'NAME';

will show you all columns called NAME

EDIT:

Based on your comment, aren't you missing the operators in your WHERE clause? ie =

select name, id
from   "TEST"
where  id :2      -- Surely you mean: id = :2
AND name :1       -- Surely you mean: name = :2
order by id desc

EDIT 2:

Based on the SQL*Plus output, it looks like you've created the table with lower-case column names. Whilst this is possible and valid it's usually just hard work. I'd recreate the columns with upper case names. (as Alex said)

EDIT 3:

I think...

SELECT "id", "name"
FROM   TEST
WHERE  "id" = :1
AND    "name" = :2
ORDER BY "id" desc;

should work

cagcowboy
I am getting those parameters from user, `:1` and `:2` are basically placeholders also when I ran above query than my column `name` did appear in the result but it is not `NAME` and so not sure what is happening in here.
Rachel
You still need to add the equals operator (if I understand you correctly) The error you're getting isn't anything to do with the column... it's that your SQL statement is incorrect. You need to add the = into the WHERE clause.
cagcowboy
It might help if you "DESC TEST" in SQL*Plus and post the result
cagcowboy
Are you saying that the column name is showing lower case in all_tab_columns? That suggests you wrapped it in double quotes when creating the table. Normally Oracle is case-insensitive for object names but you can force it to behave differently - not sure why you'd want to. As you can see from the error message, it's translating it to upper-case internally. So you may be able to `select "name", id from test where id = :2 and name = :1`? But you seem to be making life hard for yourself.
Alex Poole
i have the create query in which my column names are wrapped in double quotes, dunno if that would make difference.
Rachel
OK, so id is lower case too; so `select "name", "id" from test where "id" = :2 and "name" = :1`
Alex Poole
Yes it does make a big difference. Any particular reason for doing that?
Alex Poole
stay tuned, i will check it now and repost the result...
Rachel
Did the modified changes but still it gives same error.
Rachel
Wierd part is that I am able to get values if I do ` System.out.println("name:"+req.getParameter("s_1984"));` but if I run the query than it is giving me errors.
Rachel
Can we see your CREATE TABLE statement please?
cagcowboy
Still complaining about "TEST"."NAME"? Odd. You put quotes around all the column name appearances? Oh, just noticed the order by clause, that needs `"id"` too. If that doesn't work can you post exactly what your query looks like now?
Alex Poole
I'd be inclined to lose all the double-quotes (") Needed pretty rarely in my experience.
cagcowboy
it sitll gives me same error. here is the actual query `select "name", "id" from "TEST" where "name" = :2 AND "id" = :1 order by "id" desc`
Rachel
@cagcowboy agreed if the table can be recreated, this seems a salient lesson on why they're a bad idea unless there's a really really good reason...
Alex Poole
I am still wondering what could be possible reason for such an issue.
Rachel
Alex... completely agree! Have upvoted a random answer of yours on another question so that you get some credit for this question!
cagcowboy
Rachel... are you able to re-create the table?
cagcowboy
Thanks! Not quite there yet though! Looks like you're calling the SQL from Java so maybe it needs the double-quotes to be escaped; though that ought to cause a compiler error. If you're executing that query in SQL*Plus and still getting an ORA-904 then I'm confused. May still be easier to start again with a new table created without the quotes...
Alex Poole
I can modify the table also it has many references to other tables and so am not sure if re-creating a table would be the best bet for me.
Rachel
`Select "id", "name" from TEST where "id" = 1;` ran this in sql developer and it worked but still other way it gives ORA 904...am confused .
Rachel
`CREATE TABLE "AGNS"."TEST" ( "id" NUMBER(11,0) NOT NULL ENABLE, "name" VARCHAR2(29 BYTE), CONSTRAINT "TESTAPURVA_PK" PRIMARY KEY ("id") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "AGNSDATA" ENABLE )`
Rachel
If I delete the database and re-create it with new names than will my initial references also gone or once I have re-created table the references would be still alive ? Trying to see if there is an easy approach to do it.
Rachel
You could rename the columns? ALTER TABLE TEST RENAME COLUMN "id" TO ID; ALTER TABLE TEST RENAME COLUMN "name" TO NAME;
cagcowboy
but then for every reference I will have to change id to ID and name to NAME, initially i was doing with NAME and ID but then I was getting ora 904 for id and name and so had to change everything back to id and name and now am getting ORA for `NAME`
Rachel
True. It might be short-term pain for long-term gain though? It depends how much code you have to change, but if it makes it easier in the long-run it might be worth it.
cagcowboy
Only if you have the column names wrapped in quotes everywhere - in which case remove them from everywhere. But if you haven't then other things are probably broken too, and this will continue to be a pain and a source of initially hard-to-spot bugs forever. Definitely worth taking the hit early if possible, IMO.
Alex Poole
hmm...so I will go ahead and try to update all references and than see if it works...probably update comments here after modification.
Rachel
`ORA-00936: missing expression` is the next in line error for me.
Rachel
I think it might be worth you updating the question with: 1. New SQL*Plus table describe. 2. Full SQL statement. 3. Full error message for the new error
cagcowboy
Updated question with mentioned details.
Rachel
Cheers. Please can we get the java code too, since that's what throwing the error. Looks much better without those quotes!
cagcowboy
I am rolling up and down with this...Actually am using some sort of framework which is on the basis of Database Driven Application and so java layer is very thin and I do not know how internally framework works, moreover there is jsp file which directly communicates with the data source. I will add that too in the question but am not sure if it would be off much help.
Rachel
Rest assured it is not my code and its a legacy code which has been written 8 yrs back and so if you find something fishy than it is not my fault `;)`
Rachel
Hmmm.. kinda hard to see where the SQL statement comes from in the java, and so hard to see what might be wrong with it. Is it your own framework? Do you have access to the actual jdbc call?
cagcowboy
No. It's an internal framework and I do not have access to it. I am not sure if I have access to the native jdbc call but I can try to see if I can get hold of it.
Rachel
Basically we have `sql` defined inside the table which is somehow internally referenced by the Framework and thus the sql is executed and so it's kind off hard to debug. Current Application is totally database base driven, also all the fields appearing on the page are defined in database along with their access rights as to how can see the application and who can not see it.
Rachel
select name, id from TEST where name = :1 AND id = :2 order by id
Rachel
Wow! Can we see a couple more (similar-ish?) entries in the SQL table for comparison?
cagcowboy
Rachel
`select ur.user_id, ur.role_id, r.descr from user_role ur, app_role r where ur.user_id = :1 and ur.role_id = r.role_id and r.role_type in (383, 385) and r.role_id not in (169) order by r.descr`
Rachel
I am afraid but there is no other `SQL` similar to one we have in here for our case.
Rachel
Hmm. Suggest you try putting in a very simple version of the statement (e.g. SELECT id, name FROM test WHERE id = 1) and see if that works?
cagcowboy
`ORA-00936: missing expression` still getting errors even if I put basic version of sql in database table instead of placeholders.
Rachel
Probably I will try to look into this after sometime with fresh mind and update my observation in the question after sometime, anyways thanks for your help and guidance on this. I will share my update later in the day on this and would seek for the same.
Rachel
My instinct is that we're passed a point at which this is an Oracle issue... sounds more like it's probably an issue with your framework. Struggling to think of a way to find out what the SQL that's actually running is without getting under the hood of the framework. Does it have a logging mode or something you can turn on?
cagcowboy
Gosh. Not at all sure how the Java/SP relates to the SQL; I have a horrible, though entirely unsubstantiated, feeling that the framework might be doing its own thing with the bind variables. I'm wondering about `args[]`; you only seem to be giving it one numeric value, which I assume is `id`, so maybe it can't find a value for `name` and the framework is mangling the actual query sent through to Oracle. Bit of a stretch but could try leaving out the `name`/`:2` check and see what it does. Fun.
Alex Poole
Also based on something much earlier I suspect the query stored in the database is being cached, you don't seem to get the right error immediately after it's updated, which may not be helping.
Alex Poole
I am not sure if there is some kind of logging mechanism available but here the issue is `select name, id from TEST where name = :2 AND id = :1 order by id desc` is run properly if ran directly on db but if it is ran using framework that is if it is put in the database column and than trying to read it and run it than some wierd things are happening, I am very sure that there is something that I am doing crazy here but I need fresh pair of eyes to debug this issue further as many others have used the framework and never had this kind of issue.
Rachel
The order of the :2 and :1 don't make a difference do they? Should the :1 come first maybe?
cagcowboy
I have tried using different orders but still errors are not affected with the order.
Rachel
Can you pass it a second argument in the JSP `args[]` and see if it makes a difference? The ordering might be an issue but I don't think it's getting that far; you'd maybe be seeing an ORA-01722 if it was seeing the numeric and string args in the wrong order.
Alex Poole
Phew...was finally able to make it and you won't believe the issue...in sql table they need 3 parts, 1st is requirement of having image link by default and than 2nd and 3rd table is where we right actual SQL query and so I was able to run it properly now...thanks alex and cagcowboy for all your guidance on this.
Rachel
+2  A: 

It's a good idea not to surround column and table names with double-quotation marks unless you are know what you are doing and confident you need that.

In Oracle, database object names (including table and columns) are not case-sensitive and assumed upper-case unless you include them into double-quotes.

E.g, if a table created as TEST, it can be referred to as test, Test or TesT or "TEST". But if it is created as "Test", you will only be able to refer to it as "Test" (in double quotation marks). All the other ways will result in "invalid identifier" error.

Sergey Stadnik