OraOpenSource / oos-utils

Common PL/SQL utility scripts
MIT License
203 stars 73 forks source link

Add function oos_util_string.strtok #174

Open jeffreykemp opened 6 years ago

jeffreykemp commented 6 years ago

Tokenize a string. Similar in functionality to strtok from C and PHP.

Useful in procedural code when the delimiter character(s) can change from token to token - i.e. not a fixed set of delimiters for the whole string.

I'll update with a simple implementation.

alexys009 commented 6 years ago

Hi, Jeff. I have a pipelined function (in my lib package) I am using for many years. It can be used in sql or pl/sql. Here its interface function str2tbl (p_str clob, p_delimiter varchar2:= ',|;.', p_encloser varchar2:='"', p_low varchar2 := 'y' , p_split number:=0, p_char varchar2:=chr(1)) return str_arr pipelined;

It seems that it does what you are looking for, although not exactly C or PHP tokenizer. If you are interested I can submit function code.

Regards, Alex

jeffreykemp commented 6 years ago

Hi Alex, that's nice and might make a good addition to this package, but it's not a like-for-like replacement for strtok.

strtok is called once per token, and you can give a different delimiter (or set of delimiters) for each token.