在 oracle 中使用参数创建视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15570084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make a View in oracle with Parameters
提问by Atif Imtiaz
I want to make a view in Oracle in which I am required to give student_ID
as parameter and it will extract student_name
from student
table.
I have no experience in views and no experience with Oracle.
我想在 Oracle 中创建一个视图,其中我需要将其student_ID
作为参数提供,并且它将student_name
从student
表中提取。我没有视图经验,也没有使用 Oracle 的经验。
回答by Don
Assuming a table definition like this:
假设一个表定义是这样的:
CREATE TABLE STUDENT (
student_id int,
student_name varchar2(100),
student_address varchar2(255),
student_email varchar2(100)
);
Create a view with just id and name fields:
创建一个只有 id 和 name 字段的视图:
CREATE VIEW VSTUDENT AS
SELECT student_id, student_name
FROM STUDENT;
You can then:
然后你可以:
SELECT student_name
FROM VSTUDENT
WHERE student_id=123;
Creating the view with only the student_id (query field) and student_name (required field) protects all the other student data from those who do not have access permissions.
创建仅包含 student_id(查询字段)和 student_name(必填字段)的视图可保护所有其他学生数据免受无访问权限的人的侵害。
回答by Art
CREATE VIEW view_name AS
SELECT student_name, student_grades, more columns...
FROM student_table
WHERE student_id = 20
/