How do I create a view with parameters in Oracle?

Source: Internet
Author: User

This article describes an example of creating a parameter view in an Oracle database, with the need for a friend reference.

How do I create a view with parameters in Oracle?

In an Oracle database, views are not like stored procedures and functions, but can be defined as input parameters, but can be implemented in a different way, using packages.

First, define the package:

Copy Code code example:

/* Defined by individual needs, I define three parameters, because my project program needs, so three parameters are number, of course, can define other types
But remember, the parameter type of the second create must be the same as the first create, or the package creation fails
*/
Create or Replace package P_view_param is
--Parameter One
function Set_param (num number) return number;
function Get_param return number;
--Parameter Two
function Set_type (num number) return number;
function Get_type return number;
--Parameter Three
function set_id (num number) return number;
function get_id return number;
End P_view_param;
--
Create or Replace package body P_view_param is
Paramvalue number;
Paramtype number;
Paramid number;
--Param
function Set_param (num number) return number is
Begin
Paramvalue:=num;
return num;
End

function Get_param return number is
Begin
return paramvalue;
End
--Type
function Set_type (num number) return number is
Begin
Paramtype:=num;
return num;
End

function Get_type return number is
Begin
return paramtype;
End
--ID
function set_id (num number) return number is
Begin
Paramid:=num;
return num;
End

function get_id return number is
Begin
return paramid;
End

End P_view_param;

Make sure you create the first one first;

Next define the view:

Copy Code code example:

/*
* Define the view, where you follow the parameters, you can assemble yourself, note that the View field matches the field of select
*/
CREATE OR REPLACE VIEW abstract_sum_view (fa_id, Aircraft_num,aircraft_weight,airline_code,anchor_pos)
As SELECT f.fa_id, F.aircraft_num,findweight (f.aircraft_num), F.airline_code,f.anchor_pos
From Tb_flight_abstract F
where f.fa_id=p_view_param.get_id (); --Parameters

--using views, sending parameters
SELECT * from Abstract_sum_view where p_view_param.set_id (3) =3;

How do I create a view with parameters in Oracle?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.