1、MySQL 表主键
<insert id="Application.insert" parameterClass="Application">
<selectKey resultClass="java.lang.Long" keyProperty="appId" type="post">
SELECT LAST_INSERT_ID() as value
</selectKey>
INSERT INTO t_application
(app_id,
app_name,
app_url,
app_desc,
status,
app_review,
updater,
update_time
)
VALUES (#appId#,
#appName#,
#appUrl#,
#appDesc#,
#status#,
#appReview#,
#updater#,
NOW()
)
</insert>
2、oracle 表主键
<insert id="Application.insert" parameterClass="Application">
<selectKey resultClass="long" keyProperty="appId" type="pre">
<![CDATA[SELECT SEQ_APP_ID.NEXTVAL AS appId FROM DUAL]]>
</selectKey>
INSERT INTO t_application
(app_id,
app_name,
app_url,
app_desc,
status,
app_review,
updater,
update_time
)
VALUES (#appId#,
#appName#,
#appUrl#,
#appDesc#,
#status#,
#appReview#,
#updater#,
SYSDATE
)
</insert>
//调用存储过程重现排序 传栏目ID
this.getSqlMapClientTemplate().update("Category.changeOrderReset",obj);
存储过程调用
<procedure id="Category.changeOrderReset">
<![CDATA[{call p_res_cloumn_rank(#categoryId#)} ]]>
</procedure>
oracle:
create or replace procedure p_res_cloumn_rank(columnid in number) is
--更新数据
begin
for rec in ( select rowid, rownum, t1.* from (
select m.*
from T_RES_CLOUMN_MAP m
where m.column_id = columnid
order by m.resource_rank, m.id) t1)
loop
update T_RES_CLOUMN_MAP t
set t.resource_rank = rec.rownum
where rowid = rec.rowid;
end loop;
commit;
end p_res_cloumn_rank;
/
commit;
MySQL:
DELIMITER $$
DROP PROCEDURE IF EXISTS `p_res_cloumn_rank`$$
CREATE PROCEDURE `p_res_cloumn_rank`(str_in_columnid VARCHAR(100))
BEGIN
DECLARE str_l_column_ref_resource_id VARCHAR(50);
DECLARE i_l_count INT DEFAULT 1;
DECLARE i_l_done INT DEFAULT FALSE;
DECLARE cur_l_resort CURSOR FOR SELECT t.id FROM (SELECT id
FROM t_res_cloumn_map m
WHERE m.column_id = str_in_columnid
ORDER BY m.resource_rank, m.id) t;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET i_l_done = TRUE;
OPEN cur_l_resort;
read_loop: LOOP
FETCH cur_l_resort INTO str_l_column_ref_resource_id;
IF i_l_done THEN
LEAVE read_loop;
END IF;
UPDATE t_res_cloumn_map t SET t.resource_rank = i_l_count WHERE id = str_l_column_ref_resource_id;
SET i_l_count = i_l_count + 1;
END LOOP;
CLOSE cur_l_resort;
COMMIT;
END;
$$
commit;