Regarding SYS_CONTEXT

I was being told that when we use context, it does a binding so for the next call sql does a soft parse
create or replace function fn_temp(AB IN NUMBER)
RETURN VARCHAR2 IS
V VARCHAR2(100);
V1 NUMBER(1);
X1 VARCHAR2(100);
begin
V := 'SELECT DUMMY FROM DUAL WHERE 1 = D1';
V1 := AB;
DBMS_SESSION.set_context ('p1_cont', 'v_value', V1);
V := REPLACE(V, 'D1', SYS_CONTEXT('p1_cont', 'v_value'));
DBMS_OUTPUT.PUT_LINE(V);
EXECUTE IMMEDIATE V INTO X1;
DBMS_OUTPUT.PUT_LINE(X1);
RETURN X1;
end;
create or replace context p1_cont using fn_temp;
select sql_id, prev_sql_id from v$session where upper(program) like '%TOAD%' AND OSUSER = 'prnarvek'
SELECT fn_temp(2) FROM DUAL
SELECT fn_temp(1) FROM DUAL
select * from v$sqlarea where UPPER(SQL_TEXT) LIKE 'SELECT DUMMY FROM DUAL%';
SQL_TEXT SQL_ID
SELECT DUMMY FROM DUAL WHERE 1 = 2 3as9g8xuqc4qc
SELECT DUMMY FROM DUAL WHERE 1 = 1 6f1m2mcgc88mt
So what is the of the context ?? Or I was told wrong or i m doing something wrong ...

The Question has been answered.
Replaced SYS_CONTEXT('p1_cont', 'v_value') with 'SYS_CONTEXT(''p1_cont'', ''v_value'')'

