1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

No XOR in SQL?

Discussion in 'SQL PL/SQL' started by reylliam, Feb 9, 2011.

  1. reylliam

    reylliam Active Member

    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    80
    Location:
    Austin, TX
    Hello,

    It looks like I have just discovered XOR is not an SQL keyword.

    While I have no trouble coding it the long way with ANDs and ORs if necessary, is there no XOR keyword equivalent to make this tidier?

    Thanks,
    Jason
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,345
    Likes Received:
    347
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Re: No XOR?

    What, exactly, are you attempting to implement? The UTL_RAW package offers BIT_XOR which can be used with raw values; the SDO_GEOM package offers SDO_XOR for spatial geometry objects. A bit of explanation is in order here to understand what you're doing and whether or not either of those packaged offerings will help.
     
  3. reylliam

    reylliam Active Member

    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    80
    Location:
    Austin, TX
    Re: No XOR?

    Ah, well, really it was simply something like the below. Just a quick test:

    Code (SQL):
    ...
    AND ( A.Q_ID IN ( 1,2,3,4 ) XOR B.Q_ID IN ( 1,2,3,4 ) )
    ...
     
  4. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,345
    Likes Received:
    347
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Re: No XOR?

    There is no 'pure' XOR conditional in Oracle, or in the SQL Standard if I remember correctly, therefore implementing the above will require you to either

    a) write your own XOR function and overload it to take numeric values, string values, numeric value lists or string value lists
    b) do this the 'old fashioned way' and code it with ANDs and ORs
     
  5. reylliam

    reylliam Active Member

    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    80
    Location:
    Austin, TX
    Re: No XOR?

    Well shucks.. ;)

    Thanks kindly for reconfirming.
     
  6. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,345
    Likes Received:
    347
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Re: No XOR?

    If you choose the function route you'll have it for later implementations and won't need to rewrite the code over and over again whenever you need it.
     
  7. rajavu

    rajavu Forum Guru

    Messages:
    815
    Likes Received:
    52
    Trophy Points:
    610
    Location:
    @ Bangalore , India