View with parameters

Hello,
Can we create the view with the parameters? How to do that? We need to create the sql script with parameter for super user to query, instead of create sql script then we would like to create the view then user can select only view.
Many thanks in advance. :-)

Hi,
Views using SYS_CONTEXT, as Justin mentioned, are perhaps the most common way to simulate parameterized views in Oracle.
Another method is to use a table (usually a Global Temporary Table) to hold the parameters. The view can then join to the table, use it in scalar sub-queries, IN-sub-queries, etc.
This is the best way if you need to use the same parameterized view two (or more) times in the same query, with different parameters each time.
Edited by: Frank Kulash on Oct 10, 2008 4:04 PM
Sorry, I meant to reply to OP.

Similar Messages

  • How to create a view with parameters; read the documentation but nothing!

    Hello!
    I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
    Question: How do I create a view with parameters?
    I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
    I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
    The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
    Thanks for all your help and attention!
    Jorge C.

    You can set up a parameterized view via context as follows:
    1. Set up a procedure to set your context values:
    create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
    as
    BEGIN
    sys.dbms_session.set_context(p_context,p_param_name,p_value);
    END;
    2. Create your context using the procedure you just created
    create or replace context my_ctx using p_set_context
    3. This is the test table I'll use
    create table my_table(col1 number)
    and populate it:
    begin
    for v_index in 1..10
    loop
    insert into my_table values(v_index);
    end loop;
    end;
    and the view that will be parameterised
    create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
    4. Now set the parameters using the procedure above.
    begin
    p_set_context('my_ctx','start_range','1');
    p_set_context('my_ctx','end_range','5');
    end;
    5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
    selectng from v_my_table will give you 1 to 5
    You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
    Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
    begin
    p_set_context('my_ctx','start_range','3');
    end;
    and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
    Bit of a simplistic example, but you can see how easy it is. :-)
    Message was edited by:
    ian512

  • Is it possible to create views with parameters ?

    Hi,
    As MS-Access, is it possible to create views with parameters ?
    Ms-Access syntax : parameters [a] text; select * from table where code = [a]
    If yes, can you give samples ?
    Regards
    Pascal

    I suggest you you write a stored procedure that returns a recordset in oracle. Then execute the stored procedure and loop through the record set.
    Look in in MS Knowledgebase searching on ADO Stored Proceedures for the VB/C++/VBS .. code.
    Look in in Oracle PL/SQL guide for the Stored Proceedure code.

  • How I can create view with parameters?

    I have very big query (2000 rows) and 2 parameters.
    How I can create view with parameters?

    If I use this small part of my query than I have error :
    java.lang.NullPointerException
         at oracle.javatools.db.ora.OracleSQLQueryBuilder.buildQuery(OracleSQLQueryBuilder.java:199)
         at oracle.javatools.db.ora.OracleSQLQueryBuilder.buildQuery(OracleSQLQueryBuilder.java:147)
    What does it means?
    select
    ' Payroll ' as Revenue
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and ( nvl(a.scode, 0) between 60000 and 6009000 )
    union all ---------------------------------------------------------------------------------------------------------------------------------
    select
    ' Payroll Taxes '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    (nvl(a.scode, 0) between 60100 and 60690 )
    union all -------------------------------------------------------------------------------------------------------------------------------
    select
    ' Workers Comp/Disability '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    ( nvl(a.scode, 0) between 61200 and 61260)
    union all -------------------------------------------------------------------------------------------------------------------------------
    select
    ' Pension and Hospitalization '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    ( nvl(a.scode, 0) between 61000 and 61550 )
    union all -------------------------------------------------------------------------------------------------------------------------------
    select
    ' Other Labor Costs '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    ( nvl(a.scode, 0) between 616000 and 616400 )

  • Encapsulating a query in a view with "parameters"

    I have a complex query using analytic functions and an inline view, something like:
    select * from (
    select a, b, c, row_number() over (partition by x, order by y) rn
    where b like 'XXX%'
    where rn = 1;
    (The actual query is a little more complex, but that's the idea). This query performs very well.
    As the query is of some general use, I'd like to package it up. However, the 'XXX%' pattern will vary with each use.
    If I try to make a view v which is the query minus the XXX% where clause, the optimiser cannot merge the where clause and the view in a query like
    select * from v where b like 'XXX%'
    This doesn't surprise me too much - merging like that is going to be hard (if indeed it's possible at all!) As a result, the query using the view is significantly slower.
    Is there any way of making my original query reusable? For PL/SQL, I can use a function returning a REF CURSOR and taking the pattern as a parameter - but I need to use this from SQL.
    I could write a pipelined function and then do select * from table(my_fn('XXX%')). However, this is in 8i, where I don't have that option. Also, for a pipelined function, I'd need to define a record type and an associated table type - what seems like quite a lot of code for what is conceptually pretty simple.
    Have I missed any obvious options? I can live with the pipelined function and "no way until 9i" - but only as a general answer. For my current specific issue, that's equivalent to "you can't do this".
    I thought of using SYS_CONTEXT, but if I understand correctly, I can only use that in PL/SQL, as I can't set the context outside of an authorised package. Is that right, or is there a way I could use contexts? (Hmm, I need to be able to use the query from SQ, but I could probably execute a PL/SQL procedure before running the query, to set things up - does that help?)
    Thanks for any suggestions.
    Paul.

    SYS_CONTEXT would work, as would package global variables.
    I once wrote an example about this (though with TABLE function but for your case the principle stays the same) which you may find here:
    Re: TABLE FUNCTION - Using database view - send parameters to the function.
    hth, michael

  • Makes it possible to create view with parameters

    makes it possibel to create view with paramater, example
    create or replace view v_test(segment varchar2)
        select * from ref_user where segment = segmentThanks

    thanks..
    select count(distinct substr(a.svm_id,1,10)) jumlah " +
       " from daily_distribution_pop a, ref_toko b " +
       " where " +
       " substr(a.svm_id,1,10)=b.id and b.segment_type = 'A' and enable_flag='Y' " +
       " and a.tgl_visit between to_date('" + fromStartDate + "', 'dd/MM/yyyy') and to_date('" + fromEndDate + "', 'dd/MM/yyyy')
         and " + whereA + "= '" + whereB + "' " +
       " and substr(a.pom_id,1,2) = 'DP' and (a.qty_instore <> 0 or a.qty_delivered <> 0) ";
    {code}
    where fromStartDate,  fromEndDate, whereA, whereB  is variable parameter from asp.net.
    how to i can implement with view                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to call a url i-view with parameters

    Hello,
    I want to make a portal navigation in a absolute way. This call should open a url-iview. In this iview the main url string is placed. Further more, a url-parameter ("test") is placed with a standard value. Now, i want to call this iview (see the call below) and hand over the value of this url-parameter. But how could this be done? In the following way, it doesn`t work. The iView will be called but the parameter is not settet.
    Call:
    WDPortalNavigation.navigateAbsolute(
                    "ROLES://portal_content/de.dbag.dbag-f/de.dbag.optitechpro.connection_monitor-f/com.dbag.iViews-f/com.dbag.urltest-i",
                    WDPortalNavigationMode.SHOW_INPLACE,
                    (String) null,
                    (String) null,
                    WDPortalNavigationHistoryMode.NO_DUPLICATIONS,
                    (String) null,
                    (String) null,
                    "test=NUIBI");
    best regards
    Mathias

    hi Mathias
    Try this
    1) First right click on the iView you wish to open and click Open -> Object
    2) In the iView editor you will see:
    url parameter : The parameter identifier as recognized by the information source
    value: The value of the parameter
    type: The data type
    personalize:Define if portal end users can view the param and its assigned value and if they can personalize the iView at runtime
    display name: The display name for the parameter identifier
    3) Once you have defined the iView’s URL to the targeted Web page, you may need to configure parameters that are passed to the information source as part of the URL .
    4) The parameter name is something that shouldn’t be changed because it is recognized by the information source .
    5) The parameter value can be changed.
    6) The type specifies data type of the parameter. String: Apply this option for all data types whose property is for example, an integer or string. Mapped User and Mapped Password : Apply this option when the URL parameter requires authentication with the information source at runtime.
    7) The Personalization -specifies whether or not portal end users can view the parameter and its assigned value if they personalize the iView at runtime.
    Hidden: The end user does not see the parameter and its value. This is the default setting.
    Read/Write: The end user sees the parameter and is able to modify its value.
    Read Only: The end user sees the parameter and the fixed value assigned to it. The end user cannot modify the parameter value.
    8) The display name - specifies an intuitive display name for the parameter identifier. If you set the parameter to be viewable by end users at runtime, this name is displayed instead of the parameter identifier, which is often abbreviated and unintuitive. This attribute is available only if Read/Write or Read Only is selected in the Personalize attribute
    9) The Request method:
    Get – appends parameters to the URL when the data request is sent to the information source. The server receives the data in one long query string, which typically limits the length of parameters that can be passed.
    Post - sends parameters for the URL in the header of the data request stream (parameters are not appended to the URL). This allows for long parameters to be passed to a script and parsed one element at a time. POST is only supported when the Fetch Method property defined in the iView is set to Server-side
    Regards
    Pratyush

  • Call graphical calc view with parameters

    Hello,
    We want to call a graphical calculation view that requires parameters via CE functions.
    Is this possible? How can we do that?
    Thanks,
    Oshrit.

    Hello,
    We still don't know, how is it possible to select from CV with parameter through CE function.
    Thanks,
    Amir

  • Invocation report (Discoverer Viewer) with parameters from an application

    Hi everyone,
    I'm proving report in Discoverer Viewer invoking them from an application, which sends parameters to him.
    I cannot obtain, that they directly execute when doing click in the URL of execution with its parameters, but that opens the screen where it requests to enter the parameters, without assigning those that they are arriving to him in the URL.
    I verified if the problem were in the name of the parameters and apparently it takes the values from such by the order in which they arrive.
    Also I verified that the values of parameters are arriving correctly from the application.
    Somebody can help me with this?
    Thank you very much
    Ana

    Hi,
    I could resolve the problem.
    The creation parameters in discoverer reports is case sensitive with the parameters that arrive from an application.
    Anyway, thank you
    Ana

  • Can we create a Materialized View with Parameters?

    Experts,
    Can we create a materialized view by passing parameters to it. so that we change its value dynamically.
    If yes, plese provide me the eample also.
    Regards
    ND

    I have below mentioned query to be used in MV :
    SELECT ivr_vw.event_type, ivr_vw.event_sub_type,
    ivr_vw.channel_cd,
    ivr_vw.csg_event_id,
    ivr_vw.csg_title,
    ivr_vw.itv_title,
    ivr_vw.program_id,
    ivr_vw.price,
    ivr_vw.addt_flag,
    (SELECT FROM_TZ(TO_TIMESTAMP (TO_CHAR (to_date(ivr_vw.start_date,'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'),
    'MM/DD/YYYY HH24:MI:SS' ), 'EST')
    AT TIME ZONE 'MST' FROM DUAL) start_date,
    (SELECT FROM_TZ(TO_TIMESTAMP (TO_CHAR (to_date(ivr_vw.end_date,'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'),
    'MM/DD/YYYY HH24:MI:SS' ), 'EST')
    AT TIME ZONE 'MST' FROM DUAL) end_date,
    (SELECT FROM_TZ(TO_TIMESTAMP (TO_CHAR (to_date(ivr_vw.start_order_window,'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'),
    'MM/DD/YYYY HH24:MI:SS' ), 'EST')
    AT TIME ZONE 'MST' FROM DUAL) start_order_window,
    (SELECT FROM_TZ(TO_TIMESTAMP (TO_CHAR (to_date(ivr_vw.end_order_window,'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'),
    'MM/DD/YYYY HH24:MI:SS' ), 'EST')
    AT TIME ZONE 'MST' FROM DUAL) end_order_window,
    ivr_vw.dnis_cd, ivr_vw.packaged_event_id, ivr_vw.no_instalments,
    ivr_vw.disclaimer_flag, ivr_vw.english_voice_file_name,
    ivr_vw.spanish_voice_file_name, ivr_vw.package_flag,
    ivr_vw.is_all_day_event, ivr_vw.upsell_data, ivr_vw.dur_guaran_flag,
    ivr_vw.cp_profile_id, ivr_vw.high_def_flag
    FROM ppv_ivr_vw ivr_vw,
    (Select time_diff,
    use_daylight
    From ppv_zip_timezones ztz
    Where ztz.zip_code = 80014
    ) timeOffset
    WHERE NOT EXISTS (
    SELECT 'x'
    FROM ppv_channels_blackout_vw blk_vw
    WHERE ivr_vw.channel_cd = blk_vw.channel_cd
    AND blk_vw.zone_type_code = 'Area Code'
    AND blk_vw.zone_code = '435');
    Here, the column 'ztz.zip_code = 80014' should change dynamically as per the request of the user.
    Is it possible. If yes, what is the process of doing so.?
    Regards
    ND

  • How to run a View with parameters

    Hi guys,
    I have a view which has to take the USERNAME of the current user connected to the database as a parameter:
    Create or Replace View XYZ(A1,A2,A3)
    AS Select AA1, AA2, AA3
    from X1, X2
    where ...
    and X1.id_valid in (select XX3.id_valid
                   from X3 XX3
                   where XX3.ID_VALID = X1.id_valid
                   and XX3.username = USERNAME1 )
    Where USERNAME1 is the database user connected to it!.
    Could you give me a hand please?

    Just use the USER pseudocolumn ...
    create view v as
    select *
    from all_users
    where username = user;Richard

  • How to create a view with parameter?

    who can tell me hwo to create a view with
    parameters just like a cursor?

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • Create a view with parameter

    it's posible create a view with parameters?
    i want to create a view and pass it parameters, in the same way when i create a procedure or function.
    i never have seen it, but i would like to know if that's posible
    thanks

    You cannot create a view with parameters. The only way is to use a stored proc to dynamically create the sql statement. The substitution variable approach does not work. SQL*Plus will prompt for the value of the variable at compile time (i.e. when you create the view) and use the value you provide in the view's query.
    SQL> create or replace view jws_test_v as
      2  select * from jws_test where flag = '&flg'
      3  /
    Enter value for flg: AA
    old   2: select * from jws_test where flag = '&flg'
    new   2: select * from jws_test where flag = 'AA'
    View created.
    SQL> select * from jws_test_v
      2  /
    no rows selected
    SQL> select text from user_views where view_name = 'JWS_TEST_V'
      2  /
    TEXT
    select "LEV1","LEV2","LEV3","LEV4","LEV5","LEV6","FC","FLAG","ONAFT","ONAPT","CU
    PEFT","CUPEPT" from jws_test where flag = 'AA'This makes sense, since substitution vartiables are a sqlplus construct, not a sql or Oracle construct. A view constructed in this way would not be callable from anywhere other than sqlplus.

  • List view - filter with parameters

    Hi,
    I need to define a list view to filter data with parameters.
    I saw how to do it with the SPD in another post
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/92271aa4-6582-4ea5-a10f-deaf02d2b62c/filtering-the-list-view-by-passing-date-parameters-using-sharepoint-desginer-2010?forum=sharepointcustomizationprevious
    But  need to do it in visual Studio (via definitins or Object Model).
    How can I do that in Visual Studio?
    Help is really appreciated.
    Many thanks,
    DD

    Hi,
    According to your description, you might want to create a list definition with the filter value from query string from URL. Then when you create a list instance with this list
    definition, you will be able to filter the list view page by appending parameters to the URL in the address bar.
    You can achieve this through modifying the Schema.xml file in the list definition project in Visual Studio like this:
    How to create custom list definition
    http://msdn.microsoft.com/en-us/library/office/gg276355(v=office.14).aspx
    http://www.codeproject.com/Articles/412429/SharePoint-Create-List-Definition-and-Instanc
    CAML Query Schema
    http://msdn.microsoft.com/en-us/library/office/ms467521(v=office.15).aspx
    Then we can filter the list with such an URL:
    http://sp/Lists/List1/AllItems.aspx?Param1=2014-08-24&Param2=2014-08-28
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • Hierarchy on HANA Calculation View with Optional Input Parameters Fails

    Hi,
    Has anyone succeeded in building a hierarchy on top of a calculation view with optional input parameters, where an input parameter is not filled?
    The original requirement came from the wish to create a parent child hierarchy on a calculation view that was copied into the customer space from a HANA Live Financial Statement query view, but I have found the following when creating a simple level hierarchy on a calculation view that consumes one table. The Calculation View has one Input Parameter where the 'mandatory' box is unchecked.
    Calculation view reads ECC table FAGLFLEXT
    Simple level based hierarchy on fields PRCTR, RACCT and SEGMENT
    Input parameter is used as a filter for PRCTR with logic ("EMPTY" = '$$P_PROFITCTR$$' or "PRCTR" = '$$P_PROFITCTR$$')
    When I run the view I see the following behaviour in HANA Studio and Analysis for Excel
    Before building the hierarchy I could run the view with or without the Input Parameter
    After building the hierarchy I can run the view with the Input Parameter filled, but it fails when the Input Parameter is not filled.
    Error message is "error: search table error:  [2426] missing placeholder; missing value for mandatory parameter P_PROFITCTR"
    P_PROFITCTR is not a mandatory parameter, but the selection for the hierarchy view thinks it should be. I don't find any notes around this issue, so I don't think it's version related, however the version I have used for this test is 1.00.70.
    It's a shame we can't currently build the hierarchy as the parent child relationship is provided in HANA Live view NewGLFinancialStatementQuery.
    Thanks,
    Ken

    Hi Ken,
    We have been facing similar issue. We have even tried to set default value and as optional parameter. View still fails to create hierarchy (we are not using HANA live). As mentioned on page 97 of HANA modelling guide input parameter is mandatory from engine point of view. Hierarchy is generated as column view during the initial activation of calculation view and therefore expect a value by caller.
    This seems to be a product error. Some one from HANA development team should explain this issue in detail. I would expect someone like Thomas Jung reply to us.
    At the moment, we cant use input parameter for date prompt which gives us calendar popup feature for date selection. Hierarchies just don't work with input parameter. We are missing something.
    Regards
    Angad

Maybe you are looking for

  • AUTO CLEARING CONFIGURATION

    how to configur auto clearing (open item clearing ) wht is the use of GR/IR clearing account in f.13 plz tell use of both

  • Java Mapping library

    Hello all, we recently upgraded from XI 3.0 to PI 7.1. Now i want to implement a new Java Mapping, but i can't find the the library which contains the class "com.sap.aii.mapping.api.StreamTransformation". On our PI the directory under "(INSTANCE_DIR)

  • Landed Costs- Allocation By Weight.

    Hi, When trying to allocate landed cost by weight the Freight(FC) column which shows the bifurcation of cost amongst individual items distributes the cost in a manner which is difficult to understand. e.g. If the landed cost is $50 There are two item

  • Changing My Disk Type.

    I have 4.7 GB disks but iDVD will not let me switch to that setting from 4.2 GB disks. How do i do it?

  • TB Last question

    Good Morning. I'm a little perplexed and hoping someone can straighten me out... I created a member to track outstanding shares of stock, which gets updated quarterly to calculate Earnings per Share. I used the Time Balance funstionality to so that,