SQL or How to find out Oracle COLUMNS containing value

20 pts.
Tags:
Oracle Query
SQL
SQL or How to find out Oracle COLUMNS containing value "0" in a table. Suppose we have 20 columns in a table lets say 'T1' having column like C1, C2, C3, ----- upto C20, and we have to know in how many column zero or any other user specific value is present. Lets say in C1, C5, C7 there is/are zero in any of its row. This question is for Oracle DB
ASKED: August 4, 2010  1:22 PM
UPDATED: August 4, 2010  3:06 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

You could create an ugly query like this, including all 20 columns:

<pre>SELECT DECODE(SUM(DECODE(c1,<b>0</b>,1,0)),0,’C1 DOESN”T HAVE 0s’,'C1 HAS 0s’),
DECODE(SUM(DECODE(c2,<b>0</b>,1,0)),0,’C2 DOESN”T HAVE 0s’,'C2 HAS 0s’),
DECODE(SUM(DECODE(c3,<b>0</b>,1,0)),0,’C3 DOESN”T HAVE 0s’,'C3 HAS 0s’)
FROM your_Table;</pre>

Or you could use dynamic SQL to construct a similar query at run time based on the ALL_TAB_COLUMNS view.

—————

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following