SQL> select * from t;NUMBER_CODE AREA_CODE
-------------------- ----------
9314977366 0931
2868005400 028
5303940098 0530
1051710900 010
1068317189 010已用时间: 00: 00: 00.20SQL> update t set number_code=substr(number_code,length(trim('0' from area_code||' ')))
2 where number_code like trim(trim('0' from area_code||' '))||'%';已更新5行。已用时间: 00: 00: 00.10
SQL> select * from t;NUMBER_CODE AREA_CODE
-------------------- ----------
4977366 0931
68005400 028
3940098 0530
51710900 010
68317189 010已用时间: 00: 00: 00.30
SQL>
-------------------- ----------
9314977366 0931
2868005400 028
5303940098 0530
1051710900 010
1068317189 010已用时间: 00: 00: 00.20SQL> update t set number_code=substr(number_code,length(trim('0' from area_code||' ')))
2 where number_code like trim(trim('0' from area_code||' '))||'%';已更新5行。已用时间: 00: 00: 00.10
SQL> select * from t;NUMBER_CODE AREA_CODE
-------------------- ----------
4977366 0931
68005400 028
3940098 0530
51710900 010
68317189 010已用时间: 00: 00: 00.30
SQL>
解决方案 »
- 建立全文索引后,搜索不到数据,dr$$i表里没有数据
- 表的设计中字段带*号表示什么意思?
- oracle 事物问题
- 求一SQL,关于ROWNUM的问题。
- sql实现下列操作
- 求一个sql语句
- pl/sql 存储过程中 返回一个记录集,怎么返回,接受的时候怎么接受
- 817oracle安装,需联接局域网中另一台机器817oracle的库,请问工作站上要作好哪几点,服务器要让工作站用这个库
- 一个用户有500个表 想备份其中的495个 怎么做最方便 大家讨论一下
- ORACLE中是否存在象SQL SERVER 中BCP命令行导入TXT文本到数据库中?
- 高分求解一个Oracle在存储过程中组合处理输入参数的问题。
- 请问如何把附件存放到ORACLE的字段中?
create table t_test (
number_code varchar2(30),
area_code varchar2(10),
primary key (number_code)
);insert into t_test values('1234567890','010');
insert into t_test values('101234567890','010');
insert into t_test values('75584135221','0755');
commit;select decode(substr(number_code, 1, length(area_code) - 1) -
substr(area_code, 2),
0,
substr(number_code, length(area_code)),
number_code)
from t_test;
比如:
NUMBER_CODE AREA_CODE
-------------------- ----------
21000000 021
28111111 028
...
比如:
NUMBER_CODE AREA_CODE
-------------------- ----------
21000000 021
28111111 028
...
这个问题根据你的需求是无法解决的就像这个号码2121212121 021
你说它是带区号的还是不带区号的?至少从你现有的需求中是分不出来的。所以你不能怪别人写的代码有问题
commit;select decode(sign(length(decode(substr(number_code,
1,
length(area_code) - 1) -
substr(area_code, 2),
0,
substr(number_code, length(area_code)),
number_code)) - 7),
-1,
number_code,
decode(substr(number_code, 1, length(area_code) - 1) -
substr(area_code, 2),
0,
substr(number_code, length(area_code)),
number_code))
from t_test;---------------------------------------------------------------
1 1234567890
2 1234567890
3 84135221
4 2800000