title: Oracle Function Return CHAR
body: <p>I wrote a function (FN_TEST_BE8) that returns a CHAR.</p>
  <pre><code>create or replace FUNCTION FN_TEST_BE8 
  ( P_PARAM1 IN Char
  , P_PARAM2 IN Char
  ) RETURN Char AS 
  BEGIN
    RETURN P_PARAM2;
  END FN_TEST_BE8;
  </code></pre>
  <p>My problem is that when I run it it returns me a VARCHAR2 and for me it's a problem.</p>
  <pre><code>SELECT FN_TEST_BE8('XX','YY') RESULT
    FROM  DUAL
  </code></pre>
  <p><a href="https://i.stack.imgur.com/h3nf8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h3nf8.png" alt="enter image description here" /></a></p>
  <p>Since I use the function in where condiction and this forces me to cast the result:</p>
  <pre><code>SELECT *
    FROM TABLE1
   WHERE CHAR_2 = CAST(FN_TEST_BE8('XX','YY') AS CHAR(2));
   --  DOES NOT WORK --&gt; WHERE CHAR_2 = FN_TEST_BE8('XX','YY');
  </code></pre>
  <p>The 'TABLE 1.CHAR_2' field is defined as CHAR (2).
  If I use the WHERE CONDICTION commented with the label &quot;NOT WORK&quot; the statments does not extract data.
  If I force the CAST on the result of the FUNCTION, the statements extracts the data correctly.</p>
  <p>There are two point I don't understand</p>
  <ul>
  <li>The 'char' datatype is supported by PL/SQL. Why does the function not extract a CHAR but a VARCHAR2?</li>
  <li>I would have expected Oracle Database automatically converts a value from one CHAR datatype to VARCHAR2 datatype</li>
  </ul>
  <p>Thanks for your help.</p>