top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to write a sql statement to find the first occurrence of a non zero value?

+1 vote
758 views
How to write a sql statement to find the first occurrence of a non zero value?
posted Jun 17, 2014 by Rajni

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

There is a slight chance the column "a" has a value of 0 which is not null. In that case, you will loose the information. There is another way of searching the first not null value of a column:

select column_name from table_name where column_name is not null and rownum<2; 
answer Jun 18, 2014 by Madhavi Latha
Similar Questions
0 votes

Write the prototype function in C: char * my_strchr (char * arr, char c);

The function should return the cursor to the first occurrence of the forwarded character in the character sequence or NULL if the forwarded character was not found.

i came up with solution also but it has to be string :

char *my_strchr(char *arr,char c)
{
int i=0;
char *p;
while(1)
{
if(i[arr] == c){p = i[arr];return p;break;}
if(i[arr] == '\0'){p= NULL;return p;break;}
i++;
}}

+2 votes

1,1,2,2,2,6,6,6,7,7,7,7,7,7,7,8,8,9,9,9

Example:
Input = 1 Output=0 (First index of 1).
Input = 2 Output=2 (First index of 2).
Input = 6 Output= 5 (First index of 6).
Input = 7 Output= 8 (First index of 7).
Input = 8 Output=15 (First index of 8).
Input = 9 Output=17 (First index of 9).

0 votes

Enter character: r
Enter string: programming
Output: Positions of 'r' in programming are: 2 5
Character 'r' occurred for 2 times

...