title: Oracle Function with table_name and date as input and Number as output
body: <p>I am trying to test a function, where I am passing a table name and date as input and getting a number as return value.
  I am passing just the date as bind variable (cannot pass table_name )</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION TABLE_TEST (reptable in varchar2, fltdate in varchar2)   RETURN NUMBER
  
          IS
          day_exists VARCHAR2(5 CHAR);
          BEGIN
  
      execute immediate
      'Select CASE WHEN max(day_i)  IS NULL THEN ''NO'' ELSE ''YES'' END FROM '|| reptable ||' WHERE 1 IN
                    (SELECT max(day_i)
                    FROM '|| reptable ||'
                    where day_i = 1 and flt_dptr_Date_d = :1)' into day_exists
                    using fltdate
            ;
              IF day_exists = 'YES' THEN
                return 1;
              END IF;
  
      END TABLE_TEST;        
  </code></pre>
  
  <p>This is how I am testing it</p>
  
  <pre><code>Select TABLE_TEST('FDR_REP', '07/25/2015') from dual;
  </code></pre>
  
  <p>It works properly when I test them individually i.e. when I pass just the table_name or just the date.
  But for some reason it  shows error not a valid month. I don't believe there is any problem with the date thing.</p>
  
  <p>This part works when I just pass the table_name</p>
  
  <pre><code>CREATE OR replace FUNCTION TEST_FUNCTION (name_table IN VARCHAR2) RETURN NUMBER
  
          IS         
  
            rday NUMBER;                
    BEGIN 
     execute immediate  'select day_i 
                  FROM ' || name_table || '
                  WHERE day_i = 1 and rownum = 1' into rday;
  
  
     return rday;
  
    END TEST_FUNCTION;
  </code></pre>