oracle中一些词语的使用(union与union all ,rpad,cast)

oracle中一些词语的使用(union与union all ,rpad,cast)
1.union 与union all 的区别
union把两条记录合并成一个查询,但是前提,所选的记录的两个表的字段名要一致。
union和union all的区别是,union会自动压缩多个结果集合中的重复结果,同时进行默认规则的排序。而union all则将所有的结果全部显示出来,不管 是不是重复,不排序。
2.rpad与lpad区别

Lpad()函数的用法:
lpad函数将左边的字符串填充一些特定的字符其语法格式如下:   
     lpad(string,n,[pad_string])
     string:可是字符或者参数
     n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;
     pad_string:是个可选参数,这个字符串是要粘贴到string的左边,如果这个参数未写,lpad函数将会在string的左边粘贴空格。
    例如:
lpad('tech', 7); 将返回' tech'
lpad('tech', 2); 将返回'te'
lpad('tech', 8, '0'); 将返回'0000tech'
lpad('tech on the net', 15, 'z'); 将返回 'tech on the net'
lpad('tech on the net', 16, 'z'); 将返回 'ztech on the net'

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'
3.to_number字符串转换
oracle中函数用to_number('321312','99999999')
4.
cast
是进行类型转换的, 可以针对各种Oracle数据类型. 修改的是用户的数据类型.
round只是修改的数据显示格式. 对数据做四舍五入. 类似的函数还有ceil(取此数据的最小整数). trunc( 取整函数.)
SQL> create table t1(a varchar(10));

Table created.

SQL> insert into t1 values ('12.3456');

1 row created.

SQL> select round(a) from t1;

ROUND(A)
----------
12

SQL> select round(a,3) from t1;

ROUND(A,3)
----------
12.346

SQL> select cast(a as int) from t1;

CAST(AASINT)
------------
12

SQL> select cast(a as number(8,4)) from t1;

CAST(AASNUMBER(8,4))

--------------------
12.3456

你可能感兴趣的:(oracle中一些词语的使用(union与union all ,rpad,cast))