• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 37
  • Last Modified:

Storing a column count into an id

Can someone tell me how to fix this query? Basically I just want to do a select count on a column and then to store the result in a number or integer. It seems pretty simple, but I am really tired right now, so some help would be appreciated.

COUNTER INT;

SELECT COUNT ('CustomerId') INTO COUNTER FROM user_tables where table_name = 'Customers';

Here CustomerId is the column name. The query is not working as the result returned is zero.
0
brgdotnet
Asked:
brgdotnet
1 Solution
 
slightwv (䄆 Netminder) Commented:
By default Oracle stores object names in upper case.  You should NEVER alter that behaviour.

And surrounding the column name in single quotes makes it a string not an object name.

So to make what you posted syntax correct:
SELECT COUNT (*) INTO COUNTER FROM user_tables where table_name = 'CUSTOMERS';

That should return 1 if the table exists in the schema or 0 if it doesn't.

customer_id isn't a column in user_tables.

So is this what you want?

SELECT COUNT (CustomerId) INTO COUNTER FROM customers;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now