DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Problem With SQL Query

  1. #1
    Join Date
    Jan 2002
    Posts
    17

    Question Problem With SQL Query

    Hi,
    I am querying a table by getting values from a function in the where caluse .
    My Query
    ----------
    Select * from emp where empid in (myFunction()

    The function returns 1,2,3,4.But the query is not giving me the desired results.
    Is there any way to get the results besides using DBMS_SQL.

    Your help is greatly appreciated.

    Thanks in Advance.
    --SModem.

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    Well, if the query is returning something, but not the desired results, don't you think that perhaps your query is messed up? So, without knowing what the function does, it's hard to help you.

    Plus, there are probably no less than 100 ways to do the query in lieu of the function.

  3. #3
    Join Date
    Jan 2002
    Posts
    17

    SQL Query Problem

    Hi,
    Thanks for your help.
    The function returns values 1,2,3,4.And I do have data in the Emp table. But when I am executing the query it shows no records.
    I guess it is taking the function result as one single value instead of multiple values. Is there any work around for this ?

    Thanks,
    --SModem.

  4. #4
    Join Date
    May 2002
    Posts
    2,645
    Originally posted by stecal
    So, without knowing what the function does, it's hard to help you.

    The code?

  5. #5
    Join Date
    Jan 2002
    Posts
    17

    SQL Query Problem

    Hi,
    The function returns a comma separated value.
    Here is the Eg.
    Name of the function : get_data('Name')

    select get_data('Name') from dual;
    ---
    1,2,3,4

    Select id from emp where id in (1,2,3,4)
    ----
    1
    2
    3
    4

    Select id from emp where id in (get_data('Name'));
    --
    No Data found

    But I am expecting a result of
    --
    1
    2
    3
    4

    Thanks In Advance.
    --SModem.

  6. #6
    Join Date
    May 2002
    Posts
    2,645
    The purpose of a function is to take zero or more parameters and return a single value. You are returning a string. How is ID, a number, supposed to be compared to a string value of '1,2,3,4'?

    http://tahiti.oracle.com/pls/db92/db...?section=42070

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width