gpt4 book ai didi

sql - 使用 CTE 函数插入语句

转载 作者:行者123 更新时间:2023-12-02 15:06:27 26 4
gpt4 key购买 nike

我正在尝试这样做:

with
function add_fnc(p_id number) return number
is
begin
return p_id + 1;
end;
insert into temp_table
(
select add_fnc(1) from dual
);

但它显示编译错误:

ORA-00928: missing SELECT keyword

有没有办法将 CTE 函数与插入语句一起使用?

最佳答案

试试这个:

create table demo (col1 int);

insert /*+ with_plsql */ into demo (col1)
with
function add_one(p_id number) return number
as
begin
return p_id + 1;
end;
select add_one(rownum)
from dual
/

https://oracle-base.com/articles/12c/with-clause-enhancements-12cr1

某些工具可能无法处理此语法。它在 SQL*Plus 12.1 中对我有用(当以斜杠字符终止时,对于 PL/SQL 代码),但在 PL/SQL Developer 12.0.7 (Oracle 12.1) 中失败。

关于sql - 使用 CTE 函数插入语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52538248/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com