查询结果排序
-- 排序:升序 asc、降序 desc,含有null值的排序
-- 默认按升序排序,在order by 字段后面指定desc,按降序。但是含有null值的会排在最前面。可以加上 nulls last,把null值排在最后面
SELECT /*+parallel(t,4)*/ t.* from tablePost t
where t.content like'%\%%' escape '\' and t.post_type = 2
order by t.title desc;
-- 默认按升序排序,在order by 字段后面指定desc,按降序。但是含有null值的会排在最前面。可以加上 nulls last,把null值排在最后面
SELECT /*+parallel(t,4)*/ t.* from tablePost t
where t.content like'%\%%' escape '\' and t.post_type = 2
order by t.title desc nulls last;
临时表的概念
-- 创建临时表
create global temporary tabletemp01
(tid number,tname varchar(20));
insert into temp01
values(1,'jack');
-- 没有commit,可以查到表里的数据
select * from temp01;
commit;
-- commit后,表里的数据,不存在了
select * from temp01;
commit后,表里的记录没有了
-- sql函数:单行函数、多行函数
-- 字符函数
-- lower 、upper、initcap首字母大写
select lower('Hello World')小写, upper('Hello world')大写, initcap('Hello world')首字母大写 from dual;
-- 字符控制函数
-- concat, substr 截取字符, length/lengthb字符长度 :中文字符算2个字节, instr, lpad, rpad, ltrim
-- substr 截取字符
select substr('Hello World',2) 子串 from dual
unionall
select substr('Hello World',2,4) 子串 from dual;
-- length/lengthb字符长度 :中文字符算2个字节
select length('Hello World'), lengthb('Hello World') from dual
union all
select length('上海'), lengthb('上海') from dual;
-- instr:查找字符串,找到返回所在位置,否则返回0
select instr('Hello World','ll') from dual
union all
select instr('Hello World','kk') from dual;
-- lpad:左填充,rpad:右填充
select lpad('abc',10,'*') from dual
union all
select rpad('abc',10,'*') from dual;
-- trim:去掉字符串前后空格,或指定字符
select trim(' h ello world ') from dual
union all
select trim('h'from'hello world he ') from dual;
-- replace:替换字符
selectre place(' hello world','l','*') from dual;
-- 数字函数
-- round:四舍五入, trunc:截断, mod: 求余
select round(3.1415,3), trunc(3.1415,3), mod(100,30) from dual;
-- 取整数(向下取整 floor, trunc;向上取整 ceil)
select floor(3.6), trunc(3.6), ceil(3.3) from dual;
-- 数字格式化
-- 小数后第3、4位不足补0
select to_char(12345.123,'9999999.9900') from dual
union all
select to_char(0.123,'9999.9900') from dual
union all
select to_char(0.123,'9990.9900') from dual;