title: Howto Declare & set variables in PL/SQL
body: <p><strong>PROBLEM</strong></p>
  
  <p>I am struggling to define variables in PL/SQL</p>
  
  <p>in T-SQL it is easy to declare &amp; set variables and reference them in Select query (as below). But how would I do something similar in PL/SQL?</p>
  
  <p><strong>WHAT I"VE TRIED</strong></p>
  
  <p>This seems to be a common question asked multiple times on Stack, but there is no clear answer! the closest I got was <a href="https://stackoverflow.com/questions/10886568/how-do-i-declare-and-use-variables-in-pl-sql-like-i-do-in-t-sql">This</a> link here, but even still I couldn't get it working for me. </p>
  
  <p><strong>MY VARIOUS PL/SQL ATTEMPTS</strong></p>
  
  <pre><code>DECLARE
     myname varchar2(20);
  BEGIN
       myname := 'Tom';
       dbms_output.print_line(myname);
  END;
  
  variable v_date datetime;
  exec :v_date := to_date('01/01/2014','mm/dd/yyyy');
  
  var myname varchar2(20);
  exec :myname := 'Tom';
  </code></pre>
  
  <p><strong>A T-SQL EXAMPLE OF WHAT I AM TRYING TO DO</strong></p>
  
  <pre><code>DECLARE 
      @String VARCHAR(10),
      @Date DATE,
      @Integer As INT
  
  SET @String = 'Hello'
  SET @Date = '20200413'
  SET @Integer = Year(@Date)
  
  SELECT *
  FROM TABLE
  WHERE 1=1
  AND col_a = @String
  AND col_b &gt;= @Year
  </code></pre>