更新时间:2023-11-29 15:25:46
我会说很难找到比oracle更丰富的另一个sql引擎. 我建议您设置 sqlfiddle 这样的问题.
I'd say its quite hard to find another sql-engine more feature rich then oracle. I advice you to setup sqlfiddle for question like this.
UPDATE t_numbers tn SET
tn.country = (
SELECT ic.country
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, 4)
)
WHERE tn.country IS NULL;
如果将其作为pl/sql脚本运行,则可以使用循环将其包装起来,以避免复制/粘贴.
if you running it as pl/sql script you can wrap it with loop, to avoid copy/paste.
BEGIN
FOR i IN REVERSE 1..4
LOOP
UPDATE t_numbers tn SET
tn.country = (
SELECT ic.country
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, i)
)
WHERE tn.country IS NULL;
END LOOP;
END;
此代码依赖于int_codes
表中的int_code
列为UK的事实.
This code relies on a fact that column int_code
in the int_codes
table is UK.