title: Create simple PL/SQL variable - Use Variable in WHERE clause
body: <p>Thanks for looking...</p>
  
  <p>I've spent hours researching this and I can't believe it's that difficult to do something in PL/SQL that is simple in TSQL.</p>
  
  <p>I have a simple query that joins 2 tables:</p>
  
  <pre><code>     Select DISTINCT
        to_char(TO_DATE('1899123000', 'yymmddhh24')+ seg.NOM_DATE, 'mm/dd/yyyy') AS "Record Date"
      , cd.CODE
      , EMP.ID
      , EMP.SHORT_NAME
  
      FROM
       EWFM.GEN_SEG seg join EWFM.SEG_CODE cd ON seg.SEG_CODE_SK = cd.SEG_CODE_SK
       join EMP on seg.EMP_SK = EMP.EMP_SK
      where NOM_DATE = vMyDate;
  </code></pre>
  
  <p>I use Toad Date Point and I'm querying against an Oracle Exadata source.  The resulting query will be dropped into a visualization tool like QlikView or Tableau.  I'd like to create a simple variable to use the the WHERE clause as you can see in the code.</p>
  
  <p>In this example, NOM_DATE is an integer such as 42793 (2/27/2017) as you can see in the first row "Record Date".  Nothing new here, not very exciting... Until... I tried to create a variable to make the query more dynamic.</p>
  
  <p>I've tried a surprising variety of examples found here, all have failed.  Such as:<br>
  <code>declare
      myDate number(8);
    Begin
      myDate := 42793;</code>
  --Fail ORA-06550 INTO Clause is expected</p>
  
  <pre><code>variable nomDate NUMBER
  DEFINE nomDate = 42793
  EXEC : nomDate := ' &amp; nomDate'
  ...where NOM_DATE = ( &amp; nomDate) ;
  </code></pre>
  
  <p>--ORA-00900: invalid SQL statement</p>
  
  <p>and</p>
  
  <pre><code>variable nomDate NUMBER;
  EXEC nomDate := 42793;
  select count(DET_SEG_SK) from DET_SEG
  where NOM_DATE = :nomDate;
  </code></pre>
  
  <p>--ORA-00900: invalid SQL statement</p>
  
  <p>and several more.. hopefully you get the idea.  I've spent a few hours researching stackoverflow for a correct answer but as you can see, I'm asking you.  From simple declarations like "Var" to more complex " DECLARE, BEGIN, SELECT INTO...." to actually creating Functions, using cursors to iterate the output.... I still can't make a simple variable to use in a Where clause.</p>
  
  <p>Please explain the error of my ways.</p>
  
  <p>--Forlorn SQL Dev</p>