PL/SQL 是否具有与 Java 等效的 StringTokenizer?

2021-12-24 00:00:00 sql tokenize oracle plsql stringtokenizer

我使用 java.util.StringTokenizer 来简单解析 java 中的分隔字符串.我需要在 pl/sql 中使用相同类型的机制.我可以写它,但如果它已经存在,我更愿意使用它.有人知道 pl/sql 实现吗?一些有用的替代方案?

I use java.util.StringTokenizer for simple parsing of delimited strings in java. I have a need for the same type of mechanism in pl/sql. I could write it, but if it already exists, I would prefer to use that. Anyone know of a pl/sql implementation? Some useful alternative?

推荐答案

PL/SQL 确实包含一个基本的逗号分隔列表 (DBMS_UTILITY.COMMA_TO_TABLE).

PL/SQL does include a basic one for comma separated lists (DBMS_UTILITY.COMMA_TO_TABLE).

示例:

DECLARE
   lv_tab_length   BINARY_INTEGER;
   lt_array   DBMS_UTILITY.lname_array;
BEGIN
   DBMS_UTILITY.COMMA_TO_TABLE( list => 'one,two,three,four'
                              , tablen => lv_tab_length
                              , tab => lt_array
                              );

   DBMS_OUTPUT.PUT_LINE( 'lv_tab_length = ['||lv_tab_length||']' );

   FOR i IN 1..lv_tab_length
   LOOP
      DBMS_OUTPUT.PUT_LINE( '['||lt_array( i )||']' );
   END LOOP;

END;
/

或者查看这个 Ask Tom 链接以获得其他想法...

Or see this Ask Tom link for other ideas...

阿克汤姆 - "IN 列表中的不同元素"

相关文章