Coding

Tách chuỗi thành mảng trong oracle

/* Formatted on 3/4/2015 12:32:08 AM (QP5 v5.126) */
DECLARE
l_input VARCHAR2 (4000) := ‘1,2,3’;
l_count BINARY_INTEGER;
l_array DBMS_UTILITY.lname_array;
BEGIN
SELECT param_value
INTO l_input
FROM item_param_detail
WHERE param_value LIKE ‘TO%,%’;

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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s