0

I need to check from Java if a certain user has at least one group membership. In Oracle (12 by the way) there is a big able that looks like this:

DocId  | Group
-----------------
    1  | Group-A
    1  | Group-E
    1  | Group-Z
    2  | Group-A
    3  | Group-B
    3  | Group-W

In Java I have this information:

docId = 1
listOfUsersGroups = { "Group-G", "Group-A", "Group-Of-Something-Totally-Different" }

I have seen solutions like this, but this is not the approach I want to go for. I would like to do something like this (I know this is incorrect syntax) ...

SELECT * FROM PERMSTABLE WHERE DOCID = 1 AND ('Group-G', 'Group-A', 'Group-Of-Something-Totally-Different' ) HASATLEASTONE OF Group

... and not use any temporary SQL INSERTs. The outcome should be that after executing this query I know that my user has a match because he is member of Group-A.

Marged
  • 10,577
  • 10
  • 57
  • 99

1 Answers1

1

You can do this (using IN condition):

SELECT * FROM PERMSTABLE WHERE DocId = 1 AND Group IN 
            ('Group-G', 'Group-A', 'Group-Of-Something-Totally-Different')
karthik manchala
  • 13,492
  • 1
  • 31
  • 55