Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL - How do I repeat a character based on a value in a column

Tags:

string

sql

oracle

So I'm trying to query to get someones salary, then display a '$' based on the number of thousands they earn.

So example, is someone makes $15,000 I would have another column displaying '$$$$$$$$$$$$$$$'

I can get as far as this:

  SELECT e.last_name, 
         e.salary, 
         REPLACE(e.salary/1000, e.salary/1000, '$') AS "Graphic"
    FROM EMPLOYEES e
ORDER BY e.salary DESC, e.last_name

But I dont know how to display a certain number of '$'

like image 533
RJP Avatar asked Feb 14 '11 04:02

RJP


1 Answers

RPAD should work (you may need to adjust the rounding a little):

select rpad('$', round(salary/1000), '$') as "Graphic" from employees
like image 64
Thilo Avatar answered Oct 14 '22 06:10

Thilo