Create Or Replace Function Ft_getsql( as_coopid char , as_applgroup char , as_function varchar2 ) Return varchar2
Is
type Cursor_data is Ref Cursor;
Cur_data Cursor_data;
ls_sql		varchar2(4000);
ls_temp	varchar2(4000);
Begin
	ls_sql := '';
	If as_coopid Is Null Then
		Return ls_sql;
	End If;
	If as_applgroup Is Null Then
		Return ls_sql;
	End If;
	
	open Cur_data for
		select nvl( trim( sql_desc ) , '' ) as sql_desc
		from cmsql
		where coop_id = as_coopid
		and applgroup_code = as_applgroup
		and function_code = as_function 
		order by seq_no ;
		Loop
			fetch Cur_data Into ls_temp ;
			Exit when Cur_data%notfound;

			ls_sql		:= ls_sql || ' ' || ls_temp ;

		End loop;
	Close Cur_data;

 	Return trim( ls_sql );

End ;
/