展现层框架sqlmap调用存储过程
sqlmap配置文件增加的:
?<!--存储过程-->?????
? <parameterMap id="procParamMap" >?
??? <parameter property="p_sbackCode" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>?
??? <parameter property="p_iNodeLevel" jdbcType="INTEGER" javaType="java.lang.Integer" mode="IN"/>?
? </parameterMap>
? <procedure id="countNodeLevel" parameterMap="procParamMap">?
??? {call RASINFO.SETBACKPAY_NODELEVEL(?,?)}??
? </procedure>
我们展现层框架(struts+dao+sqlmap)中DAO:
?
?? public void add(HashMap bfmap)
???? {
???????? try
???????? {
???????? ?getSqlMap().insert("insertForTs_BACKPAYTYPE", bfmap);
???????? ?
???//插完值后还得调用yuanyun后台的一个存储过程RASINFO.SETBACKPAY_NODELEVEL;
???//注意这个存储过程是没有返回值的,有返回值的存储过程调用方法还需要大家继续实践,共享
???????? ?HashMap params = new HashMap();
???????? ?params.put("p_sbackCode","$");
???????? ?params.put("p_iNodeLevel",new Integer(0));
???? ?
???????? ?getSqlMap().queryForList("countNodeLevel",params);
???????? }
???????? catch(SQLException sqlexception)
???????? {
???????????? throw new DaoException("Error creating Ts_BACKPAYTYPE.? Cause: " + sqlexception);
???????? }
???? }
具体的存储过程(为yangyun提供的,其主要功能是根据具有树结构的数据的上下级关系算出每条数据的级数,这个存储过程只在后台运行,不给前台返回值)
CREATE OR REPLACE Procedure RASINFO.SETBACKPAY_NODELEVEL(p_sbackCode in varchar2 default '$', p_iNodeLevel in int default 0)
AS
? Cursor sBackPayCur(p_sParentCode in varchar2) IS
???? SELECT BackCode FROM RasInfo.TS_BackPayType
???? WHERE ParentCode=p_sParentCode;
? I INT;
? v_sBackCode varchar(10);
? v_sParentCode varchar(10);
BEGIN
?? IF p_sBackCode='$' THEN
????? v_sParentCode := 'BP0ALL';
????? I := 1;
?? ELSE
????? v_sParentCode := p_sbackCode;
????? I := p_iNodeLevel;
?? END IF;
?? FOR S in sBackPayCur(v_sParentCode) LOOP
????? -- 修改点级别
????? UPDATE RasInfo.TS_BackPayType SET NodeLevel=I
????? WHERE BackCode=S.backCode;
????? -- 先置叶点为0标志
????? UPDATE RasInfo.TS_BackPayType SET LeafFlag='0'
????? WHERE BackCode=S.backCode;
????? -- 再置叶点确值
????? UPDATE RasInfo.TS_BackPayType SET LeafFlag='1'
????? WHERE BackCode=S.backCode
??????? AND not Exists( select 1 from RasInfo.TS_BackPayType
???????????? WHERE ParentCode=S.backCode);
????? COMMIT;
????? SetBackPay_NodeLevel(S.backCode, I+1);
?? END LOOP;
END;
?
参考资料:
http://jamesby.iteye.com/blog/post/239540
特别是这一部分:
?
1. ?<!--存储过程,如果没有返回列表,procTest的resultMap可以省略-->??? ??
2. ??<parameterMap?id="procParamMap"?class="java.util.HashMap"?>??
3. ????<parameter?property="id"?jdbcType="INTEGER"?javaType="java.lang.Integer"?mode="IN"/>??
4. ????<parameter?property="outid"?jdbcType="INTEGER"?javaType="java.lang.Integer"?mode="OUT"/>??
5. ????<parameter?property="errMsg"?jdbcType="VARCHAR"?javaType="java.lang.String"?mode="OUT"/>??
6. ??</parameterMap>??
7. ??<resultMap?id="procResultMap"?class="java.util.HashMap"?>??
8. ????<result?property="a"?column="AAA"/>??
9. ????<result?property="b"?column="BBB"/>??
10. ????<result?property="c"?column="CCC"/>???? ??
11. ??</resultMap>?? ??
12. ??<procedure?id="procTest"?parameterMap="procParamMap"?resultMap="procResultMap">??
13. ????{call?test_sp_1?(?,?,?)} ??
14. ??</procedure>??
?
?
?
?
1. ?public?List?procTest(Map?params)?throws?Exception?{ ??
2. ????????List?ret?=?(List)?getSqlMapClientTemplate().queryForList("procTest",params); ??
3. ????????return?ret; ??
4. ????} ??
?
避免使用存储过程得一个小例子:
?
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
--------- -------------------- ------------------ --------- ---------- --------- --------- ---------
7839 KING PRESIDENT 17-10月-81 5000 10
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 18-7月 -81 2450 10
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7844 TURNER SALESMAN 7698 18-9月 -81 1500 0 30
7900 JAMES CLERK 7698 03-12月-81 950 30
7521 WARD SALESMAN 7698 22-12月-81 1250 500 30
7902 FORD ANALYST 7566 03-12月-81 3000 20
7369 SMITH CLERK 7902 17-12月-80 800 20
7788 SCOTT ANALYST 7566 04-12月-82 3000 20
7876 ADAMS CLERK 7788 13-2月 -83 1100 20
7934 MILLER CLERK 7782 23-2月 -82 1300 10
14 rows selected.
SQL> select * from emp
2 start with empno=7566
3 connect by prior empno = mgr;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
--------- -------------------- ------------------ --------- ---------- --------- --------- ---------
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7902 FORD ANALYST 7566 03-12月-81 3000 20
7369 SMITH CLERK 7902 17-12月-80 800 20
7788 SCOTT ANALYST 7566 04-12月-82 3000 20
7876 ADAMS CLERK 7788 13-2月 -83 1100 20
即找到7566所有下屬
JONES
-- FORD
-- SMITH
-- SCOTT
-- ADAMS
?
Oracle用Start with...Connect By子句递归查询
Start with...Connect By子句递归查询一般用于一个表维护树形结构的应用。
创建示例表:
CREATE TABLE TBL_TEST
(
ID NUMBER,
NAME VARCHAR2(100 BYTE),
PID NUMBER DEFAULT 0
);
插入测试数据:
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('1','10','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('2','11','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('3','20','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('4','12','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('5','121','2');
从Root往树末梢递归
select * from TBL_TEST
start with id=1
connect by prior id = pid
从末梢往树ROOT递归
select * from TBL_TEST
start with id=5
connect by prior pid = id
Start with...Connect By子句递归查询一般用于一个表维护树形结构的应用。 创建示例表: CREATE TABLE TBL_TEST(&n.
Oracle用Start with...Connect By子句递归查询. 作者:54powerman 的Blog. Start with...Connect By子句递归查询一般用于一个表维护树形结构的应用。 创建示例表:. CREATE TABLE TBL_TEST ( ID NUMBER, NAME VARCHAR2(100 BYTE), PID NUMBER DEFAULT 0 ...
(转)Oracle用Start with...Connect By子句递归查询. 原文出处:http://www.yourblog.org/Data/200612/496779.html Start with...Connect By子句递归查询一般用于一个表维护树形结构的应用。 创建示例表: CREATE TABLE TBL_TEST ...
唯一下载软件下载,软件,下载,共享,共享软件,免费,免费软件,汉化,汉化补丁,游戏,游戏下载,软件教程,软件新闻,软件资讯,操作系统,邮件.
Oracle用Start with...Connect By子句递归查询. ... 从Root往树末梢递归. select * from TBL_TEST start with id=1 connect by prior id = pid. 从末梢往树ROOT递归. select * from TBL_TEST start with id=5 connect by prior pid = id ...
Oracle用Start with...Connect By子句递归查询. 出处:统一教学网; 作者:54powerman 的Blog; 编辑:N/A; 发表日期:2006-6-25 16:00:00 ... 从Root往树末梢递归. select * from TBL_TEST start with id=1 connect by prior id = pid. 从末梢往树ROOT递归 ...
数据库栏OracleOracle用Start with...Connect By子句递归查询,电脑资讯,电脑快报,it资讯,网站建设资讯,教程基地.
Oracle用Start with...Connect By子句递归查询,Or,ra,ac,cl,le,e用,用S,St,ta,ar,rt,tw,wi,it,th,h.,..,..,.C,Co,on,nn,ne,ec,ct,tB,By,y子,子句,句递,递归,归查.
Oracle用Start with...Connect By子句递归查询,数据库使用技巧,网络大本营是一个专门发布编程资料,计算机相关技巧的大型网站,收集的资料非常之多,做中国最大的IT技术库和编程数据库!
?
?
简单的ORACLE存储过程??
--工资加500,OLD。SAL>2500 不加,NEW。SAL>2500 则改为2500;
SELECT * FROM EMP??????????????????????????????????????????????????????????????? --加工资之前
CREATE OR REPLACE PROCEDURE SP_ADD (add IN number) is?????? --add参数接收传入的工资增幅
???? --DECLARE
???? --CURSOR emp_cur IS SELECT * FROM emp;
????
BEGIN
????
???? FOR? sal_sum IN (SELECT * FROM emp) LOOP????--使用循环游标隐式打开游标emp_cur或????
?????????????????????????????????????????????????????????????????????????????????? --(SELECT * FROM emp)(在FOR循环中不需要声明此游标)
?????????????????????????????????????????????????????????????????????????????????? --自动从活动集获取行,然后在处理完所有行时关闭游标????
????????? IF sal_sum.sal > 2500 THEN???????????????????????????????????????????? --逐行进行比较赋值
??????????????? UPDATE emp SET sal = sal_sum.sal WHERE empno = sal_sum.empno;
???????????????
????????? ELSIF (sal_sum.sal + add) > 2500 THEN
??????????????? UPDATE emp SET sal = 2500 WHERE empno = sal_sum.empno;
???????????????
????????? ELSE?????????????
??????????????? UPDATE emp SET sal = sal_sum.sal + add? WHERE empno = sal_sum.empno;
????????? END IF;
?????????
???? END LOOP;
????
END;
BEGIN
???? SP_ADD(500);???????????????????????????????????????????????????????????????? --输入增资的幅度????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
END;
SELECT * FROM EMP???????????????????????????????????????????????????????????????? --加工资之后??