Doubt of SQL.

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Thu, 26 Jul 2007 10:16 am

Save big guys oraclianos.

Everybody was worried about a stop, that I came across today.

Did the following select: SELECT USER, T6155.* FROM FORMA_PAGAMENTO_TIPO_TARIFA WHERE T6155 T6155.CD_OPERACAO_TRANSPORTE IN (SELECT T6439.CD_OPERACAO_TRANSPORTE FROM USUARIO_PROGRAMA_OPE_TPT WHERE T6439 T6439.CD_USUARIO = USER AND T6439.CD_PROGRAMA = ' LTCC1110 ') OR USER = ' CAMCOM01 ' AND T6155.NR_SEQ_FORMA_PGT_TARIFA = 11426 however I was connected with the enterprise user, and he was returning all records.

Then I changed my sql for the following: SELECT USER, T6155.* FROM FORMA_PAGAMENTO_TIPO_TARIFA WHERE T6155 (T6155.CD_OPERACAO_TRANSPORTE IN (SELECT T6439.CD_OPERACAO_TRANSPORTE FROM USUARIO_PROGRAMA_OPE_TPT WHERE T6439 T6439.CD_USUARIO = USER AND T6439.CD_PROGRAMA = ' LTCC1110 ') OR USER = ' CAMCOM01 ') AND T6155.NR_SEQ_FORMA_PGT_TARIFA = 11426 and returned only the record that I wanted.

Well the question in question is what is the difference of my sql ´ s, when I put OR without parenthesis he interprets what is below?
meguelito
Location: Santa Catarina

Att.:
Alan Juliano Metzger
Programador Oracle
Inside System Informática
Msn/E-mail: alanjuliano@yahoo.com.br

Poston Thu, 26 Jul 2007 12:11 pm

That there is a logical problem. The rows are returned if all conditions specified in the where result in True. So you see, evaluate:
Code: Select all
Verdadeiro AND Verdadeiro OR Falso
may give different results to assess
Code: Select all
Verdadeiro AND (Verdadeiro OR Falso)
tom
Location: Guarulhos - SP

Poston Thu, 26 Jul 2007 1:11 pm

Exactly. See what's in parentheses is executed BEFORE.
dr_gori
Location: Portland, OR USA

Thomas F. G

Você já respondeu a dúvida de alguém hoje?
http://glufke.net/oracle/search.php?search_id=unanswered


  • See also
    Replies
    Views
    Last Post


    Return to SQL

    Who is online

    Users browsing this forum: Bing [Bot] and 3 guests