title: How to use variables in Oracle PL/SQL Function
body: <p>I'm sorry upfront because this question seems to easy.
  I have this function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION Costs_MK (VIEWNAME IN VARCHAR2 , WHERE_CLAUSE IN VARCHAR2) 
  RETURN VARCHAR2
  
  IS
     v_Costs VARCHAR2 (500);
  
  BEGIN
  
    Select Listagg(Costs, ';' ) WITHIN GROUP (ORDER BY Costs)
    into v_Costs
    from (select distinct (Costs) 
          from VIEWNAME
          where WHERE_CLAUSE);
  
    RETURN v_Costs;
  END Costs_MK;
  </code></pre>
  
  <p>However I get the Error-Message:</p>
  
  <blockquote>
    <p>Error(13,30): PL/SQL: ORA-00920:  invalid relational operator</p>
  </blockquote>
  
  <p>I even can't compile it. If I use the exact values for Viewname and Where_clause I get the desired result.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>/edit: Line 13 is </p>
  
  <pre><code>from VIEWNAME
  </code></pre>
  
  <p>/edit #2:
  Thanks guys. You helped me a lot. I didn't thought about dynamic sql in the first step, so thanks for the refresher ;). </p>