1. CONNECT BY 是一个连续的
SELECT REGEXP_SUBSTR(‘01#02#03#04‘, ‘[^#]+‘, 1, LEVEL) AS NEWPORT
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(‘01#02#03#04‘, ‘[^#]+‘);
1.0select REGEXP_SUBSTR(‘由店间调拨单433453自动生成‘,‘[0-9]+‘) from dual; ====〉433453
1.1 SELECT LEVEL FROM DUAL CONNECT BY LEVEL <=7;
1.2 connect by prior 【就是2个列的上下级关联,可以控制向上、下查找,】
SELECT
ep.*,LEVEL
FROM scott.emp ep
start with ep.empno = 7839
connect by prior ep.empno = ep.mgr
ORDER BY LEVEL
3.OVER与rank()【按部门分区,以工资分等级】
SELECT deptno,EMPNO, SAL, rank() OVER(PARTITION BY deptno order by SAL)
FROM SCOTT.EMP
4.OVER与row_number()【按部门分区,以工资排序】
SELECT deptno,EMPNO, SAL, row_number() OVER(PARTITION BY deptno order by SAL)
FROM SCOTT.EMP
5.OVER与sum()不与 order by 【按部门分区,计算整个部门的工资合】
SELECT deptno,EMPNO, SAL, sum(SAL) OVER(PARTITION BY deptno)
FROM SCOTT.EMP
6.OVER与sum()与 order by 【按部门分区,累计计算工资】
SELECT deptno,EMPNO, SAL,sum(SAL) OVER(PARTITION BY deptno order by SAL)
FROM SCOTT.EMP
7.merge into fzq1 aa --fzq1表是需要更新的表
using fzq bb -- 关联表
on (aa.id=bb.id) --关联条件
when matched then --匹配关联条件,作更新处理
update set
aa.chengji=bb.chengji+1,
aa.name=bb.name --此处只是说明可以同时更新多个字段。
when not matched then --不匹配关联条件,作插入处理。如果只是作更新,下面的语句可以省略。
BEGIN
EXECUTE IMMEDIATE ‘begin ‘ || v_procname || ‘(:1, :2, :3); end;‘
USING p_abnapplyno,p_lastmodify, OUT out_abnormityno;
END;
9.
SELECT TRUNC(SYSDATE, ‘MM‘) + ROWNUM - 1 FROM DUAL CONNECT BY ROWNUM <= TO_NUMBER(TO_CHAR(LAST_DAY(SYSDATE), ‘dd‘))
SELECT LAST_DAY(SYSDATE) FROM dual
SELECT TRUNC(SYSDATE,‘mm‘) FROM DUAL --当月第一天
原文:https://www.cnblogs.com/mikeshc/p/11776810.html