1.创建一个package
--定义包
create or replace package view_move_user is
--set值方法
function set_moveuser(moveuser varchar2) return varchar2;
--get值防范
function get_moveuser return varchar2;
end view_move_user;
2.创建package body,实现package中的两个方法
--包方法实现
create or replace package body view_move_user is
paramValue varchar2(32);
--给paramValue赋值
function set_moveuser(moveuser varchar2) return varchar2 is
begin
paramValue :=moveuser;
return moveuser;
end;
--返回paramValue的值
function get_moveuser return varchar2 is
begin
return paramValue;
end;
end view_move_user;
--3.创建带参数视图view_move_user.get_moveuser()是从方法中获取传入的参数
create view view_move2 as
SELECT U.NAME,U.MOVE_USER,C.CLASS_NAME FROM NJP_USER_TEST U
INNER JOIN CLASS C ON U.ID=C.U_ID
where U.MOVE_USER=view_move_user.get_moveuser()
--查询带参数视图
select * from view_move2 where view_move_user.set_moveuser('USER1')='USER1'
建表语句:
DROP TABLE "njp"."CLASS";
CREATE TABLE "njp"."CLASS" (
"ID" VARCHAR2(255 BYTE) NOT NULL,
"CLASS_NAME" VARCHAR2(255 BYTE),
"U_ID" VARCHAR2(255 BYTE)
)
LOGGING
NOCOMPRESS
PCTFREE 10
INITRANS 1
STORAGE (
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS 2147483645
BUFFER_POOL DEFAULT
)
PARALLEL 1
NOCACHE
DISABLE ROW MOVEMENT
;
-- ----------------------------
-- Records of CLASS
-- ----------------------------
INSERT INTO "njp"."CLASS" VALUES ('1', 'CLASS1', '1');
INSERT INTO "njp"."CLASS" VALUES ('2', 'CLASS2', '2');
---------------------------------------------------------------------------
DROP TABLE "njp"."NJP_USER_TEST";
CREATE TABLE "njp"."NJP_USER_TEST" (
"ID" VARCHAR2(255 BYTE) NOT NULL,
"NAME" VARCHAR2(255 BYTE),
"MOVE_USER" VARCHAR2(255 BYTE)
)
LOGGING
NOCOMPRESS
PCTFREE 10
INITRANS 1
STORAGE (
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS 2147483645
BUFFER_POOL DEFAULT
)
PARALLEL 1
NOCACHE
DISABLE ROW MOVEMENT
;
-- ----------------------------
-- Records of NJP_USER_TEST
-- ----------------------------
INSERT INTO "njp"."NJP_USER_TEST" VALUES ('1', 'NAME1', 'USER1');
INSERT INTO "njp"."NJP_USER_TEST" VALUES ('2', 'NAME2', 'USER2');
参考资料: