Help - Search - Members - Calendar
Full Version: queries
Oracle DBA Forums > Oracle > Oracle Forum
ravichand
hi ,
please solve this query

i want an employee details for which the sum of the individual digits of the empid is 30.

for ex let empid=55555

now 5+5+5+5+5=25

like that i need the emp details for which sum of the individual digits of the empid is 30.
can any one help me .
Arthritic Toe
QUOTE (ravichand @ Jun 26 2008, 06:21 AM) *
hi ,
please solve this query

i want an employee details for which the sum of the individual digits of the empid is 30.

for ex let empid=55555

now 5+5+5+5+5=25

like that i need the emp details for which sum of the individual digits of the empid is 30.
can any one help me .


Temptation is to ask why the hell...? Without getting into pl/sql, if you know how many digits your biggest empid is (the following assumes 5 digits max):

WHERE NVL(TO_NUMBER(SUBSTR(TO_CHAR(empid),1,1)),0) +
NVL(TO_NUMBER(SUBSTR(TO_CHAR(empid),2,1)),0) +
NVL(TO_NUMBER(SUBSTR(TO_CHAR(empid),3,1)),0) +
NVL(TO_NUMBER(SUBSTR(TO_CHAR(empid),4,1)),0) +
NVL(TO_NUMBER(SUBSTR(TO_CHAR(empid),5,1)),0) = 30

Is this your sql homework?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.