ORACLE INSTR AND SUBSTR DEAL WITH STRINGS

DECLARE
    names VARCHAR2(60) := 'Anna,Matt,Joe,Nathan,Andrew,Aaron,Jeff';
    names_adjusted VARCHAR2(61);
    comma_location NUMBER := 0;
   prev_location NUMBER := 0;
BEGIN
    --Stick a comma after the final name
         names_adjusted := names || ',';
     LOOP
        comma_location := INSTR(names_adjusted,',',comma_location+1);
     EXIT WHEN comma_location = 0;
            DBMS_OUTPUT.PUT_LINE(
                       SUBSTR(names_adjusted,prev_location+1,
                            comma_location-prev_location-1));
                            prev_location := comma_location;
       END LOOP;
   END;
 

你可能感兴趣的:(oracle,pl/sql)