Name Type Description
--------------- --------------- ---------------------------------
Operator VARCHAR2(30) Default operators: '!^*/=+-&|'
Op_Association VARCHAR2(30) Operator associations: 'RRLLLLLLL'
Op_Precedence VARCHAR2(30) Operator precedence: '443322210'
Quote VARCHAR2(5) Quote characters: '"'''
Blank VARCHAR2(5) Space and tab characters: ' '||CHR(9)
Comma CHAR(1) Comma character: ','
Tok# PLS_INTEGER Count of Tokens
Ops# PLS_INTEGER Count of Operators
Res# PLS_INTEGER Count of Result elements
Text_Array TABLE OF VARCHAR2 Main type definition for arrays
Ops Text_Array Array of operators
Tokens Text_Array Tokenized source
Results Text_Array Result array
SUBPROGRAMS
Subprogram Description
-------------- ----------------------------------------------
Initialize Setup initial options
Tokenize Return array of string constituents
Parse_Csv Return field values of delimited string
Shunting Yard Return Shunting Yard array
INITIALIZE Procedure
Option Description
--------------- ---------------------------------------------------
Operator Change/Set the default list of operators
Op_Association Change/Set the corresponding association of operators
Op_Precedence Change/Set the operator precedence
Use_Quotes Enable quoted strings to be tokenized regardless of
embedded delimiters
Discard_Blanks Ignore spaces and tabs (exclude blanks from result array)
Include_Operators Includes operators in the result array
Debug_On Enables debugging messages
Syntax
Text2Token.INITIALIZE (
P_Operator VARCHAR2 DEFAULT NULL
, P_Op_Association VARCHAR2 DEFAULT NULL
, P_Op_Precedence VARCHAR2 DEFAULT NULL
, P_Include_Operators BOOLEAN DEFAULT TRUE
, P_Use_Quotes BOOLEAN DEFAULT TRUE
, P_Discard_Blanks BOOLEAN DEFAULT TRUE
, P_Debug BOOLEAN DEFAULT FALSE);
TOKENIZE Function
Text2Token.Tokenize (
P_Source_Text VARCHAR2
, P_Delimiters VARCHAR2 DEFAULT NULL );
Returns
Text2Token.Tokens%TYPE;
Text2Token.Parse_Csv (
P_ P_Source_Text VARCHAR2
, P_Delimiters VARCHAR2 DEFAULT Comma );
Returns
Text2Token.Results%TYPE;
SHUNTING_YARD Function
Text2Token.Shunting_Yard (
P_ P_Source_Text VARCHAR2
, P_Delimiters VARCHAR2 DEFAULT Comma );
Returns
Text2Token.Results%TYPE;
SQL> DECLARE
2 V_Text VARCHAR2 ( 1000 );
3 V_Results Text2token.Results%TYPE;
4
5 PROCEDURE Print_Result ( P_Ttl VARCHAR2 )
6 IS
7 BEGIN
8 DBMS_OUTPUT.Put_Line ( '***** ' || P_Ttl || ' Results *****'||CHR(10)||'String ['||V_Text||']' );
9
10 FOR I IN 1 .. V_Results.COUNT
11 LOOP
12 DBMS_OUTPUT.Put_Line ( TO_CHAR ( I, '000.' ) ||' '|| V_Results ( I ) );
13 END LOOP;
14 END;
15 BEGIN
16 Text2token.Initialize ( );
17 V_Text := '3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3';
18 V_Results := Text2token.Tokenize ( V_Text );
19 Print_Result ( 'Tokenize' );
20
21 Text2token.Initialize ( );
22 V_Results := Text2token.Shurting_Yard ( V_Text );
23 Print_Result ( 'Shurting_Yard' );
24
25 Text2token.Initialize ( );
26 V_Text := 'We are,the people,out fishing,with,"O''Brien, Elka",at the lake.';
27 V_Results := Text2token.Parse_Csv ( V_Text );
28 Print_Result ( 'Parse_Csv' );
29
30 END;
31 /
***** Tokenize Results *****
String [3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3]
001. 3
002. +
003. 4
004. *
005. 2
006. /
007. (
008. 1
009. -
010. 5
011. )
012. ^
013. 2
014. ^
015. 3
***** Shurting_Yard Results *****
String [3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3]
001. 3
002. 4
003. 2
004. *
005. 1
006. 5
007. -
008. 2
009. 3
010. ^
011. ^
012. /
013. +
***** Parse_Csv Results *****
String [We are,the people,out fishing,with,"O'Brien, Elka",at the lake.]
001. We are
002. the people
003. out fishing
004. with
005. O'Brien, Elka
006. at the lake.
PL/SQL procedure successfully completed.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Author
Commented:I'll remove the disclaimer.
Author
Commented:The source code seems to be missing -- added the source code.
Author
Commented:text2token-pkg.sql