Using a variable in a view?

I know that it may not be possible to use a variable within a view, but I'm wondering if there isn't a work-around? If there is a single value---pulled from another table---you wish to reuse in a view that does not use dynamic SQL, how do you do so? I've been toying around with WITH statements, but that's getting me nowhere. I'm using 11r2.
BTW, please do not ask me the standard litany of angry-dba questions (why are you doing this? your database is f*****, RTFM, etc.), this is just for my own curiosity. :)
Thank you
Example for demo purposes only (I know it's not syntactically correct):
variable var_value varchar2(30)
begin
select this_is_just_one_value
int :var_value
from tableX where column1 = 'BOB';
end;
select
numerous_columns
from tableY
where
column5 = :var_value;

893968 wrote:
BTW, please do not ask me the standard litany of angry-dba questions (why are you doing this? your database is f*****, RTFM, etc.), this is just for my own curiosity. :)Why are you doing this? your database is f*****! RTFM! Etc!! ;-)
SQL is not a procedural language - so you cannot create a view for example that has a parameter signature. E.g. this is possible in a procedural language:
declare
        cursor c( deptID number ) is
                select * from emp where deptno = deptID;
begin
        open c( 1234 ); --// open SQL cursor using a parameter/variable
        --// etc..
        close c;
end;This is not possible using a SQL object like a view. As a view is not a procedure. So the same approach as the above using SQL (silly example, but do demonstrates the basics):
// define
create or replace view emp_view as select * from emp;
// use
select * from emp_view where deptno = 1234;The CBO is clever - and it will likely push such a predicate into the emp_view SQL statement.
To parameterise such a view, is ugly. And should only be considered when dealing with issues such as security and data restrictions. A context is created - this can contain a number of name-values. The view can then use a name-value from the context. Oracle's data dictionary views use this approach.

