------------------------------------------------------------/
--处理树型结构
--表结构
create table TREE
(
ID NUMBER(10) not null,--自动编号
PARENTID NUMBER(10) not null,--父类编号
NAME VARCHAR2(50) not null--保存的信息
)
tablespace ME
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
--数据
ID PARENTID NAME
1 0 企业甲
2 0 企业乙
3 0 企业丙
4 1 部门a
5 1 部门b
6 2 部门c
7 2 部门d
8 3 部门e
9 4 科室1
10 5 科室2
11 6 科室3
12 5 科室4
13 8 科室5
--查询
--列出ID=8的所有子节点
select * from tree
start with id=8 --要查询的节点的ID号
connect by prior id=parentid
--查询结果
ID PARENTID NAME
1 8 3 部门e
2 13 8 科室5
----------------------------------------------------------/
--处理自动编号
方法一:
1. 建立序列 s_tree_id
2. insert into tree values(s_tree_id.nextval,1,'部门信息')--每次插入记录是
方法二:
1. 建立序列 s_tree_id
2. 使用触发器
CREATE OR REPLACE TRIGGER Tig_Tree--触发器名称
BEFORE INSERT ON tree--表名称
FOR EACH ROW
BEGIN --序列名称
SELECT s_tree_id.nextval INTO :NEW.id FROM DUAL;
END;
辅助:得到最近的插入的序列号
select s_tree_id.CURRVAL from DUAL
--------------------------------------------------------
--取得系统时间
select sysdate from dual
--------------------------------------------------------------------------------------------/
--数据库分页 --当前用户名称
create or replace PROCEDURE SCOTT.Page_Maker
(
Pindex in decimal,--第几页
Psql in varchar2, --表名称
Psize in decimal, --分页大小
Pcount out decimal,--总页数
v_cur out type_cur
)
AS
v_sql VARCHAR2(1000);
v_count decimal;
v_Plow decimal;
v_Phei decimal;
Begin
------------------------------------------------------------取分页总数
v_sql := 'select count(*) from (' || Psql || ')';
execute immediate v_sql into v_count;
Pcount := ceil(v_count/Psize);
------------------------------------------------------------显示任意页内容
v_Phei := Pindex * Psize + Psize;
v_Plow := v_Phei - Psize + 1;
--Psql := 'select rownum rn,t.* from cd_ssxl t' ; --要求必须包含rownum字段
v_sql := 'select * from (' || Psql || ') where rn between ' || v_Plow || ' and ' || v_Phei ;
open v_cur for v_sql;
End DotNetPagination;
--调用
C#调用ORACLE返回结果集:
OracleCommand cmd=new OracleCommand("pk_wt.p_wt",orcn);--名字
cmd.CommandType=CommandType.StoredProcedure;--类型
OracleParameter p1=new OracleParameter("mycs",OracleType.Cursor);
p1.Direction=System.Data.ParameterDirection.Output;
cmd.Parameters.Add(p1);
OracleDataAdapter da=new OracleDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds,"test");
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
--------------------------------------------------------------------------------------------/