Sign Up

Hey, Dev!
Are you looking for a forum full of active developers to help you?
So if you want to:
➡️ Get answers for your development issues
➡️ Help others
➡️ Write an article
➡️ Get rewarded for your active participation
Then you are going to love this place.

Have an account? Sign In


Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

OrclQA.Com

OrclQA.Com Logo OrclQA.Com Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Blog
  • New Questions
  • Tutorials
    • Oracle Apex
    • Python
  • Tags
  • Users
  • Badges & Points
  • About
Home/Questions/Q 3935
Answered
Greg
Greg

Greg

  • 6 Questions
  • 7 Answers
  • 0 Best Answers
  • 57 Points
View Profile
  • 1
GregProfessional
Asked: December 4, 20202020-12-04T07:06:18+05:30 2020-12-04T07:06:18+05:30

ORA-00920 in SELECT clause when interrogating user role.

  • 1

I have an APEX 20.2 page region based on selecting rows from a table. This works fine, but if I want an administrator to see all records, I would have thought I could add the line:

OR apex_acl.has_user_role(:APP_ID, :APP_USER, ‘ADMINISTRATOR’)

An example would be:

select ALBUM_TITLE,

       YEAR_OF_RELEASE,

       ALBUM_ID,

       ARTIST_ID,

       ALBUM_TYPE_ID,

       COMMENTS,

       COVER_ART_BLOB_CONTENT,

       COVER_ART_MIME_TYPE

  from MUSIC_ALBUMS

  where 0=1 OR apex_acl.has_user_role(:APP_ID, :APP_USER, 'ADMINISTRATOR')

But when I do this, the query returns the error

  • ORA-20999: Failed to parse SQL query! <p>ORA-06550: line 10, column 66: ORA-00920: invalid relational operator</p>

What am I doing wrong?

 

apex
  • 2
  • 45
  • 0
  • 0
  • Share
    • Share on Facebook
    • Share on Twitter
Answer

    2 Answers

    1. Vinish

      Vinish

      • 1 Question
      • 422 Answers
      • 40 Best Answers
      • 2k Points
      View Profile
      Best Answer
      Vinish Legendary
      2020-12-04T10:09:09+05:30Added an answer on December 4, 2020 at 10:09 am

      Some inbuilt packaged functions do not work with SQL queries. You can create a function and can use it in your query. Below is an example:

      create or replace function user_has_role (i_app_id in number, i_app_user in varchar2)
      return varchar2
      is
      l_is_admin boolean := false;
      v_value varchar2(1);
      begin
      l_is_admin := APEX_ACL.HAS_USER_ROLE (
      p_application_id => i_app_id,
      p_user_name => i_app_user,
      p_role_static_id => 'ADMINISTRATOR' );
      
      if not l_is_admin then
      v_value := 'N';
      else
      v_value := 'Y';
      endif;
      
      return v_value;
      
      end;

      Then use the above function in your query:

      select ALBUM_TITLE,
      YEAR_OF_RELEASE,
      ALBUM_ID,
      ARTIST_ID,
      ALBUM_TYPE_ID,
      COMMENTS,
      COVER_ART_BLOB_CONTENT,
      COVER_ART_MIME_TYPE
      from MUSIC_ALBUMS
      where 0=1 OR user_has_role(:APP_ID, :APP_USER) = 'Y'
      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
      • Greg

        Greg

        • 6 Questions
        • 7 Answers
        • 0 Best Answers
        • 57 Points
        View Profile
        Greg Professional
        2020-12-06T06:23:42+05:30Replied to answer on December 6, 2020 at 6:23 am

        That has worked. Thanks.

        • 0
        • Share
          Share
          • Share on Facebook
          • Share on Twitter

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask Question
    Write a Post
    • Recent
    • Answers
    • Engr. SM Hasem

      How to insert item data with default IG in IG ...

      • 0 Answers
    • suriya

      how to download multiple view/table data in one excel

      • 1 Answer
    • Engr. SM Hasem

      How to add one column data to another column in ...

      • 11 Answers
    • Bheem

      What is best way to design school time table?

      • 0 Answers
    • Vinish
      Vinish added an answer Below is an example to download the CSV file using… January 25, 2021 at 12:54 pm
    • afzal
      afzal added an answer step 1--- report query like-- select EMPNO, ENAME, JOB, MGR,… January 25, 2021 at 10:14 am
    • Engr. SM Hasem
      Engr. SM Hasem added an answer Thank you so much sir. January 25, 2021 at 9:22 am
    • Vinish
      Vinish added an answer For all rows? It seems you want to compare the… January 25, 2021 at 6:19 am
    • Vinish
      Vinish added an answer Ok, then create a dynamic action on the bill month… January 25, 2021 at 6:17 am

    Recent Blog Posts

    • Vinish

      Pro*C - Connect to Oracle Database

    • Vinish

      Copy URL to Clipboard on Button Click Examples

    • Vinish

      Find When Your Mac Was Last Shutdown

    • Vinish

      Oracle SELECT Statement

    • Vinish

      Python Append List to List Example

    Explore

    • Home
    • Blog
    • New Questions
    • Tutorials
      • Oracle Apex
      • Python
    • Tags
    • Users
    • Badges & Points
    • About

    © 2020 OrclQA.Com. All Rights Reserved. Privacy Policy