title: PL/SQL function to check length and build a string
body: <p>I have created a VIEW with a column containing aggregated values(stores the output in varchar2 data type). Some of the records exceed the maximum limit, for example varchar2(4000). I was suggested a PL/SQL function to check the length and build a string if necessary..</p>
  
  <p>I've checked, and tried to correct the syntax errors,</p>
  
  <pre><code>CREATE OR REPLACE
  FUNCTION SUBURL(col1 IN VARCHAR2, col2 IN varchar2)
  RETURN varchar2
  IS
  v_result_string varchar2(4000);
  v_length varchar2(4000);
  BEGIN
  IF (length (col1) + length (col2) ... &lt;= 4000) then return col1 || col2 || ...
  END IF; 
  -- build the string and check the length for every column you contatenate
  v_result_string := col1;
  if (length(v_result_string) + length (col2) &gt; 4000) THEN
     -- add as much of col2 as you can up to a total of 4000
     v_length := 4000 - length(v_result_string);
     v_result_string := v_result_string  + substr(col2, 1, v_length);
     return v_result_string;
  end if;
  end suburl;
  </code></pre>
  
  <p>Two errors this time,</p>
  
  <p>Error(7,35): PLS-00103: Encountered the symbol "." when expecting one of the following:     . ( ) , * % &amp; = - + &lt; / > at in is mod remainder not rem =>     &lt;> or != or ~= >= &lt;= &lt;> and or like like2    like4 likec as between || member submultiset The symbol "." was ignored. </p>
  
  <p>Error(7,76): PLS-00103: Encountered the symbol "." when expecting one of the following:     ( - + case mod new null          continue avg count current max min prior sql stddev sum    variance execute forall merge time timestamp interval date          pipe