Prepare for your Next Interview
This is a discussion on please, help me within the SQL forums, part of the Databases category; i have emp table it contains empno,ename,sal,sal level i need sal by thouthands = * SAL LEVEL if sal = 1000 than sal level =* if sal = 2000 than sal level =** ...
|
|||
|
i have emp table it contains
empno,ename,sal,sal level i need sal by thouthands = * SAL LEVEL if sal = 1000 than sal level =* if sal = 2000 than sal level =** if sal = 3400 than sal level =*** if sal = 15000 than sal level =*************** i donot want it static ![]() Thanks |
| Sponsored Links |
|
|||
|
Re: please, help me
Try this
sql> set serveroutput on; declare cursor c1 is select empno,sal,trunc(sal/1000,0) lvl from emp; c1r c1%rowtype; x varchar2(255); begin open c1; loop fetch c1 into c1r ; exit when c1%notfound; x:=null; if c1r.lvl >=1 then for i in 1..c1r.lvl loop x:=x||'*'; end loop; dbms_output.put_line(c1r.empno||' '||c1r.sal||' '||x); else dbms_output.put_line(c1r.empno||' '||c1r.sal||' '||'less than 1000'); end if; end loop; close c1; end; |
| The Following User Says Thank You to susarlasireesha For This Useful Post: | ||
|
|||
|
Re: please, help me
Try to use the following.
It is a simple answer for EMP table. Code:
select decode(round(sal/1000),1,'*',2,'**',3,'***',4,'****',5,'*****',6,'******',7,'*******',8,'********',9,'*********',10,'**********') from emp |
|
|||
|
Re: please, help me
little change to above post
select decode(TRUNC(sal/1000),1,'*',2,'**',3,'***',4,'****',5,'*****',6,'******',7,'*******',8,'********',9,'*********',10,'**********') from SCOTT.emp use trunc in place of round because 1600 is rounded to 2000 |
|
|||
|
Re: please, help me
try the above Transact SQl command and let me know how it works
|
|
|||
|
Re: please, help me
My friend this works better for you in oracle
select lpad('*',trunc(sal/1000),'*') from emp |
| The Following User Says Thank You to expertsharingdotcom For This Useful Post: | ||
|
|||
|
Re: please, help me
Quote:
i try this answer and i found it is the best way i need thanks expertsharingdotcom ![]() |