Search code examples
sqloracle-databasewildcardsql-like

Unable to fetch names ending with a character in oracle database


Oracle - Run SQL Command line

I have given the proper syntax but I couldn't fetch the information...Please help!!!

Here is my query...

SQL> select fname from faculty where fname like 'A%';
FNAME
------------------------------
Amit
Aman
SQL> select fname from faculty where fname like '%';

FNAME
------------------------------
Amit
Aman
Sumit
Suman
Sumathi
SQL> select fname from faculty where fname like '%n';

no rows selected

Solution

  • It might be related to the datatype of column FNAME. Is it CHAR? If So, Oracle will append extra spaces after the string and then your string would not match with your specified selection criteria.

    To make it more clear, You can try below query -

    SELECT fname FROM faculty WHERE TRIM(fname) LIKE '%n';
    

    This will trim extra spaces and then might fetch the expected result.

    For further assistance, Please post the structure of your table.