Humble Trader

Wednesday, September 13, 2006

Warehouse Libraries - lib_string_b.sql

-- ------------------------------------------------------------------------- --
-- --
-- Title: lib_string_b.sql --
-- Author: Steve Roach --
-- Date: 12-SEP-2006 --
-- Version: 01.00 --
-- --
-- Description: Container for all procedures and functions relating to --
-- String Libraries. --
-- --
-- History: --
-- --
-- Date Ver Author Description --
-- --------- ----- ------ -------------------------------------------------- --
-- 12-SEP-06 01.00 SRR First release --
-- --
-- ------------------------------------------------------------------------- --

-- Package body definition.
CREATE OR REPLACE PACKAGE BODY lib_string
AS
-- ltrim_chr
-- Strips all of the specified character from the start of the string.
FUNCTION ltrim_chr
(
p_string IN VARCHAR2
,p_chr IN VARCHAR2
)
RETURN VARCHAR2
IS
l_chars NUMBER;
l_cut NUMBER;
BEGIN
FOR l_chars IN 1 .. LENGTH(p_string)
LOOP
IF SUBSTR(p_string, l_chars, 1) != p_chr
OR
l_chars = LENGTH(p_string)
THEN
l_cut := l_chars;
EXIT;
END IF;
END LOOP;

IF SUBSTR(p_string, l_cut) = p_chr
THEN
RETURN NULL;
ELSE
RETURN SUBSTR(p_string, l_cut);
END IF;
END ltrim_chr;

-- count_chr
-- Strips all of the specified character from the start of the string.
FUNCTION count_chr
(
p_string IN VARCHAR2
,p_chr IN VARCHAR2
)
RETURN NUMBER
IS
l_i NUMBER;
l_count NUMBER := 0;
BEGIN
FOR l_i IN 1..LENGTH(p_string)
LOOP
IF SUBSTR(p_string, l_i, 1) = p_chr
THEN
l_count := l_count + 1;
END IF;
END LOOP;

RETURN l_count;
END count_chr;
END lib_string;
/

SHOW ERRORS

0 Comments:

Post a Comment

<< Home