Use Oracle functions to implement a simple version of The. NETString. Format Function

Source: Internet
Author: User
Selectstringreplace (

Select stringreplace (

Due to development needs, I want to implement some common prompts. For example, the prompt message content is: "The XXX value YYY is incorrect. Please check and enter it again !", Then, the general information should be: "{0} value {1} is incorrect. Please check and enter it again !". But how can I Replace "{0}" and "{1? In.. net, the String has a String. format function, so that we can easily replace different content with different content, but there is no such function in Oracle (as far as I know, I don't know if there is any news !), But I want to use it again, so I can only write it myself.

Think about it. If you have any questions, please let me know:

There are multiple parameters in the information, and they are represented by numbers in curly brackets, such as {0}, {1}, {2, it is best to use Arrays for these parameters, but is there an array in Oracle PL/SQL? I blame myself for not working hard at ordinary times. I hate little books when I use them. After logging on to the Internet, there is no ready-made data type in Oralce. You only need to customize the array type (actually the Table structure type). The following code is shown:

But the problem arises again. How can I pass the value to the function when I use it? Cup, tangled for a while, forget it, just be stupid for a moment, string split. So what does this function need?

1. Information Content

2. Parameter List (multiple parameters are separated by delimiters)

3. delimiter (of course, it is the same as that in 2. Otherwise, you will be confused)

Let's start writing it. In another thought, is it better to divide it into two functions? One is used to split the returned parameter array list, and the other is to call the split function to obtain the parameter list, perform the replacement action, and finally return. En, think about it. Let's write it into two. The function is simple and naive.

As the saying goes, you can attack the jade. The split function is ready for use. Let's take a look at it:

1RETURN returnvalue;
44 END stringsplit;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.