Oracle递归查询
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_TESTstart with
ORA-01476的异常
主要就是在ORACLE中进行除的时候出现了除数为0.所以应该做的就是。避免出现这样的情况。就使用函数。decode(t.person_no,0,null,a.count_uid /t.person_no ) 可以避免select round (decode(t.person_no,0,null,a.count_uid /t.person_no ),2), t.unit_idfrom (select count(tg.unit_id) count_uid, tg.unit_idfrom t_group_info tg, t_alarm_allmember tawhere tg.unit_id = ta.unit_codeand tg.be_policy_type = 'AB'group by tg.unit_id) a,t_group_info twhere t.be_policy_type = 'AB'and a.unit_id= t.unit_id[@more@]
一篇工作上的BUG总结
一:bulk collect into :into子句用于单行操作,如果你的结果集是多行的,必须使用bulk collect into这个子句,另外,into子句是针对单条记录的操作,而Bulk collect into是针对集合的操作。二:PRAGMA AUTONOMOUS_TRANSACTION,自动开启事务,主要是在trigger中调用了procedure开始了一个自动事务。create or replace procedure pro_cr_channel_update_form(curdate in date,rebound out varchar2) isv_rownum number;v_sql varchar2(32767);v_sql2 varchar2(32767);PRAGMA AUTONOMOUS_TRANSACTION;beginend;[@more@]