[英]Include multiple inline functions and multiple CTEs in a WITH clause in a single query
Oracle 18c:甲骨文 18c:
What is the syntax for including multiple inline functions and multiple CTEs in a WITH clause in a single query?在单个查询的 WITH 子句中包含多个内联函数和多个 CTE的语法是什么?
Function #1:功能#1:
function fucntion1(num in number) return number
is
begin
return num + 1;
end;
Function #2:功能#2:
function fucntion2(num in number) return number
is
begin
return num + 2;
end;
CTE #1: CTE #1:
cte as (select 1 from dual)
CTE #2: CTE #2:
cte2 as (select 2 from dual)
As ever for a "what is the syntax for ..." questions, you should refer to the official documentation.与以往一样,对于“...的语法是什么”问题,您应该参考官方文档。
The SELECT
syntax is SELECT
语法是
query_block ::=
查询块 ::=
with_clause ::=
with_clause ::=
plsql_declarations ::=
plsql_declarations ::=
subquery_factoring_clause ::=
subquery_factoring_clause ::=
The PL/SQL function syntax PL/SQL 函数语法
function_definition ::=
函数定义 ::=
body ::=
身体 ::=
Therefore:所以:
A PL/SQL function's body must be terminated with a ;
PL/SQL 函数的主体必须以
;
结尾。 . .
(Note: this is a PLSQL statement terminator and not a separator in the WITH
clause between PL/SQL function declarations as there is no separator character following PL/SQL function declarations.) (注意:这是一个 PLSQL 语句终止符,而不是 PL/SQL 函数声明之间的
WITH
子句中的分隔符,因为 PL/SQL 函数声明之后没有分隔符。)
There is a ,
character between successive sub-query factoring clauses.在连续的子查询因式分解子句之间有一个
,
字符。
The SELECT
statement does not need a ;
SELECT
语句不需要;
or /
statement terminator but it may be allowed/required/forbidden by the client application you are using to denote the termination of the statement.或
/
语句终止符,但您用于表示语句终止的客户端应用程序可能允许/要求/禁止它。
For example:例如:
It looks like the syntax is:看起来语法是:
with
function fucntion1(num in number) return number
is
begin
return num + 1;
end;
function fucntion2(num in number) return number
is
begin
return num + 2;
end;
cte as (select 1 from dual),
cte2 as (select 2 from dual)
select
fucntion1(1) as function_result
from
cte
union all
select
fucntion2(1)
from
cte2
FUNCTION_RESULT
---------------
2
3
Related: Using an inline function and CTE in a SQL query相关: 在 SQL 查询中使用内联函数和 CTE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.