---
title: "判断截串sql 以及 树递归查询函数"
author: "yjkun"
date: "2012-05-21T16:52:02Z"
tags: ["SQL"]
categories: ["数据库"]
slug: "sql"
draft: false
lastmod: "2012-05-22T13:56:19Z"
id: 1528569
url: "https://yjkun.iteye.com/blog/1528569"
---

网址如果包含http://www则截掉 不包含www则 截掉 http://
select decode(INSTR(t.home_web_url, 'www', 1, 1),0,substr(t.home_web_url,8,length(t.home_web_url)-8),substr(t.home_web_url,12,length(t.home_web_url)-12))
from ipms_website_now t

instr：查找字符串出现位置  instr（a,b,c,d) 表示在 a从c开始第d次b出现的位置 c,d为可选默认1

父取子
select *
  from ipms_subject t
connect by prior t.id = t.parent_id
 start with t.id = "?" //父id

子取父
select *
  from ipms_subject t
connect by prior t.parent_id = t.id
 start with t.id = "?" //子孙id