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?