Search code examples
sqloraclecursoruppercaselowercase

oracle sql -not matter upper or lower in cursor


enter a domain name to search on the database, no matter the domain name is upper or lower, as long as the alpha is matching.

example. 'hotmail.com' in the database, If I enter 'hOTmAIL.Com'. it still found the domain name 'hotmail.com'.

cursor E_info is select Email_Address from broker
where REGEXP_LIKE (substr(Email_Address, instr(Email_Address,'@')+1), old_email);

Solution

  • You can do this without using regexp_like.

    Lower

    select * from test where lower(substr(email_address,instr(email_address,'@')+1))=lower('HotMail.com');
    

    This will return the results faster as compared to regexp_like as you are doing exact match.

    EDIT

    create or replace procedure PR_Q3
    (old_email in varchar2, new_email in varchar2)
    authid current_user
    is 
    cursor E_info is select Email_Address from test where lower(substr(email_address,instr(email_address,'@')+1))=lower(old_email);
    v_email E_info%rowtype;
    begin 
    open E_info;
    loop
    fetch E_info into v_email;
    exit when E_info%notfound;
    update test set 
    Email_Address = replace(Email_Address,substr(Email_Address,instr(Email_Address,'@')+1),new_email) 
    where Email_Address = v_email.Email_Address;
    end loop;
    close E_info;
    end PR_Q3;
    /