title: How to write dynamic sql in Oracle Stored procedure?
body: <p>Basically in my update sql query column names going to be dynamic like </p>
  
  <pre><code>update bi_employee set &lt;this_is_dynamic_column&gt; where emp_id = 12
  </code></pre>
  
  <p>Below is the stored procedure that I have written so far.</p>
  
  <pre><code>CREATE OR replace PROCEDURE Sp_run_employee_updates
  IS
    CURSOR c_emp IS
      SELECT *
      FROM   BI_EMPLOYEE_UPDATE
      WHERE  EFFECTIVE_DATE = To_date('30-Apr-2012', 'dd-mm-yy');
  BEGIN
      FOR employee_update IN c_emp LOOP
          declare update_sql varchar2(225);
          update_sql := 'UPDATE BI_EMPLOYEE   SET     '
                        || employee_update.column_name
                        || '= employee_update.new_value  WHERE     emp_id = '
                        || employee_update.employee_id;
      END LOOP;
  END; 
  </code></pre>
  
  <p>Its giving me foloowing errors</p>
  
  <blockquote>
    <p>Error(17,13): PLS-00103: Encountered the symbol "=" when expecting one of the following:     constant exception      table long double ref    char time timestamp interval date binary national character    nchar The symbol "" was substituted for "=" to continue. </p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>Error(22,5): PLS-00103: Encountered the symbol "UPDATE" when expecting one of the following:     begin function pragma procedure subtype type      current cursor delete    exists prior The symbol "begin" was substituted for "UPDATE" to continue. </p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>Error(31,6): PLS-00103: Encountered the symbol ";" when expecting one of the following:     loop </p>
  </blockquote>