Oracle SQL - 如何根据列中的值重复字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4988906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL - How do I repeat a character based on a value in a column
提问by RJP
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 '$$$$$$$$$$$$$$$'
例如,如果有人赚了 15,000 美元,我会有另一列显示“$$$$$$$$$$$$$$”
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 '$'
但我不知道如何显示一定数量的“$”
回答by Thilo
RPAD should work (you may need to adjust the rounding a little):
RPAD 应该可以工作(您可能需要稍微调整四舍五入):
select rpad('$', round(salary/1000), '$') as "Graphic" from employees