To Convert Comma Delimited Strings to Result Set | |
We have seen Query to Convert Comma Delimited Strings to Result Set previously. Here the same has been implemented using pipelined function. It can be reused when there is a need to use comma to table conversion logic in more than one place. CREATE FUNCTION FN_CONV_COMMA_TO_RESULTSET (IN_COMMA_DELIMTED_STRING VARCHAR2) RETURN TYP_COMMA_RSLT_SET PIPELINED AS V_TYP_COMMA_RSLT_SET TYP_COMMA_RSLT_SET; BEGIN SELECT SUBSTR (COMMA_DELIMTED_STRING, INSTR (COMMA_DELIMTED_STRING, ',', 1, LEVEL) + 1, INSTR (COMMA_DELIMTED_STRING, ',', 1, LEVEL + 1) INSTR (COMMA_DELIMTED_STRING, ',', 1, LEVEL) - 1 STRINGS BULK COLLECT INTO V_TYP_COMMA_RSLT_SET FROM (SELECT ',' || IN_COMMA_DELIMTED_STRING || ',' COMMA_DELIMTED_STRING, LENGTH (IN_COMMA_DELIMTED_STRING || ',') - LENGTH (REPLACE (IN_COMMA_DELIMTED_STRING || ',', ',', '' ) ) NO_OF_STRINGS FROM DUAL) CONNECT BY LEVEL <= NO_OF_STRINGS; FOR STRING_SET IN 1 .. V_TYP_COMMA_RSLT_SET.COUNT LOOP PIPE ROW (V_TYP_COMMA_RSLT_SET (STRING_SET)); END LOOP; END FN_CONV_COMMA_TO_RESULTSET; / |
|
|
|
This function can be reused. Another way is we can create this function and type as system user and grant execute privilege to other oracle users... you feedback is appreciated... :) |
Saturday, May 12, 2012
To Convert Comma Delimited String to Result Set
Friday, April 20, 2012
Reverse Engineering using Erwin Modeler
Reverse Engineering Oracle User using Erwin Modeler
Using
Create a new Model - [ File -> New ] / Ctrl + N
select the target database ( here oracle 10g is chosen ) and click on Next
Choose Database option to import object details by connecting to database. In the options listed right choose Current User to import details of user, which we are going to use when establishing the database connection.
Make sure Primary Keys, Relations options are checked to draw foreign key relation of schema objects.Click on Next to continue to key in database details.
Choose Authentication type as Database Authentication and key in the User Name, Password and Connection String Parameter value.
Click on Connect to begin the Reverse Engineering Process and finally you will get the Schema details as shown below
Now you can do modification to this logical structure depending on the new business requirement.
Thursday, April 12, 2012
Query to Convert Comma Delimited String to Result Set
Query to Convert Comma Delimited String to Result Set | |
Yes we can convert comma delimited string to result set. Although we have DBMS_UTILITY.COMMA_TO_TABLE, it is not accepting special characters... so, i have tried query to get it done... eg: to convert "Scott,Sachin-Tendulkar,Michael,Amma" as Result ------------- Scott Sachin Michael Amma Here is the query SELECT SUBSTR ( COMMA_DELIMTED_STRING , INSTR ( COMMA_DELIMTED_STRING , ',', 1, LEVEL) + 1, INSTR ( COMMA_DELIMTED_STRING , ',', 1, LEVEL + 1) - INSTR ( COMMA_DELIMTED_STRING , ',', 1, LEVEL) - 1 ) AS STRINGS FROM (SELECT ',' || COMMA_DELIMTED_STRING || ',' AS COMMA_DELIMTED_STRING , LENGTH ( COMMA_DELIMTED_STRING || ',') - LENGTH (REPLACE ( COMMA_DELIMTED_STRING || ',', ',', '')) AS NO_OF_STRINGS FROM (SELECT 'Scott,Sachin-Tendulkar,Michael,Amma' AS COMMA_DELIMTED_STRING FROM DUAL)) CONNECT BY LEVEL <= NO_OF_STRINGS / |
|
|
|
In the next page the same functionality is achieved using pipelined function, which will be reusable if comma to table conversion is to be done in more than one place. |
Subscribe to:
Posts (Atom)