Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Pl/sql Like

  • 07-12-2007 08:30PM
    #1
    Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭


    i have a piece of pl/sql that looks like this:
    DECLARE
        dest    Location.description%TYPE:=&dest;
        result    Location.description%TYPE;
        
    BEGIN
        SELECT description INTO result FROM Location WHERE description LIKE '%' || dest || '%' ;    
           
        IF result LIKE dest
        THEN
            DBMS_OUTPUT.PUT_LINE('we have holidays based in ' || dest || ' contact a agent to arrange today.');
        END IF;
        
        
        EXCEPTION
                    WHEN NO_DATA_FOUND THEN
                        DBMS_OUTPUT.PUT_LINE('cannot find ' || dest || ' in the database.');
                    WHEN OTHERS THEN
                        DBMS_OUTPUT.PUT_LINE('Unexpected error occurred.');    
    END;
    
    


    what i want it to do is enter in a destination eg. 'new york' and check it to see if it's like the result. the problem arises with the description in the Locations table is capitalised so when i enter in 'New York' it does the output line, but i want it to execute this if someone types in something like new york eg 'new yokr'. i thought the LIKE command would do this.


Comments

  • Registered Users, Registered Users 2 Posts: 995 ✭✭✭cousin_borat


    Usually in pl/sql when comparing string you make both strings uppercase so use the pl/sql upper function
    DECLARE
        dest    Location.description%TYPE:=&dest;
        result    Location.description%TYPE;
        
    BEGIN
        SELECT description INTO result FROM Location [B]WHERE UPPER([/B]description[B])[/B] LIKE '%' || [B]UPPER([/B]dest[B])[/B] || '%' ;    
           
       and so on...
    

    Hope this helps.

    Also watch out for NULLvalues in your WHERE clauses as this will generate PL/SQL exceptions


  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭Creamy Goodness


    thank you kind sir.


Advertisement