如何匹配字符串长度以获取数据?
How to match on string length to get the data?
我有 emp1 和 emp2 表。我正在尝试通过 mathcing emp_id 将一些值从 emp2 更新为 emp1。但是 emp1 有正确的 emp_id ,因为 emp2 在末尾有额外的字符。我如何根据字符的长度匹配 emp_ids((例如:如果 emp1 中的 3 个字符则匹配 emp2 中的前 3 个字符,emp1 中的 4 个字符则匹配前 4 个字符等)
**TABLE: EMP1 TABLE2: EMP2**
EMP_ID DEPT EMP_ID DEPT
AAA Accounts AAA12 Accounts
BBBBB HR BBBBBrcp HR
-提前致谢。
您可以在 like
加入。不清楚你要update
in emp2
,但逻辑是:
update emp2 e2
set col1 = e1.col1, col2 = e1.col2 -- columns you want to update go here
from emp1 e1
where e2.emp_id like e1.emp_id || '%'
请注意 emp2
中的每个员工应该只匹配 emp1
中的一行,否则可能会发生意外情况。
我有 emp1 和 emp2 表。我正在尝试通过 mathcing emp_id 将一些值从 emp2 更新为 emp1。但是 emp1 有正确的 emp_id ,因为 emp2 在末尾有额外的字符。我如何根据字符的长度匹配 emp_ids((例如:如果 emp1 中的 3 个字符则匹配 emp2 中的前 3 个字符,emp1 中的 4 个字符则匹配前 4 个字符等)
**TABLE: EMP1 TABLE2: EMP2**
EMP_ID DEPT EMP_ID DEPT
AAA Accounts AAA12 Accounts
BBBBB HR BBBBBrcp HR
-提前致谢。
您可以在 like
加入。不清楚你要update
in emp2
,但逻辑是:
update emp2 e2
set col1 = e1.col1, col2 = e1.col2 -- columns you want to update go here
from emp1 e1
where e2.emp_id like e1.emp_id || '%'
请注意 emp2
中的每个员工应该只匹配 emp1
中的一行,否则可能会发生意外情况。