SQL> create or replace type obj_dept as object
2 (deptcode varchar2(30),
3 deptname varchar2(60),
4 parentcode varchar2(30),
5 batchcount number,
6 unprintcount number);
7 /类型已创建。SQL> create or replace type t_depttree is table of obj_dept;
2 /create or replace FUNCTION mfn_GetBatchDeptTree(FileInfoUID varchar2,UserName varchar2)
RETURN t_depttree
AS
cstid number;
depttree t_depttree := t_depttree();
begin
select customer_id into cstid from FileInfo where UID=FileInfoUID;
insert into depttree
with
P1(PrintDeptCode, BatchCount, PrintedCount) AS
(
SELECT PrintDeptCode, COUNT(*), SUM(CASE Printed WHEN 1 THEN 1 ELSE 0 END) FROM BatchInfo
WHERE FileInfo_uid=FileInfoUID
GROUP BY PrintDeptCode
),
P (PrintDeptCode, BatchCount, UnPrintCount) AS
(
SELECT PrintDeptCode, BatchCount, BatchCount-PrintedCount FROM P1
left join CustomerDept d on P1.PrintDeptCode=d.DeptCode and d.Customer_Id=cstid
where d.username=UserName
),
DEPT (DeptCode, DeptName, ParentCode, BatchCount, UnPrintCount) AS
(
SELECT P.PrintDeptCode, D.DeptName, D.ParentCode, BatchCount, UnPrintCount FROM P
LEFT JOIN CustomerDept D ON D.Customer_Id=cstid AND D.DeptCode=P.PrintDeptCode
UNION ALL
SELECT PARENT.DeptCode, PARENT.DeptName, PARENT.ParentCode, CHILD.BatchCount, CHILD.UnPrintCount
FROM CustomerDept PARENT, DEPT CHILD
WHERE PARENT.DeptCode=CHILD.ParentCode AND PARENT.Customer_Id=cstid
)
select deptcode, DeptName, ParentCode, SUM(BatchCount), SUM(UnprintCount)
from dept group by DeptCode, DeptName, ParentCode
order by ParentCode, DeptCode;
RETURN depttree;
END mfn_GetBatchDeptTree;
2 (deptcode varchar2(30),
3 deptname varchar2(60),
4 parentcode varchar2(30),
5 batchcount number,
6 unprintcount number);
7 /类型已创建。SQL> create or replace type t_depttree is table of obj_dept;
2 /create or replace FUNCTION mfn_GetBatchDeptTree(FileInfoUID varchar2,UserName varchar2)
RETURN t_depttree
AS
cstid number;
depttree t_depttree := t_depttree();
begin
select customer_id into cstid from FileInfo where UID=FileInfoUID;
insert into depttree
with
P1(PrintDeptCode, BatchCount, PrintedCount) AS
(
SELECT PrintDeptCode, COUNT(*), SUM(CASE Printed WHEN 1 THEN 1 ELSE 0 END) FROM BatchInfo
WHERE FileInfo_uid=FileInfoUID
GROUP BY PrintDeptCode
),
P (PrintDeptCode, BatchCount, UnPrintCount) AS
(
SELECT PrintDeptCode, BatchCount, BatchCount-PrintedCount FROM P1
left join CustomerDept d on P1.PrintDeptCode=d.DeptCode and d.Customer_Id=cstid
where d.username=UserName
),
DEPT (DeptCode, DeptName, ParentCode, BatchCount, UnPrintCount) AS
(
SELECT P.PrintDeptCode, D.DeptName, D.ParentCode, BatchCount, UnPrintCount FROM P
LEFT JOIN CustomerDept D ON D.Customer_Id=cstid AND D.DeptCode=P.PrintDeptCode
UNION ALL
SELECT PARENT.DeptCode, PARENT.DeptName, PARENT.ParentCode, CHILD.BatchCount, CHILD.UnPrintCount
FROM CustomerDept PARENT, DEPT CHILD
WHERE PARENT.DeptCode=CHILD.ParentCode AND PARENT.Customer_Id=cstid
)
select deptcode, DeptName, ParentCode, SUM(BatchCount), SUM(UnprintCount)
from dept group by DeptCode, DeptName, ParentCode
order by ParentCode, DeptCode;
RETURN depttree;
END mfn_GetBatchDeptTree;
解决方案 »
- 数据库一张表,外键关联自身,在没有数据的情况下,如何添加第一条数据!
- plsql一个sql语句优化 急!!
- 表列的数量是否直接响查询速度
- 这个日期怎么插?高手指点!
- 向各位求一存储过程,谢谢
- 在没有和服务器连接的oracle的客户端,怎样建立数据库??恳请赐教!!!
- 索引碎片问题,急,下班前要交给老板
- 一个简单的sql语句,帮忙
- 如何通过isqlplus访问数据库??
- 怎样将Date类型的默认格式改成yyyy-mm-dd
- 错误oracle-12514:TNS:监听程序当前无法识别
- Cannot create PoolableConnectionFactory (Listener refused the connection with th
参考一下简单类型的例子如何?建立和使用不包含任何方法的对象类型CREATE OR REPLACE TYPE PERSON AS OBJECT
(
NAME VARCHAR2(10),AGE NUMBER(3),BIRTHDATE DATE
) 建立行对象
CREATE TABLE PERSON_TABLE OF PERSON为行对象插入数据BEGIN
INSERT INTO PERSON_TABLE VALUES('张三',20,'11-4月-58');
INSERT INTO PERSON_TABLE VALUES('李四',20,'11-4月-58');
END;
DECLARE
PP PERSON;
BEGIN
SELECT VALUE(A) INTO PP FROM PERSON_TABLE A--(必须使用表别名)
where A.NAME='&NAME';
DBMS_OUTPUT.PUT_LINE(PP.NAME||' '||PP.AGE||' '||PP.BIRTHDATE);
END;
create or replace FUNCTION mfn_GetBatchDeptTree(FileInfoUID varchar2,UserName varchar2)
RETURN t_depttree
AS
cstid number;
--depttree t_depttree := t_depttree();
begin
select customer_id into cstid from FileInfo where UID=FileInfoUID;
insert into depttree
with
P1(PrintDeptCode, BatchCount, PrintedCount) AS
(
SELECT PrintDeptCode, COUNT(*), SUM(CASE Printed WHEN 1 THEN 1 ELSE 0 END) FROM BatchInfo
WHERE FileInfo_uid=FileInfoUID
GROUP BY PrintDeptCode
),
P (PrintDeptCode, BatchCount, UnPrintCount) AS
(
SELECT PrintDeptCode, BatchCount, BatchCount-PrintedCount FROM P1
left join CustomerDept d on P1.PrintDeptCode=d.DeptCode and d.Customer_Id=cstid
where d.username=UserName
),
DEPT (DeptCode, DeptName, ParentCode, BatchCount, UnPrintCount) AS
(
SELECT P.PrintDeptCode, D.DeptName, D.ParentCode, BatchCount, UnPrintCount FROM P
LEFT JOIN CustomerDept D ON D.Customer_Id=cstid AND D.DeptCode=P.PrintDeptCode
UNION ALL
SELECT PARENT.DeptCode, PARENT.DeptName, PARENT.ParentCode, CHILD.BatchCount, CHILD.UnPrintCount
FROM CustomerDept PARENT, DEPT CHILD
WHERE PARENT.DeptCode=CHILD.ParentCode AND PARENT.Customer_Id=cstid
)
open t_depttree /*修改部分*/ select deptcode, DeptName, ParentCode, SUM(BatchCount), SUM(UnprintCount)
from dept group by DeptCode, DeptName, ParentCode
order by ParentCode, DeptCode;
RETURN depttree;
END mfn_GetBatchDeptTree;
create or replace FUNCTION mfn_GetBatchDeptTree(FileInfoUID varchar2,UserName varchar2)
RETURN t_depttree
AS
cstid number;
--depttree t_depttree := t_depttree();
begin
select customer_id into cstid from FileInfo where UID=FileInfoUID;
insert into depttree
with
P1(PrintDeptCode, BatchCount, PrintedCount) AS
(
SELECT PrintDeptCode, COUNT(*), SUM(CASE Printed WHEN 1 THEN 1 ELSE 0 END) FROM BatchInfo
WHERE FileInfo_uid=FileInfoUID
GROUP BY PrintDeptCode
),
P (PrintDeptCode, BatchCount, UnPrintCount) AS
(
SELECT PrintDeptCode, BatchCount, BatchCount-PrintedCount FROM P1
left join CustomerDept d on P1.PrintDeptCode=d.DeptCode and d.Customer_Id=cstid
where d.username=UserName
),
DEPT (DeptCode, DeptName, ParentCode, BatchCount, UnPrintCount) AS
(
SELECT P.PrintDeptCode, D.DeptName, D.ParentCode, BatchCount, UnPrintCount FROM P
LEFT JOIN CustomerDept D ON D.Customer_Id=cstid AND D.DeptCode=P.PrintDeptCode
UNION ALL
SELECT PARENT.DeptCode, PARENT.DeptName, PARENT.ParentCode, CHILD.BatchCount, CHILD.UnPrintCount
FROM CustomerDept PARENT, DEPT CHILD
WHERE PARENT.DeptCode=CHILD.ParentCode AND PARENT.Customer_Id=cstid
)
open t_depttree /*修改部分*/ select deptcode, DeptName, ParentCode, SUM(BatchCount), SUM(UnprintCount)
from dept group by DeptCode, DeptName, ParentCode
order by ParentCode, DeptCode;
RETURN depttree;
END mfn_GetBatchDeptTree;
还要insert,还要depttree t_depttree := t_depttree();
。好想java里面的定义class和newclass()一样!我浆糊了