众所周知,视图(view)中是不能直接使用变量的,但是在视图里面是可以调用包(package)的,通过package为视图传参。
1 创建全局变量(简单的get/set方法)
Package:
create or replace package p_countyarea_param is
function set_param(datetime varchar2) return varchar2;
function get_param return varchar2;
end p_countyarea_param;
Package Body:
create or replace package body p_countyarea_param is
paramValue varchar2(10);
function set_param(datetime varchar2) return varchar2 is
begin
paramValue := datetime;
return datetime;
end;
function get_param return varchar2 is
begin
return paramValue;
end;
end p_countyarea_param;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
2 在视图中调用变量
create or replace view p_view_user as
select id,
realName,
address
from tbl_info
where id = p_countyarea_param.get_param();
3 在查询中调用变量
select *
from p_view_user
where p_countyarea_param.set_param(<param>)=<param>