Similar Messages

  • Query regarding sys_context function

    Hello
    I have created report with custom folder and parameters are passed using sys_context function. I have few queries regarding this.
    1) How to see actual sql query executed by report. I can see from discover administorator - sql inspector. But it is not showing which is value passed for sys_context parameter. If want to see query with full parameter then what to do? I have also tried to look it from toad - session browser, there also it is not showing parameter value.
    2) If anything special needed to manage sys_context variable. i.e i have executed report with parameter 1 = A and now next time executed with parameter 1 =b. Will it takes proper value, i mean sys_context parameter will be refreshed itself, or need to do somehting..
    Please help me out.
    Thanks in advance

    Hi,
    How to see actual sql query executed by reportSYS_CONTEXT returns values from a namespace. Normally you create a local namespace and values in this namespace can only be retrieved by the session. So there is no way to see the values for a Discoverer session from Toad. Normally, one would create a Discoverer report that returns all the values in your namespace that you can use for debugging.
    If anything special needed to manage sys_context variableNo, once you have set the context in the namespace using DBMS_SESSION.set_context then it is there for the rest of the session.
    Rod West

  • Oracle Discoverer integrate with SSO, SYS_CONTEXT function does not work?

    Here is the summary of steps I have already completed:
    1. Following the Discoverer configuration guide, I modified mod_osso.conf file.
    2. So right now, when I typed
    http:\\host: 7778\discoverer\plus, it will direct me to the single-sign-on page.
    3. Then I login as "orcladmin" (a user in OID), and I will be direct to the standard Connection page.
    4. And I already create a private connection using database user "EDW".
    5. So when I click the private connection, I can run the workbook and see all the data. So far so good.
    6. Now is the problem, since I am going to use VDP to restrict the data that SSO user can see. (for example, "orcladmin" can only see school1 data, but not school2 data) So I need to use some sort of function to return value "orcladmin" in the database so that I can use it to create security context and policy (for example, when "orcladmin" login, the SQL query discoverer generated will have a where clause school_id=1). And according to the configuration guide, if I run the following SQL, I should get back "orcladmin":
    Select SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') from dual;
    But instead, I got null. What is the problem? BTW, when I ran the above SQL, I login into the database as EDWPRD, who owns all the base tables that underlying all the workbooks.
    Thank you in advance for your help!!
    Ren

    Hi Ren
    When you say that you are testing this in SQL presumably you are doing this in SQL Plus. If this is true then the answer you got back is correct because connections to SQL Plus do not use the App Server SSO login and so the CLIENT_IDENTIFIER attribute will always return NULL. Try switching this to OS_USER and you should see the user name from the operating system. Switching this to SESSION_USER will tell you the database user name, while switching it to TERMINAL will tell you the name of the machine that you are logged on, and so on.
    For a full list of attribute values to SYS_CONTEXT take a look here:
    http://www.psoug.org/reference/sys_context.html
    To take advantage of any of this inside Discoverer you would have to register the PL/SQL SYS_CONTEXT function with Discoverer.
    Hope this helps
    Regards
    Michael

  • SYS_CONTEXT usage taking time for first run

    Hi all,
    we have a screen(search) with conditions like make, manufacturing date, region, etc upto 20 conditions. User can restrict the result he wants based on the filters specified. As there are more parameters, a static query was takign a lot of time to return the result.
    We went with dynamic query(only adding the conditions that user has specified in the screen dynamically) and to avoid hard parsing we introduced sys_context.
    we found the result amazing with the subsequent run taking very less time(3-10 secs max) to fetch the results. But the first run (which goes for hard parsing done) is taking a quite a lot of time (close to 10mins).
    we are using Oracle 11g.
    thought this query is used on a regular basis, sometimes the sqlID gets cleared off from the cache due to LRU algorithm. Also sometimes, I see there are more than one SQL ID getting generated for the same set of parameter.
    we cannot use the sql pin option as we would need to pin the sql for every combination of parameter(around 30).
    Could anyone suggest a way of reducing the first run time?
    Thanks in advance..
    Regards,
    Ela

    >
    we cannot use the sql pin option as we would need to pin the sql for every combination of parameter(around 30).
    >
    Then try specifying 'something' for every condition and using '%' for the context values that you don't care about.
    If you don't care about 'empno' use '%' for the context value.
    select * from emp where empno like '%'If you do care use an actual value
    select * from emp where empno like '7369'The 'like' will be treated as '=' for the second case and in the first case it should be optimized out in the actual query.
    That way every query has the same 30 placeholders but the '%' will optimize out the ones you don't want to use.

  • How to view sys_context value in SQL Developer?

    hello
    i can view the results via sqlplus with following statements:
    SELECT SYS_CONTEXT ('empno_ctx', 'empno_attrib') empno_attrib FROM DUAL;
    SELECT * FROM SESSION_CONTEXT;
    both retrieve correct values;
    now, since i work mainly in SQL Developer i wanted to view the results in there as well;
    i ran the procedure in SQL Developer via right-click on the procedure -> run;
    it looked like it ran ok;
    however when i do the above queries nothing is retrieved;
    any suggestions?
    thanks
    rgds

    Hi,
    You can use
    SELECT SYS_CONTEXT ('empno_ctx', 'empno_attrib') empno_attrib into <Variable Name> FROM DUAL;
    dbms_output.putline (<Variable Name>
    So after you execute the procedure. You will be able to see the value in output window.
    Regards,
    Kushal Gupta

  • Sys_context - Error in Oracle 8 Database

    I am using sys_context but it gives error message.
    SELECT SYS_CONTEXT ('userenv', 'host') FROM dual
    ------ it gives following message
    SELECT SYS_CONTEXT ('userenv', 'host') FROM dual
    ERROR at line 1:
    ORA-00904: invalid column name
    Pl. help me urgently
    My database is ORACLE 8.

    Please post your technical questions [url http://forums.oracle.com/forums/forum.jsp?forum=61]here for quick response.
    Regards,
    Anupama
    [url http://otn.oracle.com/sample_code/]OTN Sample Code

  • SYS_CONTEXT in JDeveloper

    I use sys_context and fine grain control in our application. However, sys_context doesn't seem to work fine for application running Java. My procedure to set predicate is as following:
    /* To set select predicate. */
    CREATE OR REPLACE
    FUNCTION SELECT_POLICY
    (P_OWNER VARCHAR2
    ,P_OBJECTNAME VARCHAR2
    RETURN VARCHAR2
    IS
    -- Program Data
    V_PREDICATE VARCHAR2(2000);
    -- PL/SQL Block
    BEGIN --Begin of function
    IF (sys_context('Apps','Responsibility')='Client') THEN
    v_predicate :='CLIENT_ID=sys_context(''Apps'',''Client'')';
    ELSE
    v_predicate := '0=1';
    END IF;
    RETURN(v_predicate);
    END; -- End of function;
    The function work fine in SQL* Plus, but in JSP application written using JDeveloper, the result set:
    rs = dbConnection.executeQuery("select client_id from clients");
    rs.next();
    always return no row.
    However, if we use:
    rs = dbConnection.executeQuery("select client_id from clients");
    rs = dbConnection.executeQuery("select client_id from clients");
    rs.next();
    then the result set woulc obtain correct result.
    It seems that the sys_context function doesn't work in the first query.
    I make us very inconvinient in codding because every query must be execute twice.
    If you have any idea on this, please give me a hand.
    Thanks and regards,
    Hien.
    null

    - Does the value for CURRENT_SCHEMA actually match
    the ownername column for the tables in your IN
    clause? Yes
    >
    - Is there anything different between 9i and 10g?
    E.g. did you have any fine grained access control?Not that I know of, but I am not a DBA so I could not say for sure.
    Were you setting CURRENT_SCHEMA with an ALTER SESSION
    statement in 9i that you have missed in your 10g
    environment?No we do not use any ALTER SESSION statements.
    >
    - What do you get if you run the following?
    select user from dual;
    select sys_context('USERENV','CURRENT_SCHEMA') from
    dual;
    Exactly the same result
    >
    - What do you get if you run the following?
    SELECT tablename, ownername FROM
    mapinfo.mapinfo_mapcatalog
    WHERE tablename IN ('ESU_GRAPHICS', 'STREETS',
    'ASD_STREETS', 'NSG_ARCHIVE_ESU_GRAPHICS');
    380 rows of data including the 4 that I am interested in
    - Can you also show the value of your variable when
    you use a SELECT INTO in PL/SQL... Were you using
    uppercase for USERENV and CURRENT_SCHEMA in PL/SQL
    (there was an incorrect results bug when using
    lowercase attributes in PL/SQL SYS_CONTEXT calls)?I am showing the value of the variable and it is holding the correct value, and yes I am using uppercase USERENV and CURRENT_SCHEMA.
    After more investigation it looks like it is not SYS_CONTEXT, it is using a variable in the WHERE clause. If I set the variable to a hard coded value I still get the same result. If I replace the variable for a hard-coded string in the WHERE clause I get the correct result.

  • SYS_CONTEXT('WEBDB_VPD_CTX','SUBSCRIBER_ID') does not work

    Hi all,
    In Portal30 tables, the column "SUBSCRIBER_ID NUMBER DEFAULT SYS_CONTEXT('WEBDB_VPD_CTX','SUBSCRIBER_ID') NOT NULL" which will be populated with SYS_CONTEXT function does not work while installing Oracle9iAS Portal30 repository.
    All tables that reference this column are empty.
    Any ideas please ?
    Thanks.
    Abdel

    Hi Ren
    When you say that you are testing this in SQL presumably you are doing this in SQL Plus. If this is true then the answer you got back is correct because connections to SQL Plus do not use the App Server SSO login and so the CLIENT_IDENTIFIER attribute will always return NULL. Try switching this to OS_USER and you should see the user name from the operating system. Switching this to SESSION_USER will tell you the database user name, while switching it to TERMINAL will tell you the name of the machine that you are logged on, and so on.
    For a full list of attribute values to SYS_CONTEXT take a look here:
    http://www.psoug.org/reference/sys_context.html
    To take advantage of any of this inside Discoverer you would have to register the PL/SQL SYS_CONTEXT function with Discoverer.
    Hope this helps
    Regards
    Michael

  • Regarding default select clauses executing during OWB Mapping execution -

    All-
    While observing the statements executing during an OWB(11gR2) Mapping execution,by monitoring the session using SQL Developer
    Iam finding the following statements executing multiple times and possibly consuming more of the mapping execution time:-
    SELECT MAX(EXECUTION_AUDIT_ID) FROM ALL_RT_AUDIT_MAP_RUNS WHERE MAP_NAME = :B1
    SELECT SYS_CONTEXT('owb_workspace' , 'workspaceID' ) FROM DUAL
    SELECT nvl2(translate(20040101, 'A1234567890','A'), 'F', 'T') FROM DUAL
    SELECT USER FROM SYS.DUAL
    These statements have no relation to be business logic being implemented.And seem to be generated by OWB default settings.
    Can anyone please let me know how to reduce the frequencey of the above mentioned statements or if possible remove them from the OWB mapping execution.
    So that the mapping would run more faster

    Hi,
    these statement are required to set the runtime audit data. Usually, they do not really impact the performance of a mapping so there is not need to bother about them.
    What causes performance problems is usually the business logic part of the mappings.
    You may purge old runtime metadata manually. Look at the script
    %ORACLE_HOME%\owb\rtp\jrtaudit\owbsys\purge_audit_tables.sqlDocumentation is included.
    Regards,
    Carsten.

  • Sys_context error

    Dear Friends,
    I created a function in database 10g to get OS name in Oracle Forms Version 6i.
    CREATE OR REPLACE FUNCTION fn1 RETURN CHAR IS
    tname VARCHAR2(200);
    BEGIN
    tname := UPPER(sys_context('USERENV','OS_USER'));
    RETURN tname;
    END;
    To get Os name in forms, I used this query
    SELECT FN1 INTO uname FROM DUAL;
    It was working fine, but then stopped suddenly and started giving error message ORA-00904 Invalid Number
    Noting was changed in the form, and from yesterday it started giving this error. Can anybody give me idea about what has happened to it
    Regards,
    Arshad

    hi
    you can define Cursor something like this.I think you do not need to define function for that.
    declare
    cursor
    os_usr is select sys_context('USERENV','OS_USER') from dual;
    begin
    open os_usr;
    fetch os_usr into :item;
    close os_usr;
    end;
    SELECT FN1 INTO uname FROM DUAL; ------ you forgot to put :
    or
    SELECT FN1 INTO :uname FROM DUAL;hope this helps u
    sarah

  • Sys_context('lt_ctx','instant')

    Hi
    I want to know, please, when sys_context('lt_ctx','instant') is null an when is it not null
    Thank you in advance

    Khaled
    These fields are for internal use. What is the application context in which you are using workspace manager that you need to understand these internal values.
    The reason I ask is that we do not want applications to use "hidden" values, because if we change them in the future it will break your application.
    regards
    Arun

  • Use sys_context

    i m using sys_context in sql plus for queries regarding operating system information.
    now i would like to use sys_context in form as select into but oracle says error
    ERROR 201 at line 7
    identifier 'SYS_CONTEXT' must be declare
    can anyone help me.
    asif ali

    I don't know what you mean by "terminal name". If you want to get the user's IP address, you can create a stored function (or create a package, and include the function there), that returns the USERENV sys_context variable. Here is how you create a function on the database:Create or replace Function IP_Address return varchar2 is begin
      Return sys_context('USERENV','IP_ADDRESS');
    End;
    /Now, you can use the function from a SQL select, another procedure, or a form. Here are several examples:
    In SQL:Select IP_Address from dual;In a form:Message('IP Address='||IP_Address);

  • Problem with sys_context

    Hi Friends,
    Oracle:10.2.0.1
    OS:Windows XP
    SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;
    SYS_CONTEXT('USERENV','IP_ADDRESS')
    --------------------------------------------------------------------------------Why it is not giving me IP address. I am giving this command on server machine itself where db exists.
    Regards

    IP address is not available if client is not connecting through TCP (@SID).
    So i can assume since you are directly on server you might not be connected through listener.
    Regards
    Anurag

  • Show the name of instance through of SYS_CONTEXT

    Hi...
    I need rescue the name of instance , but not have privileges on v$ views.
    I use the function sys_context('USERENV','INSTANCE')
    See:
    SQL> select sys_context('USERENV','INSTANCE') from dual;
    SYS_CONTEXT('USERENV','INSTANCE')
    1
    SQL>
    Qeestions:
    1.- How rescue the name of instance?
    2.- The number of instance through SYS_CONTEXT is dynamic?
    Regards
    Hector Gabriel Ulloa Ligarius
    Santiago of Chile
    http://es.groups.yahoo.com/group/desarrolloOracle/

    Thanks to all...
    I want received the name of instance and host
    See :
    SQL> select instance_number , instance_name , host_name from v$instance;
    INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
    1 PROD zbddesa
    But i skip the v$instance, because , not have a privilege
    I need the information, but, by other mode
    Thanks guys
    Regards
    Hector Gabriel Ulloa Ligarius
    Santiago of Chile
    http://es.groups.yahoo.com/group/desarrolloOracle/

  • Regarding sy-index and sy-tabix

    Hi,
    What is the major difference between sy-index and sy-tabix ,
      can you give me one good example with code..
    Regards,
    Reddy.

    Hi,
    SY-TABIX - Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY_INDEX - In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    sy-tabix is the tab index - the index of the record in the internal table you are accessing,
    sy-index is the loop counter.
    If you use a condition in LOOP the sy-index will go from 1 to n, but sy-tabix will refer to the line in the internal table.
    Hope this helps u.
    Thanks,
    Ruthra

Maybe you are looking for

  • Load bulk suppliers

    hi all i want to load suppliers in a bulk to i made one stage table and load all the data there and after that i made one script which pull all the data from here and put into ap_supplier_int and ap_supplier_sites_int. Now the data has been uploaded

  • File-file

    Hello..    I'm working on file to file scenario in XI. I have success fully processed messages in SXMB_MONI but i'm unable to see the output in the output directory. in the receiver adapter i selected like file system NFS message protocal :- file tar

  • How can I make audio come out of the phone speaker rather than the standard speaker in android?

    just like the title says. is this possible? Has anyone sussessfully done this?

  • Nokia e65 sync with Lotus Notes problems

    Hi everyone! I ve got delay in Nokia calendar for 30 minutes in comparison with LN calendar. Need help or advice. BR

  • Multi Popup menu not work

    I use the Dreamweaver to create a web page which have two popup menus. When I run the page, it only the first popup menu is come up. the second one never show up and give me an error undefined is null or not an object. Is anyone can help Thank you