Ste*_*ven 13 string oracle formatting printf
以下是否有等价物或替代物?
SELECT mix_type || ' (' || mix_num || ')' as description
FROM acid_batch
WHERE mix_num < 10
Run Code Online (Sandbox Code Playgroud)
Oracle有类似printf样式的格式吗?
SELECT printf("%s (%s)", mix_type, mix_num) as description,
FROM acid_batch
WHERE mix_num < 10
Run Code Online (Sandbox Code Playgroud)
Ren*_*ger 20
我能想到的最接近于printf的标准近似值是utl_lms.format_message.但是,它在SQL语句中不起作用,也就是说,这是可以的:
begin
dbms_output.put_line(
utl_lms.format_message('hello %s, the number is %d', 'world', 42)
);
end;
/
Run Code Online (Sandbox Code Playgroud)
但是这给出了ORA-00902:无效的数据类型错误:
select utl_lms.format_message('hello %s, the number is %d', 'world', 42)
from dual
Run Code Online (Sandbox Code Playgroud)
没有没有以这种方式应用格式化字符串的内置Oracle函数.虽然为这个特定的例子编写自定义函数会很容易,但编写基于PL/SQL的printf实现将是一项挑战.
如果您经常需要这样做,也许您可以编写一个Oracle函数来包装Java调用以获得更丰富的字符串处理环境.
| 归档时间: |
|
| 查看次数: |
16810 次 |
| 最近记录: |