昨天推敲出了一段值得記錄的代碼.可以解決oracle子查詢 不能order by 去第一個的問題.對於初學者知識點較多.
select nvl(REGEXP_SUBSTR((select listagg(to_char(sg.CUSTOM_COST,'fm9999999990.00'), ',') within GROUP(ORDER BY s.PRICE_PRIORITY desc)
from store_goods sg
left join store s
on s.id = sg.relation_store_id
where sg.goods_sku = i.sku),'[^,]+',1),
g.custom_cost) custom_cost,i.sku
from ORDER_ITEMS i
left join goods g
on g.goods_sku = i.sku
有一定的技巧性.當然如果熟悉REGEXP_SUBSTR 還可以實現top priority 正則表達式也可以用 \d+(\.\d+)?
REGEXP_SUBSTR(string,' \d+(\.\d+)?',1,n) n是第幾次出現的位置.默認爲1