title: How do I query a table using a variable?
body: <p>I'm trying to do the SQL equivalent of this in Oracle. Basically, I need to put values from a given column in a variable, then use those variables to query tables</p>
  
  <pre><code>DECLARE @transID INT
         ,@pol_no varchar(20)
  
  SELECT @pol_no = 'xxx'
  
  SELECT @transID = p.transID 
    FROM policy_dimension p 
   WHERE p.pol_no = @pol_no
  
  SELECT pd.* 
    FROM property_dimension pd 
   WHERE pd.trans_id = @transID
  </code></pre>
  
  <p>I've tried this</p>
  
  <pre><code>DECLARE 
    policy_no VARCHAR2(20);
    transaction_id int;
  BEGIN
    :policy_no := '20P0000175';
  
    SELECT pd_transaction_id
      INTO transaction_id
      FROM policy_dimension p
     WHERE p.pd_policy_no = :policy_no
       AND ROWNUM = 1 
     ORDER BY pd_transaction_id desc;
  
     BEGIN
       SELECT *
         FROM property_dimension pd
        WHERE pd.pd_transaction_id = :transaction_id;
     END;
  
  
  END;
  /
  </code></pre>