오라클 url 자르는 문제 질문 드립니다. 0 6 626

by 위동충 [Oracle 기초] url [2020.09.15 16:19:26]


var service_url = 'test01.test02.com/test03/test04/test05'

select :service_url
      ,protocol2
      ,substr(protocol2,2,instr(protocol2,'/',1,2)-2) as t01
      ,substr(protocol2,2,instr(protocol2,'/',1,3)-2) as t02
      ,instr(protocol2,'/',1,2)
from 
(
select :service_url
      ,regexp_replace(:service_url,'(http[s]?://)?(.*?)((/|:)(.)*|$)', '\1') protocol1
      ,regexp_replace(:service_url,'(http[s]?://)?(.*?)((/|:)(.)*|$)', '\2') hostname
      ,regexp_replace(:service_url,'(http[s]?://)?(.*?)((/|:)(.)*|$)', '\3') protocol2
from dual
)
;

원하는 결과가 

test01  test02  test03  test04  test05

이런식으로 각 컬럼별로 받고 싶은데, 위에 한것 처럼 이것저것 해봐도 잘 안되네요 

혹시 답변 부탁드려도 될지 모르겠습니다.

by 마농 [2020.09.15 16:33:17]

자료 추출 조건에 대한 설명도 없고, 샘플은 1개 뿐이네요.
자료 추출 조건에 대한 설명이 필요하고, 그에 따른 다양한 형태의 샘플을 제시해 주세요.
원본 대비 결과표 형태의 예시를 주세요.


by 위동충 [2020.09.15 16:36:36]

test01.test02.com/test03/test04/test05

이 형태의 데이터(url) 을,

test01   test02   test03   test04   test05 

이런식으로 . 이나 /  기준으로 잘라서, 각 컬럼별로 보고 싶은 내용입니다. 


by 마농 [2020.09.15 16:48:54]

test 일색의 1개 샘플만 봐서는 잘 모르겠습니다.
이해를 돕기 위한 의미 있는 샘플, 다양한 샘플을 원합니다.
. 이나 / 기준으로 나누는 건데? com 은 왜 안나오죠?
예외적인 상황이 있다면 그에 맞는 설명이 있어야 합니다.


by 위동충 [2020.09.15 17:12:25]

 markets.points.com/main/point/report

이런 URL에서는 

col1 col2 col3 col4 col5
markets points main point report

 

 markets.cloud.com/main/report/service 

이런 URL 에서 

col1 col2 col3 col4 col5
markets cloud main report service

 

이런 의미입니다. test01, test02... 이런식으로 해서 의미가 좀 바뀐것 같아요


by 마농 [2020.09.15 17:18:16]

com 은 왜 빠지죠?
http://gurubee.net/article/83527 에서는 결과가 어찌 나와야 할까요?
http://www.gurubee.net/article/83527 에서는 결과가 어찌 나와야 할까요?
com 이 빠진다면? net 이나 co.kr 이나 go.kr 등. 기타 다양한 예외사항이 존재할 듯 한데요?


by 마농 [2020.09.15 17:25:43]
WITH t AS
(
SELECT 'test01.test02.com/test03/test04/test05' service_url FROM dual
UNION ALL SELECT 'http://gurubee.net/article/83527' FROM dual
UNION ALL SELECT 'https://www.gurubee.net/article/83527' FROM dual
UNION ALL SELECT 'gurubee.net/article/83527' FROM dual
UNION ALL SELECT 'gurubee.net:8888/article/83527' FROM dual
UNION ALL SELECT 'http://markets.points.com/main/point/report' FROM dual
UNION ALL SELECT 'https://markets.cloud.com/main/report/service' FROM dual
)
SELECT service_url
     , v1, v2, v3
     , REGEXP_SUBSTR(v2, '[^.]+', 1, 1) x1
     , REGEXP_SUBSTR(v2, '[^.]+', 1, 2) x2
     , REGEXP_SUBSTR(v3, '[^/]+', 1, 1) x3
     , REGEXP_SUBSTR(v3, '[^/]+', 1, 2) x4
     , REGEXP_SUBSTR(v3, '[^/]+', 1, 3) x5
  FROM (SELECT service_url
             , REGEXP_REPLACE(service_url, '([^:]+://)?([^/]+)(.*)', '\1') v1
             , REGEXP_REPLACE(service_url, '([^:]+://)?([^/]+)(.*)', '\2') v2
             , REGEXP_REPLACE(service_url, '([^:]+://)?([^/]+)(.*)', '\3') v3
          FROM t
        )
;

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입