Created
April 7, 2022 12:49
-
-
Save loiclefevre/ddab41639f92f36cf7b09570d3174812 to your computer and use it in GitHub Desktop.
PL/SQL function defined in SQL WITH clause
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
FUNCTION get_domain(url VARCHAR2) RETURN VARCHAR2 IS | |
pos BINARY_INTEGER; | |
len BINARY_INTEGER; | |
BEGIN | |
pos := INSTR( url, 'www.' ); | |
len := INSTR( SUBSTR( url, pos + 4 ), '.' ) - 1; | |
RETURN SUBSTR( url, pos + 4, len ); | |
END; | |
SELECT DISTINCT url, get_domain(url) AS domain | |
FROM websites; | |
URL DOMAIN | |
---------------- -------- | |
www.oracle.com oracle | |
www.graalvm.org graalvm | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment