Tuesday 15 April 2014

Oracle function with table as input parameter -


How can you create a function in Oracle that has a table in the form of an input parameter and returns the string? Here's my attempt, but an error is returned:

  create temp_table type or object as an object (col_name varchar (100)); Create or change col_table type as table of temp_table; Create / change COLUMN_HEADERS (col_name in col_table) Return VARCHAR2 return_string is VARCHAR2 (4096); BEGIN return_string: = ''; I for 1 .. col_name.count loop return_string: = return_string || '' '' || Col_name (i) || '' As '' Regexp_replace (col_name (i), '[\ +]', '_'); If I & lt; Col_name.count again return_string: = return_string || ','; end if; End loop; Return return_string; End; I get the following:  
  Error (9): PL / SQL: I -00306: Wrong number or type of arguments in call '||'   

What are the numbers from this line:

  return_string: = return_string || '' '' || Col_name (i) || '' As '' Regexp_replace (col_name (i), '[\ +]', '_');   

My guess is that col_name (i) does not return a string, but uses VALUE () or TO_CHAR () Has other errors? Does anyone know how to debug it?

"post-text" itemprop = "text">

When you reference an index in the table using col_name (I) , then you The table property of the index needs to be referenced as col_name (i) .col_name . In your case you used the col_name as the object and as your function argument. For clarity you can change it compiled for me:

  type temp_table is the object to create or change (col_name varchar (100)); / Type or type col_table is the table of temp_table; Create / change COLUMN_HEADERS (col_name in col_table) return VARCHAR2 is return_string varchar2 (4096); BEGIN return_string: = ''; I for 1 .. col_name.count loop return_string: = return_string || '' '' || Col_name (i) .col_name || '' As '' Regexp_replace (col_name (i) .col_name, '[\ +]', '_'); If I & lt; Col_name.count again return_string: = return_string || ','; end if; End loop; Return return_string; End;    

No comments:

Post a Comment