Last active
August 29, 2015 14:23
-
-
Save carloscasalar/77bb882dc540a3a9df4b to your computer and use it in GitHub Desktop.
Tips de código PL/SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Script para hacer split sobre una cadena de valores separados por comas utilizando dbms_utility | |
-- Tomado de http://stackoverflow.com/a/3828715/840635 | |
-- Esta forma sirve si la cadena sobre la que quieres hacer split no contiene únicamente números: | |
declare | |
l_input varchar2(4000) := '1,2,3'; | |
l_count binary_integer; | |
l_array dbms_utility.lname_array; | |
begin | |
dbms_utility.comma_to_table | |
( list => l_input | |
, tablen => l_count | |
, tab => l_array | |
); | |
dbms_output.put_line(l_count); | |
for i in 1 .. l_count | |
loop | |
dbms_output.put_line | |
( 'Element ' || to_char(i) || | |
' of array contains: ' || | |
l_array(i) | |
); | |
end loop; | |
end; | |
/ | |
-- Esa forma es un truquillo para cuando la cadena contiene una lista de números: | |
declare | |
l_input varchar2(4000) := '1,2,3'; | |
l_count binary_integer; | |
l_array dbms_utility.lname_array; | |
begin | |
dbms_utility.comma_to_table | |
( list => regexp_replace(l_input,'(^|,)','\1x') | |
, tablen => l_count | |
, tab => l_array | |
); | |
dbms_output.put_line(l_count); | |
for i in 1 .. l_count | |
loop | |
dbms_output.put_line | |
( 'Element ' || to_char(i) || | |
' of array contains: ' || | |
substr(l_array(i),2) | |
); | |
end loop; | |
end; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment