how to display employee names starting with a and then b in sql

前端 未结 12 1642
谎友^
谎友^ 2021-02-05 19:58

i want to display the employee names which having names start with a and b ,it should be like list will display employees with \'a\' as a first letter and then the \'b\' as a

12条回答
  •  旧巷少年郎
    2021-02-05 20:46

    Regular expressions work well if needing to find a range of starting characters. The following finds all employee names starting with A, B, C or D and adds the “UPPER” call in case a name is in the database with a starting lowercase letter. My query works in Oracle (I did not test other DB's). The following would return for example:
    Adams
    adams
    Dean
    dean

    This query also ignores case in the ORDER BY via the "lower" call:

    SELECT employee_name 
    FROM employees
    WHERE REGEXP_LIKE(UPPER(TRIM(employee_name)), '^[A-D]')
    ORDER BY lower(employee_name)
    

提交回复
热议问题