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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1520733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:08:34  来源:igfitidea点击:

Does PL/SQL have an equivalent StringTokenizer to Java's?

sqloracleplsqltokenizestringtokenizer

提问by dacracot

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?

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

回答by PaulJ

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

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

Example:

例子:

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;
/

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

或查看此 Ask Tom 链接以了解其他想法...

Ak Tom - "varying elements in IN list"

Ak Tom - “IN 列表中的不同元素”

回答by Vincent Malgrat

if you have APEX installed, the function APEX_UTIL.string_to_tabledoes just that.

如果您安装了 APEX,该功能APEX_UTIL.string_to_table就是这样做的。

回答by APC

PL/SQL does not come with a built-in tokenizer. However, it is relatively simple to build out of SQL or PL/SQL. Adrian Billington's web site has several solutions. In addition, if you are on 10g, you could use this code from Tanel Poder, which does it in SQL using regex.

PL/SQL 没有内置分词器。但是,从 SQL 或 PL/SQL 构建出来相对简单。Adrian Billington 的网站有几个解决方案。此外,如果您使用的是 10g,您可以使用来自 Tanel Poder 的这段代码,它使用正则表达式在 SQL 中完成。

Admittedly it would be easier if Oracle just included the dang facility as one of their built-ins.

诚然,如果 Oracle 只是将 dang 工具作为其内置工具之一包含在内,那会更容易。

回答by tuinstoel

An alternative is to write a Java stored proc (there is a JVM inside the database), that means you can use java.util.StringTokenizer. You have to wrap a Java stored proc inside a PL/SQL procedure/function.

另一种方法是编写一个 Java 存储过程(数据库中有一个 JVM),这意味着您可以使用 java.util.StringTokenizer。您必须将 Java 存储过程包装在 PL/SQL 过程/函数中。

Se here for an example: http://forums.oracle.com/forums/thread.jspa?messageID=2575374&#2575374

以这里为例:http: //forums.oracle.com/forums/thread.jspa?messageID=2575374䰎

Sadly I dony understand Java's checked exceptions so the exception handling isn't really great (I'm not a Java dev).

遗憾的是,我不了解 Java 的检查异常,因此异常处理并不是很好(我不是 Java 开发人员)。