Sql 一次插入某些记录
伙计们,如果我一次插入50-60k条记录,我怎么能在全局临时表中一次插入1000条记录呢。请检查下面的插入查询以了解更多信息。谢谢Sql 一次插入某些记录,sql,oracle,Sql,Oracle,伙计们,如果我一次插入50-60k条记录,我怎么能在全局临时表中一次插入1000条记录呢。请检查下面的插入查询以了解更多信息。谢谢 Create or replace PROCEDURE Employee( emp_refno IN CLOB ) AS Begin with inputs ( str ) as ( select to_clob(emp_refno ) from dual ), prep ( s, n, token, st
Create or replace PROCEDURE Employee(
emp_refno IN CLOB
)
AS
Begin
with inputs ( str ) as (
select to_clob(emp_refno )
from dual
),
prep ( s, n, token, st_pos, end_pos ) as (
select ',' || str || ',', -1, null, null, 1
from inputs
union all
select s, n+1, substr(s, st_pos, end_pos - st_pos),
end_pos + 1, instr(s, ',', 1, n+3)
from prep
where end_pos != 0
)
INSERT into GlobalTemp_EMP
select token from prep;
commit;
OPEN p_resultset FOR
select e.empname, e.empaddress, f.department
from employee e
join department f on e.emp_id = t.emp_id
and e.emp_refno in (SELECT emp_refno from GlobalTemp_EMP) //using GTT In subquery
您可以使用
批量收集和限制
CREATE OR replace PROCEDURE employee( emp_refno IN CLOB ) AS
c_limit PLS_INTEGER := 1000;
CURSOR token_cur IS
WITH inputs
(
str
)
AS
(
SELECT to_clob(emp_refno)
FROM dual
)
,
prep
(
s,
n,
token,
st_pos,
end_pos
)
AS
(
SELECT ','
|| str
|| ',',
-1,
NULL,
NULL,
1
FROM inputs
UNION ALL
SELECT s,
n + 1,
substr(s, st_pos, end_pos - st_pos),
end_pos + 1,
instr(s, ',', 1, n + 3)
FROM prep
WHERE end_pos != 0
)
SELECT token
FROM prep
WHERE n > 0;
TYPE token_t
IS
TABLE OF CLOB;
rec_token_t TOKEN_T;
BEGIN
OPEN token_cur;
LOOP
FETCH token_cur bulk collect
INTO rec_token_t limit c_limit;
EXIT WHEN rec_token_t.count = 0;
--IF rec_token_t.count > 0 THEN
forall rec IN rec_token_t.first ..rec_token_t.last
INSERT INTO globaltemp_emp VALUES
(
rec_token_t(rec)
);
COMMIT;
--END IF;
--EXIT
--WHEN rec_token_t.count = 0;
END LOOP;
OPEN p_resultset FOR
SELECT e.empname,
e.empaddress,
f.department
FROM employee e
join department f
ON e.emp_id = t.emp_id
AND e.emp_refno IN
(
SELECT emp_refno
FROM globaltemp_emp) //USING gtt IN subquery
END;
您可以使用
批量收集和限制
CREATE OR replace PROCEDURE employee( emp_refno IN CLOB ) AS
c_limit PLS_INTEGER := 1000;
CURSOR token_cur IS
WITH inputs
(
str
)
AS
(
SELECT to_clob(emp_refno)
FROM dual
)
,
prep
(
s,
n,
token,
st_pos,
end_pos
)
AS
(
SELECT ','
|| str
|| ',',
-1,
NULL,
NULL,
1
FROM inputs
UNION ALL
SELECT s,
n + 1,
substr(s, st_pos, end_pos - st_pos),
end_pos + 1,
instr(s, ',', 1, n + 3)
FROM prep
WHERE end_pos != 0
)
SELECT token
FROM prep
WHERE n > 0;
TYPE token_t
IS
TABLE OF CLOB;
rec_token_t TOKEN_T;
BEGIN
OPEN token_cur;
LOOP
FETCH token_cur bulk collect
INTO rec_token_t limit c_limit;
EXIT WHEN rec_token_t.count = 0;
--IF rec_token_t.count > 0 THEN
forall rec IN rec_token_t.first ..rec_token_t.last
INSERT INTO globaltemp_emp VALUES
(
rec_token_t(rec)
);
COMMIT;
--END IF;
--EXIT
--WHEN rec_token_t.count = 0;
END LOOP;
OPEN p_resultset FOR
SELECT e.empname,
e.empaddress,
f.department
FROM employee e
join department f
ON e.emp_id = t.emp_id
AND e.emp_refno IN
(
SELECT emp_refno
FROM globaltemp_emp) //USING gtt IN subquery
END;
请提供架构定义、示例数据和完整的错误消息。抱歉,我不清楚。。。请编辑您的问题以包括架构定义、示例数据和完整的错误消息。错误消息在哪里?select语句的相关性是什么?请提供架构定义、示例数据和完整的错误消息。抱歉,我不清楚。。。请编辑您的问题以包括架构定义、示例数据和完整的错误消息。错误消息在哪里?select声明的相关性是什么?感谢您的努力。你是个救生员。祝你有幸福的一天,先生,谢谢你的努力。你是个救生员。祝你好运,先生