我是子查询因子条款的忠实粉丝。
WITH t1 as (select 1 as id from dual)
select * from t1;
和oracle 12c现在包含WITH子句中的PL / SQL声明部分
WITH
FUNCTION with_function(p_id IN NUMBER) RETURN NUMBER IS
BEGIN
RETURN p_id;
END;
SELECT with_function(id)
FROM t1
WHERE rownum = 1
但我似乎无法让他们一起工作吗?
WITH t1 as (select 1 as id from dual)
WITH FUNCTION with_function(p_id IN NUMBER) RETURN NUMBER IS
BEGIN
RETURN p_id;
END;
SELECT with_function(id)
FROM t1
WHERE rownum = 1;
答案 0 :(得分:3)
请参阅语法:
https://docs.oracle.com/database/121/SQLRF/statements_10002.htm#SQLRF01702
如您所见,语法为:
WITH [ plsql_declarations ] [ subquery_factoring_clause ]
这意味着PL / SQL必须首先进行,然后以其他方式进行SQL查询:
WITH
FUNCTION with_function(p_id IN NUMBER) RETURN NUMBER IS
BEGIN
RETURN p_id;
END;
t1 as (select 1 as id from dual)
SELECT with_function(id)
FROM t1
WHERE rownum = 1;