How to join two tables based on substring values of fields?

后端 未结 4 677
予麋鹿
予麋鹿 2021-01-05 07:34

I am having problem with sql. I want to join two tables, employee and class instructor. Condition is that employee is having unid column like \'u0871457\' where as class i

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 08:18

    The character position is wrong. You should start your substring on the position 2 (the first character of your string is 1 and not 0). On the other side, you are using the SUBSTR function on both string while you should use only on the employee id. Be careful, if both ids are strings, the length will be different.

    If you just only want to change the 'u' on the employee id, try with the TRANSLATE function.

    TRANSLATE returns char with all occurrences of each character in from_string replaced by its corresponding character in to_string. Characters in char that are not in from_string are not replaced. The argument from_string can contain more characters than to_string. In this case, the extra characters at the end of from_string have no corresponding characters in to_string. If these extra characters appear in char, they are removed from the return value.

    Syntax

    ──TRANSLATE──('char' , 'from_string' , 'to_string')──><

    Pl/SQL Example
    TRANSLATE ('abcd', 'ab', '12') ==> '12cd'
    TRANSLATE ('12345', '15', 'xx') ==> 'x234x'
    

提交回复
热议问题