Õâ¸öÊǾѾѵÄsql½â·¨¡£
http://blog.csdn.net/happyflystone/archive/2009/01/17/3819863.aspx
ÒýÓÃÐèÇó
½ñÌìºÍÁºÎÌÔÚȺÀïÁÄÌ죬С¼Ò»ïͻȻÅ׳öÒ»¸öÓÐÒâ˼µÄÎÊÌ⣬ÄǾÍÊÇ×Ö·û´®×Ö¶ÎÄÚµÄ×Ö·û´®ÅÅÐòÎÊÌ⣬±ÈÈçÓÐÁÐ col, ÓÐÊý¾Ý 'RDGS' , ÒªÇóÊä³öΪ 'DGRS' ¡£
--------------------------------------------------------------------------------
oracle·ÖÎöº¯ÊýÖ§³Ö¾ÛºÏ:)
create table t_test(f varchar2 ( 10 ));
insert into t_test values ( 'sdffesa' );
insert into t_test values ( 'asdflkj' );
insert into t_test values ( 'ijf92' );
select f, max ( replace (SYS_CONNECT_BY_PATH(c, ' ' ), ' ' , '' ))f1 from (
select f,rn,c,row_number()over( partition by f order by c) as ord from ( select
f,decode(rn,
1 ,substr(f, 1 , 1 ),
2 ,substr(f, 2 , 1 ),
3 ,substr(f, 3 , 1 ),
4 ,substr(f, 4 , 1 ),
5 ,substr(f, 5 , 1 ),
6 ,substr(f, 6 , 1 ),
7 ,substr(f, 7 , 1 ),
8 ,substr(f, 8 , 1 ),
9 ,substr(f, 9 , 1 ),
10 ,substr(f, 10 , 1 )
) as c,rn from
t_test a ,(
select level rn from dual connect by 1 = 1 and level <= 10 )b
where length(a.f)>=b.rn))
start with ord= 1 connect by f= prior f and ord- 1 = prior ord
group by f;
drop table t_test;
/*
F F1
ijf92 29fij
asdflkj adfjkls
sdffesa adeffss
*/
--------------------------------------------------------------------------------
ºóÀ´Êܵ½Ð¡ÁºµÄÆô·¢£¬ÐÞ¸ÄÁËһϲð·Ö×Ö·û´®µÄ·½·¨£¬¿ÉÒÔ°ÑdecodeÈ¥µô
-- ²âÊÔ»·¾³
create table t_test(f varchar2 ( 10 ));
insert into t_test values ( 'sdffesa' );
insert into t_test values ( 'asdflkj' );
insert into t_test values ( 'ijf92' );
-- ²âÊÔ×Ö·û´®µÄ²ð·Ö
select
f,substr(f,rn, 1 ) as c from
t_test a ,(
select level rn from dual connect by 1 = 1 and level <= 10 )b
where length(a.f)>=b.rn order by f;
/*
F C
asdflkj a
asdflkj f
asdflkj &n
ÓкܶàÓ¦ÓÃÏîÄ¿, ¸ÕÆð²½µÄʱºòÓÃMYSQLÊý¾Ý¿â»ù±¾ÉÏÄÜʵÏÖ¸÷ÖÖ¹¦ÄÜÐèÇó£¬Ëæ×ÅÓ¦ÓÃÓû§µÄÔö¶à£¬Êý¾ÝÁ¿µÄÔö¼Ó£¬MYSQL½¥½¥µØ³öÏÖ²»¿°ÖظºµÄÇé¿ö£º
Á¬½ÓºÜÂýÉõÖÁå´»ú£¬ÓÚÊǾÍÓаÑÊý¾Ý´ÓMYSQLǨµ½ORACLEµÄÐèÇó£¬Ó¦ÓóÌÐòÒ²ÒªÏàÓ¦×öһЩÐ޸ġ£±¾ÈË×ܽá³öÒÔϼ¸µã×¢ÒâÊÂÏϣÍû¶Ô´ó¼ÒÓÐËù°ïÖú¡£
1£® ×Ô¶¯Ôö³¤µÄÊý¾ÝÀàÐ ......