如果字符串只有開(kāi)頭有零,而字符串中間沒(méi)有0,那么可以使用replace(字符串,'0','')
在永康等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專(zhuān)注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營(yíng)銷(xiāo),外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè),永康網(wǎng)站建設(shè)費(fèi)用合理。
如果0開(kāi)頭最長(zhǎng)的位數(shù)不長(zhǎng),那么可以逐個(gè)判斷。
比如我可能知道這里面最長(zhǎng)的就是連續(xù)5個(gè)0開(kāi)頭的,這樣我就判斷如果遇到5個(gè)0開(kāi)頭的就截掉前五位,4個(gè)0開(kāi)頭截掉前四位,3個(gè)0開(kāi)頭截掉前三位,一直到1,逐個(gè)判斷使用case when可以完成.但是如果最長(zhǎng)的0開(kāi)頭個(gè)數(shù)不確定,就比較麻煩了。
select id
from (select id,decode(id,0,0,1) as flag from table_name) t
order by flag desc,id
;
這樣id=0的部分就會(huì)排在最下面
其實(shí)我覺(jué)得這種情況做個(gè)試驗(yàn)最好了,自己建個(gè)分區(qū)表,然后把每個(gè)分區(qū)建的小一點(diǎn),分別插入數(shù)據(jù)看哪個(gè)分區(qū)的數(shù)據(jù)比較大就可以了 。
create table temp1
(month1 integer,
column1 varchar2(10))
PARTITION BY LIST ("MONTH1")
(PARTITION "M11" VALUES (201011)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 1024 NEXT 1024 MINEXTENTS 1 MAXEXTENTS 5242880
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) , PARTITION "M12" VALUES (201012)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 1024 NEXT 1024 MINEXTENTS 1 MAXEXTENTS 5242880
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
);
insert into temp1
values(201011,'0000000000');
commit;
insert into temp1
values(201012,'0');
commit;
declare i integer;
begin
for i in 1..16
loop
insert into temp1 select * from temp1;
commit;
end loop;
end;
select t.bytes,t.partition_name from dba_segments t where t.SEGMENT_NAME='TEMP1';
結(jié)果應(yīng)該是
2097152 M11
1048576 M12
給你做個(gè)試驗(yàn)?zāi)憔椭懒?/p>
create?table?test
(id?varchar2(6));
insert?into?test?values?('120000');
insert?into?test?values?('120010');
insert?into?test?values?('120200');
insert?into?test?values?('123000');
insert?into?test?values?('123001');
commit;
執(zhí)行第一遍:
update?test?set?id=substr(id,1,5)?where?id?like?'%0';
commit;
此時(shí)結(jié)果:
執(zhí)行第二遍:
update?test?set?id=substr(id,1,4)?where?id?like?'%0';
commit;
后邊就不舉例了,也就是語(yǔ)句執(zhí)行4遍,需要修改里邊的參數(shù)。
這個(gè)只能寫(xiě)存儲(chǔ)過(guò)程了。
思路:
1、遍歷user_tables里面所有的表
2、遍歷每一個(gè)表的所有列
3、update操作
這個(gè)要循環(huán)嵌套一個(gè)循環(huán)才能完成。
存儲(chǔ)過(guò)程代碼如下(未測(cè)試):
CREATE?OR?REPLACE?PROCEDURE?UpdateTableSetNull?IS
DECLARE??CURSOR?C_JOB?IS
SELECT?TABLE_NAME?FROM?USER_TABLES;
C_ROW??????????C_JOB%ROWTYPE;
VAR_TABLE_NAME?USER_TABLES.TABLE_NAME%TYPE;?
BEGIN
OPEN?C_JOB;
LOOP
FETCH?C_JOB?INTO?C_ROW;
EXIT?WHEN?C_JOB%NOTFOUND;
VAR_TABLE_NAME?:=?C_ROW.TABLE_NAME;
DECLARE
CURSOR?C_JOB_1?IS
SELECT?COLUMN_NAME?FROM?USER_TAB_COLUMNS?WHERE?TABLE_NAME?=?VAR_TABLE_NAME;
C_ROW_1?????????C_JOB_1%ROWTYPE;
VAR_COLUMN_NAME?USER_TAB_COLUMNS.COLUMN_NAME%TYPE;
BEGIN
OPEN?C_JOB_1;
LOOP
FETCH?C_JOB_1?INTO?C_JOB_1;
EXIT?WHEN?C_JOB_1%NOTFOUND;
VAR_COLUMN_NAME?:=?C_ROW.COLUMN_NAME;
UPDATE?VAR_TABLE_NAME?SET?VAR_COLUMN_NAME?=?0?WHERE?VAR_COLUMN_NAME?IS?NULL;
END?LOOP;
CLOSE?C_JOB_1;
END?LOOP;
COMMIT;
CLOSE?C_JOB;
END;
END?UpdateTableSetNull;
我寫(xiě)一份,你試試,看看能不能通過(guò)一個(gè)SQL就能完成
select t.employee_id employee_id,
t.department_id department_id,
min(t.start_date) date,
min(t.start_date) start_date,
max(t.end_date) end_date,
(select t2.position
from table_name t2
where t2.employee_id = employee_id
and t2.department_id=department_id
and t2.end_date =end_date ) position
from table_name t
group by employee_id,
department_id,
position