创建表视图并按小时限制访问

时间:2012-03-11 23:10:51

标签: sql

我是新来的,想知道是否有人可以给我一些帮助/想法。

我正在创建一个视图如下:

CREATE VIEW V_ORDERS
AS 
SELECT ORDERNUMBER, 
       CUSTOMERNUMBER, 
       DATEORDERPLACED, 
       DELIVERYINSTRUCTION, 
SCHEDULEID
FROM ORDERS

所以我允许访问sumone,如下所示:

GRANT ALL ON V_ORDERS TO "SUMONESPACE"

但我希望将对桌子的访问权限限制为上午9:00至下午6:00的工作时间

提前谢谢

1 个答案:

答案 0 :(得分:6)

如果没有其他帮助,您仍然可以提供一张空表:

CREATE VIEW bla AS
SELECT blabla
WHERE HOUR(NOW()) BETWEEN 9 AND 18

也许您可以添加UNION

UNION
SELECT 'You','should','be','at','home','now!'
WHERE HOUR(NOW()) NOT BETWEEN 9 AND 18

完善第一个想法:你可以为连接创建一个0或1行视图(如果Oracle碰巧计算每行可能更慢的sysdate表达式):

CREATE VIEW STAFF_ORDERVIEW_ALLOWED( current_sys_date ) AS 
SELECT sysdate
WHERE SYSDATE BETWEEN trunc(sysdate) + 9/24 AND trunc(sysdate) + 18/24;

然后你只需要加入

CREATE VIEW STAFF_ORDERVIEW_ATHOURS( current_sys_date, ordernumber, customernumber,
  dateorderplaced, deliveryinstruction, scheduleid) AS
SELECT sysdate, ORDERNUMBER, CUSTOMERNUMBER,
  DATEORDERPLACED, DELIVERYINSTRUCTION, SCHEDULEID
FROM STAFF_ORDERVIEW_ALLOWED
INNER JOIN ORDERS;