WITH FUNCTION

说明

创建临时函数,可为查询调用

语法

with_function ::=

参数

FUNCTION_STATEMENT

函数的定义

query

查询语句。

注解

WITH FUNCTION 子句可以在 SQL 查询中定义可复用的函数,从而使查询更具模块化和易读性。 在WITH FUNCTION还可以DML操作。

示例

示例1: 使用 WITH FUNCTION

drop table ta;

create table ta(v_name varchar2(30));
insert into ta values('test');

with
function with_function(v_owner in varchar2,v_name in varchar2)
	return varchar2
is
 pragma autonomous_transaction;
begin
  delete from ta;
  insert into ta values ('tt');
  commit;
  return v_owner || '.' || v_name;
end;
select with_function(owner, object_name) from dba_objects  where rownum < 5
union
select * from ta;

/
drop table ta;