ORA-00911 in Dynamic SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • traceable1

    ORA-00911 in Dynamic SQL

    I am trying to create a stored procedure with dynamic sql referencing
    the V$SESSION table (view). I need to use this dynamically, because
    the procedure will not compile if the user does not have access to
    this table. The $ is what's causing the trouble:

    declare v_sql varchar2(4000);
    begin
    v_sql := 'select * from v$session;';
    execute immediate (v_sql);
    end;
    /


    I've tried \ and double quotes, but they don't work. Any clues?

    THANK YOU!!!!

    trace
  • AnaCDent

    #2
    Re: ORA-00911 in Dynamic SQL

    traceable1 wrote:
    I am trying to create a stored procedure with dynamic sql referencing
    the V$SESSION table (view). I need to use this dynamically, because
    the procedure will not compile if the user does not have access to
    this table. The $ is what's causing the trouble:
    >
    declare v_sql varchar2(4000);
    begin
    v_sql := 'select * from v$session;';
    execute immediate (v_sql);
    end;
    /
    >
    >
    I've tried \ and double quotes, but they don't work. Any clues?
    >
    THANK YOU!!!!
    >
    trace
    declare v_sql varchar2(4000);
    begin
    v_sql := 'select * from v$session';
    execute immediate v_sql;
    end;
    /

    Comment

    • sybrandb@yahoo.com

      #3
      Re: ORA-00911 in Dynamic SQL

      traceable1@hotm ail.com (traceable1) wrote in message news:<8551d8c9. 0404081235.4d92 51c@posting.goo gle.com>...
      I am trying to create a stored procedure with dynamic sql referencing
      the V$SESSION table (view). I need to use this dynamically, because
      the procedure will not compile if the user does not have access to
      this table.
      Untrue. Create the procedure with authid current_user or grant direct
      privilege to the user, and dump the dynamic sql.
      Not sure why you would need any user to do this though.

      Sybrand Bakker
      Senior Oracle DBA

      Comment

      • traceable1

        #4
        Re: ORA-00911 in Dynamic SQL

        This is for an application in which a user can be running multiple
        processes. Some of our clients do not want their users to have access
        to v$session, so the procedure needs to be written in such a manner
        that it uses v$session for clients who will grant the access, and thus
        have the added feature of running multiple processes, or, it they
        choose not to grant the access, the procedure goes another route.
        If they choose not to grant access, the procedure will not compile
        unless it is run via dynamic SQL.


        sybrandb@yahoo. com wrote in message news:<a1d154f4. 0404090534.5399 8fc9@posting.go ogle.com>...
        traceable1@hotm ail.com (traceable1) wrote in message news:<8551d8c9. 0404081235.4d92 51c@posting.goo gle.com>...
        I am trying to create a stored procedure with dynamic sql referencing
        the V$SESSION table (view). I need to use this dynamically, because
        the procedure will not compile if the user does not have access to
        this table.
        >
        Untrue. Create the procedure with authid current_user or grant direct
        privilege to the user, and dump the dynamic sql.
        Not sure why you would need any user to do this though.
        >
        Sybrand Bakker
        Senior Oracle DBA

        Comment

        • The Elemenatlist

          #5
          Re: ORA-00911 in Dynamic SQL

          traceable1@hotm ail.com (traceable1) wrote in message news:<8551d8c9. 0404121025.6c53 9428@posting.go ogle.com>...
          This is for an application in which a user can be running multiple
          processes. Some of our clients do not want their users to have access
          to v$session, so the procedure needs to be written in such a manner
          that it uses v$session for clients who will grant the access, and thus
          have the added feature of running multiple processes, or, it they
          choose not to grant the access, the procedure goes another route.
          If they choose not to grant access, the procedure will not compile
          unless it is run via dynamic SQL.
          >
          Sounds like you want to create a "utility" userid or schema and
          compile the procedure there. Then grant execute on that procedure to
          whoever needs it. You can grant the priv to see v$session to that
          userid so the proc will compile ..

          Note - nobody actually logs in using that userid, they still use their
          own login, they just run a procedure that belongs to somebody else ...
          no big deal .. (btw - you'll probably want to use Public Synonym for
          this as well) ..

          The Elementalist

          Comment

          • traceable1

            #6
            Re: ORA-00911 in Dynamic SQL

            Thank you for you response. Unfortunately, the installation of this
            database schema is run completely by the user. We cannot have the
            clients log in w/dba rights and create another user for this
            procedure.
            Is the $ added in to the name of these views just to make it
            impossible to use in dynamic SQL?

            Thanks,
            trace


            the_elementalis t@hotmail.com (The Elemenatlist) wrote in message news:<d04b9a68. 0404131215.3ab2 e459@posting.go ogle.com>...
            traceable1@hotm ail.com (traceable1) wrote in message news:<8551d8c9. 0404121025.6c53 9428@posting.go ogle.com>...
            This is for an application in which a user can be running multiple
            processes. Some of our clients do not want their users to have access
            to v$session, so the procedure needs to be written in such a manner
            that it uses v$session for clients who will grant the access, and thus
            have the added feature of running multiple processes, or, it they
            choose not to grant the access, the procedure goes another route.
            If they choose not to grant access, the procedure will not compile
            unless it is run via dynamic SQL.
            >
            Sounds like you want to create a "utility" userid or schema and
            compile the procedure there. Then grant execute on that procedure to
            whoever needs it. You can grant the priv to see v$session to that
            userid so the proc will compile ..
            >
            Note - nobody actually logs in using that userid, they still use their
            own login, they just run a procedure that belongs to somebody else ...
            no big deal .. (btw - you'll probably want to use Public Synonym for
            this as well) ..
            >
            The Elementalist

            Comment

            Working...