且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Oracle'printf'等价物

更新时间:2022-10-14 18:02:14

没有内置的Oracle函数以这种方式应用格式化字符串。尽管为这个特定的例子写一个自定义函数是很容易的,但是编写一个基于PL / SQL的printf实现将是一个挑战。



如果您经常需要这样做,也许您可​​以编写一个Oracle函数来封装Java调用,以实现更丰富的字符串处理环境。 b

Is there an equivalent or alternative to the following?

SELECT mix_type || ' (' || mix_num || ')' as description
  FROM acid_batch
 WHERE mix_num < 10

Does Oracle have something like printf style formatting?

SELECT printf("%s (%s)", mix_type, mix_num) as description,
  FROM acid_batch
 WHERE mix_num < 10

No there are no built-in Oracle functions that apply a formatting string in this fashion. Although it would be easy to write a custom function for this specific example, writing a PL/SQL-based implementation of printf would be challenging.

If you have a frequent need for this, perhaps you could write an Oracle function that wraps a Java call for a richer string handling environment.