Skip to content

Instantly share code, notes, and snippets.

@loiclefevre
Created April 7, 2022 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loiclefevre/ddab41639f92f36cf7b09570d3174812 to your computer and use it in GitHub Desktop.
Save loiclefevre/ddab41639f92f36cf7b09570d3174812 to your computer and use it in GitHub Desktop.
PL/SQL function defined in SQL WITH clause
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