在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:54:58  来源:igfitidea点击:

Make a View in oracle with Parameters

oracleviews

提问by Atif Imtiaz

I want to make a view in Oracle in which I am required to give student_IDas parameter and it will extract student_namefrom studenttable. I have no experience in views and no experience with Oracle.

我想在 Oracle 中创建一个视图,其中我需要将其student_ID作为参数提供,并且它将student_namestudent表中提取。我没有视图经验,也没有使用 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
 /