zoukankan      html  css  js  c++  java
  • Oracle 和sqlserver 字符串补齐

    Oracle:Lpad函数

    语法格式如下:  
    lpad( string, padded_length, [ pad_string ] )  
    string  
    准备被填充的字符串;  
    padded_length  
    填充之后的字符串长度,也就是该函数返回的字符串长度,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;  
    pad_string  
    填充字符串,是个可选参数,这个字符串是要粘贴到string的左边,如果这个参数未写,lpad函数将会在string的左边粘贴空格。  
    示例:
    select
    lpad(22,10,'0') from dual; 结果: 1 0000000022

    SQLServer:right函数

    Right(stringlength)

    Right 函数的语法具有下面的命名参数:

    部分    说明
    string    必要参数。字符串表达式,从中最右边的字符将被返回。如果 string 包含 Null,将返回 Null。
    length    必要参数;为 Variant (Long)。为数值表达式,指出想返回多少字符。如果为 0,返回零长度字符串 ("")。如果大于或等于 string 的字符数,则返回整个字符串。

    示例:

    select right(replicate('0',5)+ltrim('232'),5) 

    一、Lpad函数

    lpad函数将左边的字符串填充一些特定的字符其语法格式如下:lpad(string,n,[pad_string])

    string
    字符或者参数

    n
    字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;

    pad_string
    可选参数,这个字符串是要粘贴到string的左边,若这个参数未写,lpad函数将会在string的左边粘贴空格

    没有pad_string
    lpad('tech', 7); 将返回' tech' (左边不够,补上空格) lpad('tech', 2); 将返回'te'
    含有pad_string lpad('tech', 8, '0'); 将返回'0000tech' (左边不够补上0) lpad('tech on the net', 15, 'z'); 将返回'tech on the net' lpad('tech on the net', 16, 'z'); 将返回'ztech on the net' (左边不够补上Z)

    二、Rpad函数

    rpad函数将右边的字符串填充一些特定的字符其语法格式如下:rpad(string,n,[pad_string])

    string
    字符或者参数

    n
    字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;

    pad_string
    可选参数,这个字符串是要粘贴到string的右边,如果这个参数未写,lpad函数将会在string的右边粘贴空格。

    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'
  • 相关阅读:
    2级搭建类203-Oracle 19c SI ASM 静默搭建(OEL7.7)
    2级搭建类EM-Oracle EMCC 13c Release 3 在 OEL 7.7 上的搭建
    1级搭建类112-Oracle 19c SI FS(CentOS 8)
    0级搭建类013-CentOS 8.x 安装
    List添加map,后添加的map覆盖前面的问题
    mysql插入数据报错1366
    oracle ora-12514解决办法
    easyUI 创建详情页dialog
    Server Tomcat v7.0 Server at localhost failed to start.
    maven项目启动报错;class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not exist
  • 原文地址:https://www.cnblogs.com/alsf/p/7483364.html
Copyright © 2011-2022 走看看