當前位置:首頁 » 操作系統 » 資料庫connectby

資料庫connectby

發布時間: 2025-05-24 03:46:15

1. 如何優化start with connect by prior

用 with .. as

實現遞歸。

供參考:

Oracle自己提供的是 connect by ... start with,而別的資料庫只有使用With來實現

create tabletest1(id number, name varchar2(20), pid number);

insert intotest1 values(1,'電器',null);
insert intotest1 values(2,'家電',1);
insert intotest1 values(3,'冰箱',2);
insert intotest1 values(4,'洗衣機',2);
insert intotest1 values(5,'電腦',1);
insert intotest1 values(6,'筆記本',5);
insert intotest1 values(7,'平板',5);
insert intotest1 values(8,'組裝機',7);
insert intotest1 values(9,'品牌機',7);

withsubqry(id,name,pid) as(
select id,name,pid fromtest1 where id= 5
union all
selecttest1.id,test1.name,test1.pid fromtest1,subqry
wheretest1.pid = subqry.id
)
select* fromsubqry;

drop tabletest1;

2. 求助,oracle的connect by功能轉換到mysql如何

在Oracle中sql代碼如下編寫

select o.orgid from t_organization o
connect by prior o.orgid = o.orgparentid
start with o.orgid = #{params.swjgDm}

那麼在MySQL資料庫中需要改為如下方式

select o.orgid from t_organization o where
(o.ORGPARENTIDS LIKE concat('%/',#{params.swjgDm},'/%')
or o.ORGID =#{params.swjgDm}) and o.AVAILABLE ='1'

3. oracle SQL查詢時提示 用戶數據中的connect by 循環 報錯是什麼原因

一般是數據錯誤導致了死循環。
如數據為這樣:
ID 父ID 值
1 2 10
2 1 20

如圖,ID為1的父ID為2,而同時ID為2的父ID是1,這樣的話,就會互相認對方的ID為父ID,就會造成一個死循環,這種錯誤,一般不用修改語句,需要正確檢查數據的正確性。

熱點內容
紅米note擴展存儲卡 發布:2025-08-20 21:27:10 瀏覽:862
驗證你的電子郵件地址不能連接伺服器 發布:2025-08-20 21:27:09 瀏覽:63
存儲區是什麼意思 發布:2025-08-20 21:26:31 瀏覽:53
壓縮袋是什麼 發布:2025-08-20 20:48:27 瀏覽:618
伺服器減容會有什麼影響 發布:2025-08-20 20:40:23 瀏覽:150
我的世界怎麼聯伺服器 發布:2025-08-20 20:34:31 瀏覽:498
c語言編譯或解釋 發布:2025-08-20 20:27:17 瀏覽:601
vsm編程 發布:2025-08-20 20:16:31 瀏覽:913
腳本刷黑石塔 發布:2025-08-20 19:50:08 瀏覽:982
網上學編程可靠嗎 發布:2025-08-20 19:45:13 瀏覽:650