Reg_exp 在存储过程中需要 "into"
Reg_exp in stored procedure needs "into"
我在 Oracle 存储过程中有这个语句
select regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level)
from dual
connect by regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level) is not null;
但是,编译器抱怨我需要一个 "into" 子句。我尝试过(并且在我做之前就知道)但它没有用,因为 reg_exp 正在返回多个值。
有人可以帮忙吗?谢谢!
您可以将 cursors
用于 multiple-row
returns :
SQL> set serveroutput on;
SQL> declare
v_abc varchar2(1500);
begin
for c in ( select regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level) abc
from dual
connect by regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level) is not null )
loop
v_abc := c.abc;
dbms_output.put_line(v_abc);
end loop;
end;
您必须使用集合来存储 multi-row 结果。
以下示例演示了使用 SELECT INTO 语句将整行查询到 PL/SQL 记录集合中:
DECLARE
TYPE first_typ IS TABLE OF employees.first_name%TYPE INDEX BY PLS_INTEGER;
TYPE last_typ IS TABLE OF employees.first_name%TYPE INDEX BY PLS_INTEGER;
first_names first_typ;
last_names last_typ;
CURSOR c1 IS SELECT first_name, last_name FROM employees;
TYPE name_typ IS TABLE OF c1%ROWTYPE INDEX BY PLS_INTEGER;
all_names name_typ;
TYPE emp_typ IS TABLE OF employees%ROWTYPE INDEX BY PLS_INTEGER;
all_employees emp_typ;
BEGIN
-- Query multiple columns from multiple rows, and store them in a collection
-- of records.
SELECT first_name, last_name BULK COLLECT INTO all_names FROM EMPLOYEES;
-- Query multiple columns from multiple rows, and store them in separate
-- collections. (Generally less useful than a single collection of records.)
SELECT first_name, last_name
BULK COLLECT INTO first_names, last_names
FROM EMPLOYEES;
-- Query an entire (small!) table and store the rows
-- in a collection of records. Now you can manipulate the data
-- in-memory without any more I/O.
SELECT * BULK COLLECT INTO all_employees FROM employees;
END;
/
我在 Oracle 存储过程中有这个语句
select regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level)
from dual
connect by regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level) is not null;
但是,编译器抱怨我需要一个 "into" 子句。我尝试过(并且在我做之前就知道)但它没有用,因为 reg_exp 正在返回多个值。
有人可以帮忙吗?谢谢!
您可以将 cursors
用于 multiple-row
returns :
SQL> set serveroutput on;
SQL> declare
v_abc varchar2(1500);
begin
for c in ( select regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level) abc
from dual
connect by regexp_substr('hello,world', '[^(,|;|\s|&)]+', 1, level) is not null )
loop
v_abc := c.abc;
dbms_output.put_line(v_abc);
end loop;
end;
您必须使用集合来存储 multi-row 结果。
以下示例演示了使用 SELECT INTO 语句将整行查询到 PL/SQL 记录集合中:
DECLARE
TYPE first_typ IS TABLE OF employees.first_name%TYPE INDEX BY PLS_INTEGER;
TYPE last_typ IS TABLE OF employees.first_name%TYPE INDEX BY PLS_INTEGER;
first_names first_typ;
last_names last_typ;
CURSOR c1 IS SELECT first_name, last_name FROM employees;
TYPE name_typ IS TABLE OF c1%ROWTYPE INDEX BY PLS_INTEGER;
all_names name_typ;
TYPE emp_typ IS TABLE OF employees%ROWTYPE INDEX BY PLS_INTEGER;
all_employees emp_typ;
BEGIN
-- Query multiple columns from multiple rows, and store them in a collection
-- of records.
SELECT first_name, last_name BULK COLLECT INTO all_names FROM EMPLOYEES;
-- Query multiple columns from multiple rows, and store them in separate
-- collections. (Generally less useful than a single collection of records.)
SELECT first_name, last_name
BULK COLLECT INTO first_names, last_names
FROM EMPLOYEES;
-- Query an entire (small!) table and store the rows
-- in a collection of records. Now you can manipulate the data
-- in-memory without any more I/O.
SELECT * BULK COLLECT INTO all_employees FROM employees;
END;
/