title: Oracle function to replace all names to their nick names?
body: <p>I have a table called nicknames</p>
  <pre><code>Names   nickname
  vikram  vik
  James   Jim
  Robert  Bob
  Charles Dick
  Richard Dick
  Rich    Dick
  </code></pre>
  <p>Want to create an Oracle function to replace names with their nicknames from the table in an input string</p>
  <p>func_nicknames('vikram, James, Rajesh, Robert') should return the value 'vik, Jim, Rajesh, Bob'</p>
  <pre><code>CREATE OR REPLACE FUNCTION func_nicknames( in_val varchar2)
  RETURN VARCHAR2
  IS
  O_VAL VARCHAR2(100) := in_val;
  BEGIN
  SELECT REPLACE(O_VAL,t.name,t.nickname) INTO O_VAL FROM nicknames t;
  RETURN(O_VAL);
  END func_nicknames;
  </code></pre>
  <p>The above code is throwing an error.</p>
  <p>In SQL Server, the below code works fine:</p>
  <pre><code>CREATE OR ALTER FUNCTION getNicknames(@val NVARCHAR(MAX))
  RETURNS NVARCHAR(MAX) AS
  BEGIN
      DECLARE @result NVARCHAR(MAX);
      SET @result = @val;
      SELECT @result = REPLACE(@result, name, nickname)
      FROM nicknames;
      RETURN @result;
  END;
  </code></pre>
  <p>Similar code I want to create in Oracle.
  Working code for oracle:</p>
  <pre><code>CREATE OR REPLACE FUNCTION getNicknames(in_val VARCHAR) RETURN VARCHAR IS
  ret VARCHAR(2000);
  v VARCHAR(2000);
  CURSOR cur IS SELECT SRC_VAL_STR, TGT_VAL_STR FROM nicknames;
  BEGIN
      ret := in_val;
      FOR x IN cur
      LOOP
      SELECT REPLACE(ret, x.name, x.nickname) INTO v FROM DUAL;
      ret := v;
      END LOOP;
      RETURN ret;
  END;
  </code></pre>