SELECT
MAX(CASE WHEN deptId = 10 THEN prn ELSE 0 END) '10',
MAX(CASE WHEN deptId = 20 THEN prn ELSE 0 END) '20',
MAX(CASE WHEN deptId = 30 THEN prn ELSE 0 END) '30',
SUM(prn) '总人数'
FROM
(SELECT deptId, COUNT(perNum) prn FROM personTable GROUP BY deptId)
SELECT area_id,area_name,LEVEL,SYS_CONNECT_BY_PATH(area_name,'-')
FROM emp e
START WITH area_id = 7369
CONNECT BY area_id = PRIOR p_area_id;
SELECT area_id,area_name,LEVEL,SYS_CONNECT_BY_PATH(area_name,'-')
FROM emp e
START WITH area_id = 7566
CONNECT BY PRIOR area_id = p_area_id;
DECLARE
v_date DATE := sysdate;
BEGIN
dbms_output.put_line(V_DATE);
END;
DECLARE
v_record DICT_NATION%ROWTYPE;
BEGIN
SELECT * INTO v_record FROM DICT_NATION dn WHERE dn.NATION_CODE = 1;
dbms_output.put_line(v_record.nation_code);
dbms_output.put_line(v_record.nation_name);
END;
DECLARE
v_status DICT_NATION.status%TYPE;
v_dict NUMBER:=80;
BEGIN
SELECT status INTO v_status FROM DICT_NATION WHERE NATION_CODE < v_dict;
IF v_status < 2 THEN
UPDATE DICT_NATION SET status = 0 WHERE NATION_CODE = v_dict;
COMMIT;
END IF;
EXCEPTION
WHEN no_data_found THEN dbms_output.put_line('未找到该信息');
WHEN too_many_rows THEN dbms_output.put_line('返回多条数据,请使用游标');
WHEN OTHERS THEN dbms_output.put_line('其他异常');
END;
DECLARE
v_counter NUMBER:=57;
BEGIN
LOOP
INSERT INTO DICT_NATION (NATION_CODE,NATION_NAME,PY_CODE,STATUS) VALUES (V_COUNTER, '汉奸', 'HJ','1');
V_COUNTER:=V_COUNTER +1;
EXIT WHEN V_COUNTER > 60;
END LOOP;
COMMIT;
END;
DECLARE
v_counter NUMBER:=61;
BEGIN
WHILE V_COUNTER < 65 LOOP
INSERT INTO DICT_NATION (NATION_CODE,NATION_NAME,PY_CODE,STATUS) VALUES (V_COUNTER, '汉奸', 'HJ','1');
V_COUNTER:=V_COUNTER +1;
END LOOP;
COMMIT;
END;
DECLARE
v_counter NUMBER;
BEGIN
FOR v_counter IN 66..70 LOOP
INSERT INTO DICT_NATION (NATION_CODE,NATION_NAME,PY_CODE,STATUS) VALUES (V_COUNTER, '汉奸', 'HJ','1');
END LOOP;
COMMIT;
END;
DECLARE
v_code DICT_NATION.NATION_CODE%TYPE;
v_name DICT_NATION.NATION_NAME%TYPE;
CURSOR c_nation IS SELECT MIN(NATION_CODE), NATION_NAME FROM DICT_NATION GROUP BY NATION_NAME HAVING COUNT(NATION_CODE) >1;
BEGIN
OPEN c_nation;
LOOP
FETCH c_nation INTO v_code,v_name;
EXIT WHEN c_nation%notfound;
DELETE FROM DICT_NATION WHERE NATION_NAME = v_name AND NATION_CODE > v_code;
END LOOP;
CLOSE c_nation;
END;
CREATE PROCEDURE mp(n1 IN OUT NUMBER, n2 IN OUT NUMBER)
AS
temp NUMBER;
BEGIN
temp := n1;
n1 := n2;
n2 := temp;
END;
DECLARE
a1 NUMBER := 2;
a2 NUMBER := 5;
BEGIN
mp(a1, a2);
dbms_output.put_line(a1);
dbms_output.put_line(a2);
END;
SELECT
deptId, deptName, userName, sal,
SUM(sal) OVER () sum_sal,
SUM(sal) OVER (PARTITION BY (deptId)) sum_dept_sal,
SUM(sal) OVER (PARTITION BY (deptId) ORDER BY sal) leiji_sum_dept_sal
FROM user_table ORDER BY deptId
SELECT
deptId, deptName, userName,
RANK() OVER(ORDER BY sal DESC) rank1,
DENSE_RANK() OVER(ORDER BY sal DESC) densk_rank1,
ROW_NUMBER() OVER(ORDER BY sal DESC) row_rank2
FROM user_table
|