Similar Messages

  • Help to use presentation variables in title view

    Hi,
    I am trying to use presentation variables in title view and the presntation variable that I have created is for current month date range (04/01/2012-04/30/2012)
    When I am using this variable in the title view in the report it is showing me as (04/01/2012,04/30/2012)
    IS there any way to get the date range as 04/01/2012-04/30/2012 instead of comma

    863997 wrote:
    Hi,
    I can not create two presenation variables and use becasue I have dashboard prompts setted up and I am using that prompt in my dashboard and report to..So if I create two presentation variables seaperately and use then whenever we change the dates in the prompts the dates in the reprot title will not changeYou absolutely can use two presentation variables and they will change in the Title View if you use them there. Click on this link for the details on how to create the two prompts and use them in your report.
    http://oraclebizint.wordpress.com/2008/02/26/oracle-bi-ee-101332-between-prompts-for-date-columns-using-presentation-variables/

  • Correct Way to use Bind variables when using an MS SQL server backend

    Hey,
    I'm having some trouble figuring out how to use bind variables in a view when using an MS SQL server backend. For some reason when I'm using an ApplicationModule that has a MS SQL Server JDBC library loaded and I attempt to click OK when editing the following query:
    SELECT kit_status, component_id
    FROM numbered_inv
    WHERE trialname = :1
    I get an error stating that "SQL Query Error Message Incorrect Syntax near ':'". Is JDeveloper compatible with SQL server for bind variables because this query runs just fine if I replace the :1 with a say "Testing testing".
    Thanks in advance
    Edited by: NullCheck on Dec 15, 2010 2:06 PM

    Gotcha. I had tried %1% %0% ?0 and ?1 and various other permutations none of which worked. Got it working by setting the query to:
    SELECT kit_status, component_id
    FROM numbered_inv
    WHERE trialname = ?
    ORDER BY kit_status
    And then adding a bind variable with "Bind position" set to 0.
    Thanks again Shay!

  • How can I have a use a variable view for a Popover in Xcode Applescript-ObjC?

    I'm adding Popovers to my application, but I have it coming from buttons in different views. One button might be in a Tab-View, and one in the main window. If I specify the wrong view, the Popover is off to the left and down, like the image below:
    Here's my code:
    on OpenPopover_(sender)
            Popover's showRelativeToRect_ofView_preferredEdge_(sender's frame(), MainWindow's contentView(), current application's NSMaxYEdge)
            end OpenPopover_
    How can I use a variable view or not specify the view at all so that the buttons can be in different views without having to use multiple pieces of code, using Applescript-ObjC, Xcode?

    You are using the content view of the entire window instead of whatever view the button is in - the frame rectangles are relative to the view it is in.
    The method parameters are a rectangle that is relative to the view (to position the popover), the view containing the rectangle, and the edge of the rectangle to use.  To position relative to a button, you can get the button's superview (the containing view), for example:
    popover's showRelativeToRect_ofView_preferredEdge_(sender's frame(), sender's superview(), current application's NSMaxYEdge)

  • How to use local variables declared in b/t the methods in other views

    Hi
    i need to use the value of the local variables declared in b/w the views in one other view,as i have manipulated the value based on some condition & want to use it in 1 more view for my req.,but that variable is not global one just for once i need to use it,and i can't again write the whole for its conditions,as its there in initialization view,which if coded again,can hit the functionality there,so is it possible to use the value of such local variables thereafter or not,if yes pls let me know,or i need to declare the global variable for this.

    hi,
    1.Declare an Attribute in Component controller.
    2. Pass the value to this Attribute in View V1.
             using :
      wd_comp_controller->Att = 'Saurav'.
    3. Now in view2 , you can access this Attribute using:
      data lv type string.
         lv = wd_comp_controller->Att .
    Here Att is my attribute of type string declared in component controller.

  • How to use substitution variables in Microsoft Word using Hyperion Smart view

    Can we use Substitution Variables in copy data points and refresh in Microsoft Word? I tried it and it does not work dynamically (copy data points only copies what was in excel cell at that point). It only copies the static value of that variable from that cell. I want to use it dynamically in Word so that if I change the value of that variable in Essbase, it is updated in Word upon refresh. Any idea??
    We need this feature for reporting in microsoft word and keep using the data points every year (instead of copying the cells from excel over again)
    Any help/suggestion is appreciated.
    Thanks

    you can't use substitution variables with copy data points. I had tried a while ago (post 111.1.2.1.102) and it wouldn't work.  I checked with Oracle development and they said it I not available

  • Can we use session variables in BI publisher's Data Model SQL Query?

    Hi Experts,
    We need to implement Data level security in BI Publisher 11g.
    In OBIEE we do so by using session variables, so just wanted to ask if we can use the same session variables in BI Publisher as well
    ie can we include the where clause in the Data Models SQL Query like
    Where ORG_ID = @{biServer.variables['NQ_SESSION.INV_ORG']}
    Let me know your views on this.
    PS: We are implementing EBS r12 security in BI Publisher.
    Thanks

    Read this -> OBIEE 11g: Error: "[nQSError: 23006] The session variable, NQ_SESSION.LAN_INT, has no value definition." when Creating a SQL Query using the session variable NQ_SESSION.LAN_INT in BI Publisher [ID 1511676.1]
    Follow the ER - BUG:13607750 - NEED TO BE ABLE TO SET A SESSION VARIABLE IN OBIEE AND USE IT IN BI PUBLISHER
    HTH,
    SVS

  • Session Variable in filter view error

    Hello,
    My prompt is defaulted to current 12Weeks. I used session variable in the prompt to capture 12 Weeks (Current Week and Current+12).
    so the default value is @{biServer.variables['NQ_SESSION.PERIOD_STDATE']} where PERIOD_STDATE is my session varible.
    I am using a filter view to display the filters being applied.
    When the user opens a tab, the filter view is throwing error
    ***The syntax of the expression to be evaluated is invalid.***
    ***Expression: @{biServer.variables['NQ_SESSION.PERIOD_STDATE']}***
    My report is running fine. I just have the date column as prompted in my report request.
    When the user hits go button on the prompt then the filter view comes up just fine.
    What is that I am doing wrong? Why does the filter view gives result after hitting GO button?
    Please help.
    thanks,
    deep

    Hi,
    1. Set the default using logical SQL. Select <presentation table>.<presentation column> from <subject area> where <presentation table>.<presentationation column> =valueof(NQ_SESSION.<session variable>)
    2. You dont have to write the exact syntax for entering the session variable in the default values. You just need to use the session variable name after selecting the session variable type in the drop down.
    Hope this helped/ answered.
    Regards
    MuRam

  • How to pass the values to stored proc using presentation variable in OBIEE

    Need your help regarding in resolving an issue in OBIEE 10.1.3.4.1
    There are 6 reports say ‘A’,’B’,’C’,’D’,’E’,’F’ in the same subject area.
    The reports are being configured with prompts using either the repository/presentation variables.
    One of the reports say ‘A’ has been configured to pass the values using presentation variables from the prompt in Advanced Tab of the report request to the stored procedure defined in the Execute Before Query section of the connection pool.
    After running another report ‘B’ in the same subject area, upon visiting the report ‘A’ view display error is being seen ( Please have a look below screen shot for your reference) .
    Speculate the issue is around presentation variables of report ‘A’ getting initialized even before running the report.
    Appreciate your earliest advise as this is a prod issue.

    Hi Prasad,
    I got your note, you should not use Session variable syntax to call presentation variable.
    you should use like @{AIC_PROJ_PLAT_SEQ_NO}
    One more thing: first test the variable AIC_PROJ_PLAT_SEQ_NO value then try to pass to SP.
    Hope this helps

  • How to use the variables of Function exit in the include program

    i have a problem of using the variables of a function exit in the include program..
    If i use those variables there will be an error indicating 'Field FEBVW_IN is unknown. It is neither in one of the specified tables nor defined by a DATA statement'. Please help... Below is the code of the function exit:
    FUNCTION EXIT_SAPLIEDP_202.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     VALUE(IDOC_CONTROL_INDEX)
    *"     VALUE(IDOC_DATA_INDEX)
    *"     VALUE(FEBVW_IN) LIKE  FEBVW STRUCTURE  FEBVW
    *"     VALUE(FEBKO_IN) LIKE  FEBKO STRUCTURE  FEBKO
    *"     VALUE(FEBEP_IN) LIKE  FEBEP STRUCTURE  FEBEP
    *"     VALUE(FEBRE_IN) LIKE  FEBRE STRUCTURE  FEBRE
    *"     VALUE(FEBPI_IN) LIKE  FEBPI STRUCTURE  FEBPI
    *"  EXPORTING
    *"     VALUE(I_FIMSG) LIKE  FIMSG STRUCTURE  FIMSG
    *"     VALUE(FEBVW_OUT) LIKE  FEBVW STRUCTURE  FEBVW
    *"     VALUE(FEBKO_OUT) LIKE  FEBKO STRUCTURE  FEBKO
    *"     VALUE(FEBEP_OUT) LIKE  FEBEP STRUCTURE  FEBEP
    *"     VALUE(FEBRE_OUT) LIKE  FEBRE STRUCTURE  FEBRE
    *"     VALUE(FEBPI_OUT) LIKE  FEBPI STRUCTURE  FEBPI
    *"  TABLES
    *"      IDOC_CONTROL STRUCTURE  EDIDC
    *"      IDOC_DATA STRUCTURE  EDIDD
    *"      IDOC_AVIP STRUCTURE  AVIP OPTIONAL
    *"      IDOC_AVIR STRUCTURE  AVIR OPTIONAL
    *"      IDOC_AVIT STRUCTURE  AVIT OPTIONAL
    *"  CHANGING
    *"     REFERENCE(IDOC_AVIK) TYPE  AVIK OPTIONAL
    *"  EXCEPTIONS
    *"      PROC_ERROR
      INCLUDE ZXF08U10.
    Here is the code for the include program.
      INCLUDE ZXF08U10
    MOVE febvw_in TO febvw_out.

    Sometimes you will get this error message when checking include code in exits even though there is really no error - it happens because the include does not realise it is in the function due to the navigation index being out of date.
    Try activating the code - it may work even though the check said there were errors.
    You can also get this issue when trying to drill down on the field in the include to view its structure.
    Andrew

  • How to default bind variable using session variable at run time

    Hi All,
    I have a requirement where all VO queries (multiple VOs) produce only records that meet a certain value.
    For example, I have three tables with 3 VOs and each of them has a one-to-many relationship to another table (let's call it ref table and this table has a field called release). One of the 3 VOs is a parent/master table, and the other two are child tables. I created a VO for master table that linked to the ref table and created a view criteria using the release (use bind variable) field from the ref table. The other child tables have their own VO that has view criteria that also linked to ref table using the release field.
    On the UI page, I created a query component and a table from the master table VO. I also dropped the child table VOs in a tabbed panel which partial triggered by the master table. When I ran a query for a 'release' (hint: ref table value), the table for master table was filled the correct records that meet the criteria. Unfortunately, the child tables were not correct due to the query didn't use the bind variable that filter only records for the same 'release' value as the master table.
    The question is how do I 'default' or dynamically set the bind variable on the child tables based on the selection criteria from the query component. I am thinking to set a session variable from the query and use it in the bind variable in the child table, but not sure how to do it.
    Any suggestion how to do it or better solution to achieve the same effect?

    Hi,
    How about creating a custom AMImpl method, that takes parameters as required, and set the bind variables for all the desired VOs and perform executeQuery on them.
    You could expose this as client interface, and then use the method as parameter form.
    Check this thread for ex.
    Re: Setting Attribute in View Object through Managed Bean
    -Arun

  • Using Bind Variable in a SELECT

    Hi,
    I'm trying to build up my SQL query at run-time using bind variables and in the Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1) it says that 'After defining the bind variables, the next step is to reference them in the SQL statement. While SQL syntax allows bind variables to appear both in the SELECT list and in the WHERE clause, you'll typically use them in the latter context, as part of your WHERE clause.'.
    However, when I try to use the bind variables in my SELECT list because I've had to set a type for the variable to String the variable gets inserted with inverted commas either side e.g. SELECT 'Service' FROM TestTable. Is it possible to use bind variables to insert a value into my select list without these inverted commas around it?
    Thanks in advance,
    Tom

    OK, thanks for your response. Do you know of a way then where I can control my SELECT parameters programmatically? I'm currently trying to do it using the information in the chapter '35.9 Using Programmatic View Objects for Alternative Data Sources' from the Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1). I think I'm part way there, would this be the correct way of acheiving what I want?
    Cheers, Tom

  • Setting/using a variable in a package in SQL Developer

    The 10g db I'm working with has a package that contains a variable and routines to set and get the value of the variable. The variable is used in a number of views to tailor data displayed according to the variable value. This all works well in applications, which set the variable after a connection is opened and then issue queries against the views, and then close the connection.
    This also works well in Toad - I can open Toad, run a package routine to set the value and then open views (or run queries against views) in Toad to see how different variable values effect the data displayed. The package variable maintains its value so long as Toad is open, which seems to imply that Toad keeps a connection open.
    But I can't use SQL Developer in the same way. I can run the SET routine, but it has no effect in on views subsequently run. When running the SET routine, setting the value to 1, the output is:
    Connecting to the database HERC DB.
    Process exited.
    Disconnecting from the database HERC DB.
    I can then run the GET routine, but the value of the variable is always zero:
    Connecting to the database HERC DB.
    v_Return = 0
    Process exited.
    Disconnecting from the database HERC DB.
    The implication seems to be that a connection is made, the routine is run and then the connection is closed. The closing of the connection resets the variable. Is there some way I can have SQL Developer behave like Toad, such that the package variable value is maintained for my SQL Developer session? I've looked at connection roperties and application preferences, but I've not seen anything that seems to be related keeping a connection open.
    BTW, I have tried the "connection startup script", but to no avail. Perhaps I've doen this improperly; the script simply attempts to invoke the package set routine, like so: myPkg.set_identity(1)
    Thanks.
    Edited by: user483973 on Oct 20, 2009 9:20 AM

    When running stored PL/SQL through the IDE context node or editor, indeed a new session is opened and consequently closed on completion after committing. Although great for having the IDE free to continue working, it does have its drawbacks when you want variables to persist and changes to be visible in the IDE before committing.
    To prevent the new session and the commit, just call the PL/SQL from a worksheet (in a call, query or anonymous block).
    The startup script should work in that respect, but make sure to wrap your call in an anonymous block, else you'll get a syntax error.
    Hope that helps,
    K.

  • Using Static Variable against Context Attribute for Holding IWDView

    Dear Friends,
    I have a method which is in another DC which has a parameter of the type IWDView. In my view, I will have an action which will call the method in another component by passing the value for the view parameter. Here, I can achieve this in 2 types. One is - I declare a static variable and assign the wdDoModifyView's view as parameter value and I can pass this variable as parameter whenever calling that method or the second way - create an attribute and assign the same wdDoModifyView's view parameter as its value. Whenever I call this method, I can pass this attribute as parameter. What is the difference between these two types of holding the value since I am storing the same value i.e., wdDoModifyView's view parameter. But when I trigger the action from different user sessions, the first type of code (using static variable) prints the same value in both the sessions for view.hashCode() and View.toString(), but the same is printing the different values when I pass the attribute which holds the view parameter.
    Clarification on this is highly appreciated
    The problem I face is when I use static variable to get the view instance and export the data using the UI element's id, the data belonging to different user sessions is mixed up where as when I use Context Attribute, the same problem doesn't arise. I want to know the reason why it is so. Is there any other place or way where I can get the current view instance of each session instead of wdDoModifyView?

    Hi Sujai ,
    As you have specified the problem that we face when we use  static attributes, when end users are using the application .
    Static means i  have n number of objects but the static variable value will remain same every where.
    when it is context attribute for every object i.e nth object you have a nth context attribute i mean nth copy of the context attribute.
    so every user has a unique Iview parameter , when context is used and
    when static is used  , assume you have userA , his iview is set this intially  and u have another user B , when he is using  , since the variable is static and when you access this variable you will get the value of userA.
    Regards
    Govardan Raj

  • Opening a ref cursor using CLOB variable

    Is there any way to open a ref cusor using CLOB variable.
    When I am opening on CLOB variable , I am getting an error like 'Missing Expression'
    Please help me

    For 10g...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_large_sql  CLOB;
      3    v_num        NUMBER := 0;
      4    v_upperbound NUMBER;
      5    v_sql        DBMS_SQL.VARCHAR2S;
      6    v_cur        INTEGER;
      7    v_ret        NUMBER;
      8  begin
      9    -- Build a very large SQL statement in the CLOB
    10    LOOP
    11      IF v_num = 0 THEN
    12        v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
    13      ELSE
    14        v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
    15      END IF;
    16      v_num := v_num + 1;
    17      EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
    18    END LOOP;
    19    DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
    20    DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
    21    --
    22    -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
    23    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
    24    FOR i IN 1..v_upperbound
    25    LOOP
    26      v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
    27                                 ,256 -- amount
    28                                 ,((i-1)*256)+1 -- offset
    29                                 );
    30    END LOOP;
    31    --
    32    -- Now parse and execute the SQL statement
    33    v_cur := DBMS_SQL.OPEN_CURSOR;
    34    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
    35    v_ret := DBMS_SQL.EXECUTE(v_cur);
    36    DBMS_OUTPUT.PUT_LINE('View Created');
    37* end;
    SQL> /
    Length:40015
    Num:548
    View Created
    PL/SQL procedure successfully completed.
    SQL> select count(*) from vw_tmp;
      COUNT(*)
           548
    SQL> select * from vw_tmp where rownum <= 10;
    COL1
    The number of this row is : 0000000
    The number of this row is : 0000001
    The number of this row is : 0000002
    The number of this row is : 0000003
    The number of this row is : 0000004
    The number of this row is : 0000005
    The number of this row is : 0000006
    The number of this row is : 0000007
    The number of this row is : 0000008
    The number of this row is : 0000009
    10 rows selected.
    SQL>

Maybe you are looking for