Function returning error text validation

Hi,
I have a page where i can insert/update user, organisation, responsible.
Organisation can be nullable.
Only one user at a time can be responsible for a organisation.
To check this responsible validation i made a function returning error text validation as follow:
BEGIN
FOR c IN (SELECT usr_spa
FROM kpi_users
WHERE usr_org_id = :p22_usr_org_id
LOOP
IF upper(:p22_usr_spa) = upper('YES') and upper(c.usr_spa) = upper('YES')
THEN
RETURN 'A user is already responsible for this organisation'||'!';
END IF;
END LOOP;
END;
The validation works fine.
But it goes wrong when i want to insert a new user, without assigning him to an organisation.
I get following message:
ORA-01722: invalid number
ERR-1024 Unable to run "function body returning text" validation.
Can someone please help me solve this problem?
Thanks

Hi,
try:
BEGIN
FOR c IN (SELECT usr_spa
FROM kpi_users
WHERE usr_org_id = nvl(:p22_usr_org_id,-1)
LOOP
IF upper(:p22_usr_spa) = upper('YES') and upper(c.usr_spa) = upper('YES')
THEN
RETURN 'A user is already responsible for this organisation'||'!';
END IF;
END LOOP;
END;This assumes that :p22_usr_org_id could be null and converts this to -1 (pick another default value if this may exist as an id). It is possible that the statement would otherwise be seen as WHERE usr_org_id = null which is invalid.
or you could do:
BEGIN
IF :p22_usr_org_id IS NOT NULL THEN
FOR c IN (SELECT usr_spa
FROM kpi_users
WHERE usr_org_id = :p22_usr_org_id
LOOP
IF upper(:p22_usr_spa) = upper('YES') and upper(c.usr_spa) = upper('YES')
THEN
RETURN 'A user is already responsible for this organisation'||'!';
END IF;
END LOOP;
END IF;
END;As this would stop the validation running if the :p22_usr_org_id is null.
Or, you could just make your validation conditional on p22_usr_org_id not being null?
Andy

Similar Messages

  • Function returning error - change notification

    I have a function returning error text. When error occurs I get the message
    'xx error has occurred' on the screen (in notification). Is there a way to control the message text so I can display different text?

    It's something like this:
    DECLARE l_code zip.code%TYPE;
    got_error varchar2(1) := 'N';
    l_check_fld varchar2(30000);
    l_error_fld varchar2(32000);
    vErrorFields varchar2(1000);
    CURSOR check_zip IS
    select ''
    from zip
    where code = l_code;
    BEGIN
    apex_collection.create_or_truncate_collection('ZIP');
    FOR i IN 1 .. apex_application.g_f03.COUNT LOOP
    vErrorFields := '';
    /* Code MUST be entered */
    if (apex_application.g_f03(i) is null and
    (apex_application.g_f04(i) is not null or
    apex_application.g_f05(i) is not null))then
    got_error := 'Y';
    vErrorFields := vErrorFields || ',f03';
    l_error_fld := l_error_fld || 'Row ' || to_char(i) || ':' ||' <span style="color: red">Code cannot be <strong>blank.</strong></span><br>';
    end if;
    END LOOP;
    if got_error = 'N' then
    apex_collection.delete_collection('ZIP');
    end if;
    RETURN l_error_fld;
    END;

  • To_numer function return error in pl/sql

    Hello,
    I don't have a prob when running select to_number('1234.56') from dual, the numer contains digit decimal
    But this stm return error Invalid number in procedure unless I use to_number('1234.56','9999999.99')
    Please help me out.
    Do I have to set parameter in DB ?
    BTW: my NLS_NUMERIC_CHARACTER is set to '.,'
    Thanks.

    to_numer function return error in pl/sql
    hlthanh wrote:
    Hello,
    I don't have a prob when running select to_number('1234.56') from dual, the numer contains digit decimal
    But this stm return error Invalid number in procedure unless I use to_number('1234.56','9999999.99')
    Please help me out.
    Do I have to set parameter in DB ?
    BTW: my NLS_NUMERIC_CHARACTER is set to '.,'
    Thanks.Handle:      hlthanh
    Status Level:      Newbie
    Registered:      Mar 7, 1999
    Total Posts:      94
    Total Questions:      60 (38 unresolved)
    so many questions & so few answers.
    How SAD!

  • ODBC functions SQLExecDirectW and SQLExecute functions return error:"DIAG [22001] [Microsoft][SQL Server Native Client 10.0]String data, right truncation (0) "

    Problem Description:
    ODBC functions SQLExecDirectW and SQLExecute functions return error:”DIAG [22001] [Microsoft][SQL Server Native Client 10.0]String data, right
    truncation (0) “. When we enable tracing in the ODBC administrator, in the SQL.log we see that values for the arguments: ColumnSize, BufferLength, and StrLen_or_IndPtr of ODBC function SQLBindParameter are not being displayed.
    Environment Used:
    OS: Microsoft Windows Server 2003 R2 Standard x64 Edition.
    Complier: Microsoft Visual Studio 2008 SP1 for x64.
    Database: Microsoft SQL Server 2008
    MDAC: Microsoft Data Access Components SDK 2.8
    Note: This problem is seen only in our 64bit application. However, in 32bit
    SQLExecDirectW and SQLExecute functions return successfully.
    As we could not find the values of 6<sup>th</sup>, 9<sup>th</sup> and 10<sup>th</sup> arguments(ColumnSize,
    BufferLength, and StrLen_or_IndPtr) passed to
    SQLBindParameter in the ODBC traces for 64bit, we are not sure whether the values for the above mentioned arguments are received correctly by SQLBindParameter or not. This information would help us to debug further. So, could you please let us know why
    these values are not displayed.
    1)Here is the extract of the SQL.log file for 32bit where the values for SQLULEN , SQLLEN and SQLLEN* are displayed properly:
    PR0CNFG 1028-15f0 ENTER SQLBindParameter
    HSTMT 0x006FBDD8
    UWORD 1
    SWORD 1 <SQL_PARAM_INPUT>
    SWORD -8 <SQL_C_WCHAR>
    SWORD -9 <SQL_WVARCHAR>
    SQLULEN 23
    SWORD 0
    PTR 0x0595EBBA
    SQLLEN 46
    SQLLEN * 0x05A5FB00
    2)Here is the extract of the SQL.log file for 64bit where the values for SQLULEN , SQLLEN are not displayed properly and
    SQLExecDirectW function return error:”DIAG
    [22001] [Microsoft][SQL Server Native Client 10.0]String data, right truncation (0) “. :
    PR0CNFG a78-fe4 ENTER SQLBindParameter
    HSTMT 000000000431D2F0
    UWORD 1
    SWORD 1 <SQL_PARAM_INPUT>
    SWORD -8 <SQL_C_WCHAR>
    SWORD -9 <SQL_WVARCHAR>
    SQLULEN SQLULEN SWORD 0
    PTR 0x0000000005364EFA
    SQLLEN SQLLEN
    SQLLEN * SQLLEN *
    PR0CNFG a78-fe4 EXIT SQLBindParameter with return code 0 (SQL_SUCCESS)
    HSTMT 000000000431D2F0
    UWORD 1
    SWORD 1 <SQL_PARAM_INPUT>
    SWORD -8 <SQL_C_WCHAR>
    SWORD -9 <SQL_WVARCHAR>
    SQLULEN SQLULEN SWORD 0
    PTR 0x0000000005364EFA
    SQLLEN SQLLEN SQLLEN *

    Hi Nalsr,
    From my research, I found:
    "[Microsoft][ODBC SQL Server Driver]String
    data right truncation" error may be returned from a call to
    SQLBindParameter if the size of the string parameter being used is greater than the size of the column being compared to. In other words if the
    string size of the <expression> to the left of the <comparison_operator> is less than the
    string size of the <expression> to the
    right, ODBC may return this error.
    The resolution is to make the string size of the <expression> to the
    right of the <comparison_operator> less than or equal to the
    string size of the <expression> on the left.
    It is difficult to track down this type of problem when third party development applications are being used. ODBC Trace can be used to help determine if this problem is occuring.
    Here is an example where the customer has submitted a query "select count(*) from type1 where type1 = ?", type1 is varchar(5) and the
    data type being passed by the application is char[9].
    Here is the relevant portion of the trace. The following information from the "exit" of SQLDescribeParam
    SWORD * 0x0095e898 (12)
    UDWORD * 0x0095e880 (5)
    Maps to the following with the actual value in parenthesis - SQL_VARCHAR Size 5:
    SQLSMALLINT *DataTypePtr
    SQLUINTEGER *ParameterSizePtr
    The "exit" value from SQLBindParameter provides the following
    information:
    SWORD 1 <SQL_PARAM_INPUT>
    SWORD 1 <SQL_C_CHAR>
    SQL Data Type SWORD 12 <SQL_VARCHAR>
    Parameter Size UDWORD 5
    SWORD 0
    Value PTR 0x0181c188
    Value Buffer Size SDWORD 5
    String Length SDWORD * 0x0181c103 (9)
    The string length parameter is the length of the
    string being bound to the parameter, in this instance there is a size mismatch which results in the SQLError and the SQLErrorW with the message "[Microsoft][ODBC SQL Server
    Driver]String data
    right truncation" .
    Hope this could be helpful.
    Best regards,
    Halin Huang

  • "Error: No valid packages (-9997)" Tiger installation disc

    When attempting to install tiger on my imac g4, it gets to about 65% on the essentials bar then errors, something like BomFatal error some files are not written properly. My harddrive repairs fine but the Mac OSX disc, when i run permission verification first aid returns "Error: No valid packages (-9997)". The support page was not paticularly helpful in this respect, and the folks here tend to be more helpful anyway.
    Thanks in advance.

    Here's a post with replies that cover your issue.
    Posting in the Airport for Windows forum will not get the help you need. I found this post by accident.
    Perhaps, (if this is what you have) the iMac Flat Panel forum would help you more.
    DALE

  • Page Validation - Function Returning Boolean - Check for NULL

    I have 3 Page Validations which all fire on "When Button Pressed" = "Submit".
    <br><br>
    Number 1 is of type "Item specified is NOT NULL" for "P199_BUSINESS_UNIT1".
    <br>
    Number 2 is of type "Item specified is NOT NULL" for "P199_BUSINESS_UNIT2".
    <br>
    Number 3 is of type "Function Returning Boolean" and has the following code:
    <br><br>
    IF :P199_BUSINESS_UNIT1 IS NULL   AND
       :P199_BUSINESS_UNIT2 IS NULL  THEN
        RETURN FALSE ;
    ELSE
        RETURN TRUE  ;
    END IF ;<br>
    When P199_BUSINESS_UNIT1 is NULL and P199_BUSINESS_UNIT2 is NOT NULL, I get the Error from Validation 1. Perfect.
    <br>
    When P199_BUSINESS_UNIT1 is NOT NULL and P199_BUSINESS_UNIT2 is NULL, I get the Error from Validation 2. Perfect.
    <br>
    When P199_BUSINESS_UNIT1 is NOT NULL and P199_BUSINESS_UNIT2 is NOT NULL, I don't get an Error Message. Perfect.
    <br><br>
    When P199_BUSINESS_UNIT1 is NULL and P199_BUSINESS_UNIT2 is NULL, I get Error Message 1 & 2, <strong>but nothing from 3.</strong>
    <br><br>
    If I change the code to:
    <br><br>
    IF :P199_BUSINESS_UNIT1 = '01'   AND
       :P199_BUSINESS_UNIT2 = '01'  THEN
        RETURN FALSE ;
    ELSE
        RETURN TRUE  ;
    END IF ;<br>
    and change both values to '01', I get the appropriate Error Message.
    <br><br>
    What is going on? Is there some reason I can't check for NULL in a Function Returning Boolean?

    Scott,
    <br><br>
    Instead of adding the Validations, I changed my code from:
    <br><br>
    IF :P199_BUSINESS_UNIT1 IS NULL   AND
       :P199_BUSINESS_UNIT2 IS NULL  THEN
        RETURN FALSE ;
    ELSE
        RETURN TRUE  ;
    END IF ;
    <br>to the following and got the desired results:
    <br><br>
    IF  REPLACE(:P199_BUSINESS_UNIT1,<strong>'%null'</strong> || '%',NULL) IS NULL   AND
        REPLACE(:P199_BUSINESS_UNIT2,<strong>'%null'</strong> || '%',NULL) IS NULL  THEN
        RETURN FALSE ;
    ELSE
        RETURN TRUE  ;
    END IF ;<br>
    Note that I changed the word REPLACE to upper case and the second occurrence of the word NULL to upper case to accentuate the fact that the '%null' is case sensitive, using "%NULL' does not work, it has to be "%null' in lower case.
    <br><br>
    <strong>Thanks for your help.</strong>

  • The database error text is: ORA-01843: not a valid month

    I am trying to use a date field as a query filter and I keep getting the
    following error:
    A database error occurred. The database error text is: ORA-01843: not a
    valid month. (WIS 10901).
    When I remove the query filter and run the query it works as
    expected. I want to be able to allow the users to use the date field in order
    to select a date range. Can someone provide me with some information on how to
    resolve this issue.

    SQL> SELECT (to_char(tO_date('09/29/2006', 'mm/dd/yyyy'))||':'||TO_CHAR(systimestamp,'hh24:mi:ss:ff6'))
      2  FROM dual;
    (TO_CHAR(TO_DATE('09/29/2006
    29-SEP-06:01:33:09:023000
    But you want mm/dd/yyyy hh24:mi:ss:ff6 format then use TO_CHAR function for format specifier
    SQL> SELECT to_char(to_timestamp((to_char(tO_date('09/29/2006', 'mm/dd/yyyy'))||':'||TO_CHAR(systimestamp,'hh24:mi:ss:ff6')), 'dd/mm/yyyy hh24:mi:ss:ff6'),'mm/dd/yyyy hh24:mi:ss:ff6')
      2  FROM DUAL
      3  /
    TO_CHAR(TO_TIMESTAMP((TO_CHAR
    09/29/0006 01:40:27:113000
    SQL> Khurram

  • Application builder Error: Windows SDK function returned an error. (Error code -12) *** End Error Report

     try to create an installer in Labview 8.6.  The build fail and I got this message.
    CDK_CreateNewWizard_Invoke.vi.ProxyCaller >> CDK_CreateNewWizard_Invoke.vi >> CDK_InstallerConfiguration_Editor.vi 
    >> CDK_Build_Invoke.vi >> CDK_Engine_Main.vi >> CDK_Engine_Build.vi >> NI_MDF.lvlib:MDFBuildDist_Build.vi
    Loading product deployment information
    Loading product deployment information
    Loading product deployment information
    Loading product deployment information
    Adding files to installer
    Done adding files
    Preparing to build deployment
    Copying products from distributions
    Copying distribution 'NI LabVIEW 8.6.1 Datalogging and Supervisory Control Module' from: 
    D:\software\application\LabView\NI.LABVIEW\NI-Labview 8.6.1 DSC Module\ to: C:\Documents and Settings\Lidaoling\桌面
    \Builds\generate waveform\My Installer\
    Building deployment
    Copying setup files
    Setting merged database information
    Setting product information
    Setting developer part information
    Starting final build
    Validating...
    Copying files...
    Updating files...
    Creating merged database...
    *** Error: Windows SDK function returned an error. (Error code -12)
    *** End Error Report
    Done building deployment 

    Solution

  • PL/SQL Function call error while reading or assigning returned value

    Hi,
    I am getting the following error while tryih to read the value of the PL/SQL Function. I am calling a function in one of my PL/SQL Packages passing mutliple IN parametes and the function returns some value back. Now on BPEL side when I try to read the return value I am getting an error:
    *<summary>*
    empty variable/expression result.
    xpath variable/expression expression "/ns3:OutputParameters/ns3:TEST_FUNCTION" is empty at line 124, when attempting reading/copying it.
    Please make sure the variable/expression result "/ns3:OutputParameters/ns3:TEST_FUNCTION" is not empty.
    *</summary>*
    Even though in the console when I check the Invoke Output Parameter it does shows me a valid value being retuned by a Function but when I am trying to Assgn this value to some variable using Assign Activity I get the above error.
    Even though all goes fine but looks like I am not able to read or assign the value returned from the Function.
    So just wondering if this even works as to me I have a very simple example and that seems not to work. Function is called successfully and is returning the value as I can see it in the BPEL console but when tryin to read or assign that value to some other variable I get the above error.
    Any ideas?
    Thanks

    This issue has come up a lot. The problem is with a mismatch between the version of JDeveloper and SOA. You'll encounter namespace issues if you use 10.1.3.1 in combination with 10.1.3.3 (or 10.1.3.4). You MUST synchronize both JDev and SOA to 10.1.3.3 or 10.1.3.4 (mixing 10.1.3.3 and 10.1.3.4 is OK). We changed when going to 10.1.3.3 by adding elementFormDefault="qualified" to the generated XSD. We used the default "unqualified" in 10.1.3.1. So you'll encounter namespace issues unless you're using 10.1.3.3 or higher JDev AND SOA. The fact that I see &lt;*db:*...&gt; tells me that you're using 10.1.3.1 JDeveloper. The correct solution is to upgrade your components.

  • How to return error from subscription function of an event

    I am creating a subscription function for an oracle shipped event, oracle.apps.eng.cm.changeObject.submit. The event fires fine, i can do my custom validations in this function. In case the validations fail, I need to return an error message.
    As per the guides and metalink documents, the way to do this is by returning 'ERROR' . But even though I return an ERROR, it does not error out. Whether I return SUCCESS or ERROR , the behaviour is the same.
    While creating the subscription function, for On Error , I selected, "Stop And Rollback ".
    Is it possible to return errors from the subscription functions.
    thanks
    Satya

    You shouldn't be passing ResultSet objects across the EJB layer.
    Instead you should be passing data back and forth.
    All of the data access code should be in one place in one class.
    That class should open the connection, run the query, process/store the results of the query and then close the connection.
    In this case you probably want to return a list of something to your jsp.
    So your EJB call should be more like
    public List<resultBean> check(String id){
      ResultSet rs = Statement.("select * from table1 where id=123");
      List resultList = new ArrayList();
      while (rs.next()){
        Bean myBean = new Bean();
        myBean.setProperty1(rs.getString("field1"));
        myBean.setProperty2(rs.getString("field2"));
        resultList.add(myBean);
      return resultList;
    }

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • Function return value == -10. Native error code -2146824584 ADOBD.Recordset: Operation is not allowed when object is closed

    I want to call Stored Procedure that return records and output parameter, from CVI
    I can get output parrameter but when I want to get records stream I recieve following wrror:
    function return value == -10. Native error code -2146824584 ADOBD.Recordset: Operation is not allowed when object is closed

    in Stored procedure I create table variable and and insert into string values
    when I remove usage of table variable the error desappear

  • My iPhone 4s no longer displays photos or text in horizontal mode. Is there a reset option or a known way to have this functionality return?

    My iPhone 4s no longer displays photos or text in horizontal mode. Is there a reset option or a known way to have this functionality return?

    RRGarcia wrote:
    My iPhone 4s no longer displays photos or text in horizontal mode. ...
    It could be this... Orientation Lock
    Settings > General > Lock Rotation..
    Or...
    Double-press the home button...
    Swipe to the right until you get to the Portrait Orientation Button...

  • Function return boolean with combine query and validation

    Wondering how would you combine a query and the condition together...
    Right now i have a computation that would do a single sql query.
    and in my validation i would use a function return boolean call the result from the computation to do some if statements
    wondering how would you combine the two in the validation? ( tried pasting both in the validation but it doesn't seem to work.)
    Select count(NAME_ID)
    FROM table
    WHERE to_char(NAME_ID) = :P1_NAME_ID;
    IF :P1_results = 1 THEN
    RETURN TRUE;
    END IF;
    RETURN FALSE;

    OK, then does this work for you as validation on your item; P1_NAME_ID ?
    DECLARE
       l_rowcount   PLS_INTEGER;
    BEGIN
       SELECT COUNT (name_id)
         INTO l_rowcount
         FROM my_table
        WHERE TO_CHAR (name_id) = :P1_NAME_ID;
       IF l_rowcount = 1
       THEN
          RETURN TRUE;
       ELSE
          RETURN FALSE;
       END IF;
    END;Jeff

  • Best way to write a function that returns query texts

    Hi, I need to write a function that will take a parameter containing table name and based upon it returns the text of a query. Here is what I am thinking of doing it but would like to get feedback whether there is a better way to do it.
    For example:
    FUNCTION getSQL(p_1 VARCHAR2, p_2 VARCHAR2) RETURN VARCHAR2
    IS
       sql varchar2(2000);
    BEGIN
    --Here i want IF THEN ELSE part and thes based upon it return a desired sql. There will be more than a dozen sqls that the function will return.
    IF p_1='Employee' Then
    sql:='Select * from employee Where employee_id=p_2;'
    Else If p_1='Departement' Then
    sql:='Select col1, col2, col3,';
    sql:=sql || ' col4, col5, col6';
    sql:=sql || ' Where dept_id=p_2';
    Else If.....
    Else If.....
    Else If.....
    Else If.....
    End IF;
    return sql;
    END;Edited by: dreporter on Sep 20, 2010 8:43 AM

    I'm never sure I understand the desire to put lots of cursors into a single stored procedure, given that they are inherently different things.
    However, assuming you have made the above decision, you should almost certainly look at using the overload of dbms_xmlgen.newcontext that accepts a cursor parameter rather than a string. This would allow you to return cursors from your function rather than strings, giving you the option to use bind variables (and prevent associated SQL injection) and perhaps not even do dynamic SQL at all, something like this perhaps...
    FUNCTION get_cursor (
       p_cursor_type VARCHAR2,
       p_cursor_parameter VARCHAR2)
       RETURN sys_refcursor
    IS
       v_sys_cursor sys_refcursor;
    BEGIN
       CASE p_cursor_type
          WHEN 'Employee' THEN
             OPEN v_cursor FOR
                SELECT empno, ename
                  FROM emp
                 WHERE empno = TO_NUMBER (p_cursor_parameter);
          WHEN 'Department' THEN
             OPEN v_cursor FOR
                SELECT deptno, dname
                  FROM dept
                 WHERE deptno = TO_NUMBER (p_cursor_parameter);
       END CASE;
       RETURN v_sys_cursor;
    END get_cursor;
    /

Maybe you are looking for