Oracle常用查询技巧

Oracle常用查询技巧汇总

Oracle常用查询技巧


将查询结果插入到表中

insert into 表A(id, name, age)
select sys_guid(), from 表B

chr(10) 回车换行符号 (可用于替换或拼接字符)

-- 拼接回车换行
'xxxxxx' || chr(10) || 'yyyyyyyy'
-- 替换回车换行符
replace(t.custName,chr(10),'<br/>')

合并查询 排序

-- 添加额外的字段 用于控制排序
select * from 
(    select
        1 sort_temp,
        xxxx 
    from x
union
    select
        2 sort_temp,
    xxxx from x
)  
order by 
sort_temp asc,
xx desc,
xx,asc 

根据指定维度 查询出最新的数

select * from (
    select row_number() over (partation by t.xx,t.xx order by t.xx_time desc) rn,t.*    
    from xxxxx t
    -- 记得条件在里面
    where 
        t.xxx = xxxx
) where rn = 1

查询所有的表

SELECT * FROM all_tables;

listagg 预先排序

SELECT 
    department_id,
    LISTAGG(employee_name, ', ') WITHIN GROUP (ORDER BY hire_date) AS employees
FROM 
    (SELECT department_id, employee_name, hire_date 
     FROM employees 
     ORDER BY department_id, hire_date)
GROUP BY 
    department_id;
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值