现代编程语言允许开发人员使用占位符创建字符串,并使用通常称为format
的函数/方法替换正确的值。有时,它看起来像这样:
"Hi {0}! How are you?".format('John');
Oracle SQL或PL / SQL中是否有任何具有相同行为的功能?或者这里的最佳做法是什么?
答案 0 :(得分:14)
utl_lms包,特别是该包的format_message()
过程可用于格式化字符串。
begin
dbms_output.put_line(utl_lms.format_message('Hi %s! How are you %s?.'
, 'John'
, 'John'
)
);
end;
结果:
Hi John! How are you John?.
应该注意:
%s
表示字符串,%d
表示数字),即使它们是相同的。