0

Just like some questions here, (a== 1 && a ==2 && a==3) had been proven that it can be evaluated to true in javascript and I'm just wondering if there is also a way in PL/SQL to evaluate it also to true.

Miracle
  • 387
  • 5
  • 31
  • 1
    If `a` is a number column, then no, your expression can never evaluate to true. And if `a` is not numeric, I don't think the query would even run. Maybe on MySQL it could be true. – Tim Biegeleisen Mar 19 '18 at 02:19
  • 1
    how can a variable have 3 different values at the same time ? – Niamatullah Bakhshi Mar 19 '18 at 02:21
  • @TimBiegeleisen ahh. thanks bro. I thought it can by some way. – Miracle Mar 19 '18 at 02:29
  • @NiamatullahBakhshi there are things that you can do outside the box. – Miracle Mar 19 '18 at 02:30
  • You need to check [This](https://stackoverflow.com/questions/15817932/javascript-multiple-values-in-variable). There is no way outside the box as far as variables with distinct values is concerned. – Niamatullah Bakhshi Mar 19 '18 at 02:34
  • you need to check [this](https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever-evaluate-to-true/48270314#48270314) too. – Miracle Mar 19 '18 at 02:39
  • 1
    IMHO those answers (craftily) use ambiguous human language and data types to arrive at an answer. In a purely logical sense that expression can never be true, but as you did not specify the data type of `a`, we already have an answer below that makes that expression true. – Nick.Mc Mar 19 '18 at 04:13
  • Also... PL/SQL doesn't use `==`, it uses `=` so I guess we can be certain it will only ever evaluate to a syntax error. – Nick.Mc Mar 19 '18 at 04:16
  • did I say that i'll use == in PL/SQL? @Nick.McDermaid – Miracle Mar 19 '18 at 04:58
  • That's the code sample that you posted. It's pretty important that you post correct code samples. – Nick.Mc Mar 19 '18 at 05:00
  • reread my post. – Miracle Mar 19 '18 at 05:34
  • 2
    I think this could be evaluated as true in many languages. "a" doesn't need to specifically be a variable. It can be any expression, and functions could return something to make this true, as Connor shows. – Scott Mar 22 '18 at 11:38

1 Answers1

16

Just for fun of course

SQL> create or replace
  2  package pkg is
  3    x int := 0;
  4  end;
  5  /

Package created.

SQL>
SQL> create or replace
  2  function a return number is
  3  begin
  4    pkg.x := pkg.x + 1;
  5    return pkg.x;
  6  end;
  7  /

Function created.

SQL>
SQL>
SQL> set serverout on
SQL> begin
  2   if a = 1 and a = 2 and a = 3 then
  3     dbms_output.put_line('BINGO!');
  4   end if;
  5  end;
  6  /
BINGO!

PL/SQL procedure successfully completed.
Connor McDonald
  • 10,418
  • 1
  • 11
  • 16
  • 5
    I just upvoted the downvote. Great answer that illustrates that even if humans are ambiguous, databases are not!! – Nick.Mc Mar 19 '18 at 04:15