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:
Create or replace type stringarrary is table of VARCHAR2 (4000);
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:
1Create or replace function stringsplit (SOURCE VARCHAR2, spliter VARCHAR2)
2 RETURN stringarrary
3 IS
4 J INT:= 0;
5 I INT:= 1;
6 Len INT:= 0;
7 Len1 INT:= 0;
8 Str VARCHAR2 (4000);
9 Returnvalue stringarrary:=Stringarrary ();
10 BEGIN
11 IF (spliter is null) OR (source is null)
12 THEN
13 Returnvalue. EXTEND;
14 Returnvalue (1):=SOURCE;
15 ELSE
16 Len:=LENGTH (SOURCE );
17 Len1:=LENGTH (spliter );
18
19 WHILE j<Len
20 LOOP
21 J:=INSTR (SOURCE, spliter, I );
22
23 IF j= 0
24 THEN
25 J:=Len;
26 Str:=SUBSTR (SOURCE, I );
27 Returnvalue. EXTEND;
28 Returnvalue (returnvalue. COUNT ):=Str;
29
30 IF I> =Len
31 THEN
32 EXIT;
33 End if;
34 ELSE
35 Str:=SUBSTR (SOURCE, I, j-I );
36 I:=J+Len1;
37 Returnvalue. EXTEND;
38 Returnvalue (returnvalue. COUNT ):=Str;
39 End if;
40 End loop;
41 End if;
42
43 RETURN returnvalue;
44 END stringsplit;