title: Oracle - Using variables in SELECT statement
body: <p>My background in SQL is SQL Server, so forgive me for using Oracle in a similar way to it. I need to use a variable so I can use the value stored in it to perform a separate <code>SELECT</code> query. My aim is to find a percentage value and the variable will hold the total value of a table.</p>
  
  <pre><code>DECLARE
    v_Count INT;
  
  BEGIN
  
  --get total rows
  SELECT COUNT(OrderID)
  INTO v_Count
  FROM OrderedEquipment;
  
  --find percentage of equipment ordered
  SELECT a.Equip_Name, COUNT(b.EquipmentID), ((COUNT(b.EquipmentID)*1.0)/(v_Count*1.0)*100)
  FROM Equipment a
  LEFT OUTER JOIN OrderedEquipment b ON a.EquipmentID = b.EquipmentID
  GROUP BY a.Equip_Name;
  
  END;
  </code></pre>
  
  <p>SQL Developer will then throw this error:</p>
  
  <pre><code>Error report -
  ORA-06550: line 10, column 1:
  PLS-00428: an INTO clause is expected in this SELECT statement
  </code></pre>
  
  <p>I tried looking for solutions to this, and stumbled on to this post:</p>
  
  <p><a href="https://stackoverflow.com/questions/5653423/how-do-i-use-variables-in-oracle-sql-developer">How do I use variables in Oracle SQL Developer?</a></p>
  
  <p>But none of the answers really solved my problem. I tried using the <code>bind</code> variables example but that didn't work.</p>