how to find record with all 0 values records [message #627805] |
Mon, 17 November 2014 04:16 |
|
mmi78
Messages: 31 Registered: April 2013 Location: dhaka
|
Member |
|
|
I need a query to find out the records with all 0,
create table t1 (
id number,
val varchar2(10)
);
insert into t1 values (1,'0');
insert into t1 values (2,'01');
insert into t1 values (3,'00');
insert into t1 values (4,'0000');
insert into t1 values(5,'010');
commit;
From that table i need the output as like
1 0
3 00
5 0000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: how to find record with all 0 values records [message #627824 is a reply to message #627822] |
Mon, 17 November 2014 06:21 |
|
mmi78
Messages: 31 Registered: April 2013 Location: dhaka
|
Member |
|
|
tigsav wrote on Mon, 17 November 2014 06:17No it will Not ,Select Query will never modify the Data.
select id, val from t1 where lpad(val, 10, '0') = lpad('0', 10, '0');
select id, val from t1 where replace(val, 0) IS NULL;
2nd query is awesome. Thanks a lot
|
|
|
|
|
|
Re: how to find record with all 0 values records [message #627830 is a reply to message #627826] |
Mon, 17 November 2014 06:57 |
|
Michel Cadot
Messages: 68643 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
mmi78 wrote on Mon, 17 November 2014 13:28
select id, val from t1 where trim(TRANSLATE(val, '0', ' ')) is null
Am i correct Michel Cadot
You can avoid TRIM function:
SQL> select id, val from t1 where TRANSLATE(val, ' 0', ' ') is null;
ID VAL
---------- ----------
1 0
3 00
4 0000
3 rows selected.
If a character in the second parameter has no character at the same place in the third parameter then this character is removed from the first parameter string (val).
|
|
|
|
|
|