Results 1 to 10 of 10

Thread: please, help me

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Answers
    3

    Question please, help me

    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




  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    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;


  3. #3
    Junior Member
    Join Date
    Feb 2008
    Answers
    3

    Re: please, help me

    thank you very much

    i am Beginner in sql

    and i need a simpel answer



  4. #4
    Junior Member
    Join Date
    Nov 2007
    Answers
    12

    Re: please, help me

    Hi,

    Try below query

    select sal=
    case
    when sal> 1000 and sal <2000 then '*'
    when sal> 2000 and sal <3000 then '**'
    end from emp


  5. #5
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    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



  6. #6
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    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


  7. #7

    Re: please, help me

    Hi you can try this select empno,ename,sal,replicate('*',round(sal,-3)/1000) ---this replicate command is for sal level


  8. #8

    Re: please, help me

    Quote Originally Posted by Prabhakaran_220162 View Post
    Hi you can try this SIMPLE TRANSACT SQL COMMAND

    Select empno,ename,sal,replicate('*',round(sal,-3)/1000)
    ---the above replicate command is for sal level
    try the above Transact SQl command and let me know how it works


  9. #9

    Re: please, help me

    My friend this works better for you in oracle

    select lpad('*',trunc(sal/1000),'*') from emp


  10. #10
    Junior Member
    Join Date
    Feb 2008
    Answers
    3

    Re: please, help me

    Quote Originally Posted by expertsharingdotcom View Post
    My friend this works better for you in oracle

    select lpad('*',trunc(sal/1000),'*') from emp
    thank you for all

    i try this answer and i found it is the best way i need

    thanks expertsharingdotcom




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact