日期:2014-05-16  浏览次数:20510 次

Oracle鐨刲pad涓巖pad鍑芥暟鐨勪娇鐢?

lpad( string, padded_length, [ pad_string ] )

銆€銆€string

銆€銆€鍑嗗琚~鍏呯殑瀛楃涓诧紱

銆€銆€padded_length

銆€銆€濉厖涔嬪悗鐨勫瓧绗︿覆闀垮害(涓嶇鏄埅鍙栬繕鏄ˉ鍏咃紝鍑芥暟return鐨勫瓧绗﹂暱搴?padded_length)锛屼篃灏辨槸璇ュ嚱鏁拌繑鍥炵殑瀛楃涓查暱搴︼紝濡傛灉杩欎釜鏁伴噺姣斿師瀛楃涓茬殑闀垮害瑕佺煭锛坧added_length<length(string)锛夛紝lpad鍑芥暟灏嗕細鎶婂瓧绗︿覆鎴彇鎴愪粠宸﹀埌鍙崇殑n涓瓧绗? 濡傛灉杩欎釜鏁伴噺姣斿師鏉ョ殑瀛楃涓查暱搴﹁闀匡紙padded_length>length(string)锛夛紝鍒欏湪宸﹁竟琛ヤ笂绌烘牸

銆€銆€pad_string

銆€銆€濉厖瀛楃涓诧紝鏄釜鍙€夊弬鏁帮紝杩欎釜瀛楃涓叉槸瑕佺矘璐村埌string鐨勫乏杈癸紝濡傛灉杩欎釜鍙傛暟鏈啓锛宭pad鍑芥暟灏嗕細鍦╯tring鐨勫乏杈圭矘璐寸┖鏍笺€?/p>

銆€銆€绀轰緥1锛?/p>

銆€銆€SQL> select lpad('abcde',10,'x') from dual;

銆€銆€LPAD('ABCDE',10,'X')

銆€銆€--------------------

銆€銆€xxxxxabcde

銆€銆€绀轰緥2锛?/p>

銆€銆€SQL> select lpad('abcde',10,'oq') from dual;

銆€銆€LPAD('ABCDE',10,'OQ')

銆€銆€---------------------

銆€銆€oqoqoabcde 锛堟敞鎰忓浣曟樉绀虹殑锛?/p>

銆€銆€绀轰緥3锛?/p>

銆€銆€SQL> select lpad('abcde',2) from dual;

銆€銆€LPAD('ABCDE',2)

銆€銆€---------------

銆€銆€ab

銆€銆€~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

銆€銆€涓巐pad鍑芥暟瀵瑰簲鐨勬槸rpad鍑芥暟锛?/p>

銆€銆€rpad鍑芥暟浠庡彸杈瑰瀛楃涓蹭娇鐢ㄦ寚瀹氱殑瀛楃杩涜濉厖锛岃娉曟牸寮忎笌lpad鏍煎紡鐩稿悓锛?/p>

銆€銆€rpad(string,padded_length,[pad_string])

銆€銆€string

銆€銆€琚~鍏呯殑瀛楃涓?/p>

銆€銆€padded_length

銆€銆€瀛楃鐨勯暱搴︼紝鏄繑鍥炵殑瀛楃涓茬殑鏁伴噺锛屽鏋滆繖涓暟閲忔瘮鍘熷瓧绗︿覆鐨勯暱搴﹁鐭紝rpad鍑芥暟灏嗕細鎶婂瓧绗︿覆鎴彇鎴愪粠宸﹀埌鍙崇殑n涓瓧绗︼紙閮芥槸浠庡乏鍒板彸锛? 濡傛灉杩欎釜鏁伴噺姣斿師瀛楃涓茬殑闀垮害瑕侀暱锛屽垯鍦ㄥ彸杈硅ˉ涓婄┖鏍?/p>

銆€銆€pad_string

銆€銆€鏄釜鍙€夊弬鏁帮紝杩欎釜瀛楃涓叉槸瑕佺矘璐村埌string鐨勫彸杈癸紝濡傛灉杩欎釜鍙傛暟鏈啓锛宭pad鍑芥暟灏嗕細鍦╯tring鐨勫彸杈圭矘璐寸┖鏍笺€?/p>

銆€銆€渚嬪锛?/p>

銆€銆€rpad('tech', 7); 灏嗚繑鍥? tech '

銆€銆€rpad('tech', 2); 灏嗚繑鍥?te'

銆€銆€rpad('tech', 8, '0'); 灏嗚繑鍥?tech0000'

銆€銆€rpad('tech on the net', 15, 'z'); 灏嗚繑鍥?'tech on the net'

銆€銆€rpad('tech on the net', 16, 'z'); 灏嗚繑鍥?'tech on the netz'