Oracle stored procedure case set

Note: Use the tools PLSQL Developer

One, the while using a simple ( replacement string of characters, and the same effect REPLACE )

Note: There is no use REPLACE function

1, build stored procedures

The CREATE  OR  the REPLACE  PROCEDURE pro_testcom (P_String the IN  VARCHAR2 , replace1 the IN  VARCHAR2 , replace2 the IN  VARCHAR2 )
 the IS 
   P_STARTDue to NUMBER : =  . 1 ; - from which the start position taken 
   p_subLength NUMBER : =  . 1 ; - need to intercept long 
   p_string_length NUMBER : = length ( P_String); - obtaining a string length needs taken 
   p_new_string VARCHAR2 ( , 2014 ): =  '';--存储拼接新的字符串
BEGIN
   WHILE(p_start < p_string_length + 1) LOOP
     p_subLength := INSTR(p_string, replace1, p_start);
     IF p_subLength = 0 THEN
       p_subLength := p_string_length + 1;
     END IF ;
     
     IF p_new_string IS NULL THEN
       p_new_string := SUBSTR(p_string , p_start , p_subLength - p_start);
     ELSE
       p_new_string := P_new_string || replace2 || the SUBSTR (P_String, P_STARTDue to, p_subLength - P_STARTDue to);
      the END  the IF ; 
     P_STARTDue to: = p_subLength +  . 1 ;
    the END LOOP; 
   
   - a print result 
   the DBMS_OUTPUT.PUT_LINE ( ' character string is replaced after: ' || p_new_string);
 the END pro_testcom;

 2, executes a stored procedure ( command execution window )

- Open the log output 
SET SERVEROUTPUT ON ; 

Exec pro_testcom ( ' 555.555.555.555 ' , ' . ' , ' - ' );

3, the results 

After the string is replaced with: 555 - 555 - 555 - 555 
 
PL / the SQL Procedure successfully Completed

two,......

Guess you like

Origin www.cnblogs.com/kawhileonardfans/p/10966384.html