String between function : Utility Function « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE OR REPLACE FUNCTION betweenString (
  2     string_in   IN   VARCHAR2,
  3     start_in    IN   INTEGER,
  4     end_in      IN   INTEGER,
  5     inclusive   IN   BOOLEAN := TRUE
  6  )
  7     RETURN VARCHAR2
  8  IS
  9     v_start      INTEGER := start_in;
 10     v_numchars   INTEGER := ABS (end_in) - ABS (start_in) + 1;
 11  BEGIN
 12     IF    string_in IS NULL
 13        OR NVL (start_in, 0) = 0
 14        OR (start_in < 0 AND end_in > 0)
 15        OR (start_in > 0 AND end_in < 0)
 16        OR (start_in < 0 AND end_in > start_in)
 17        OR (start_in > 0 AND end_in < start_in)
 18     THEN
 19        RETURN NULL;
 20     ELSE
 21        IF v_start < 0
 22        THEN
 23           v_start := end_in;
 24        ELSE
 25           v_start := start_in;
 26        END IF;
 27
 28        IF NOT NVL (inclusive, FALSE )
 29        THEN
 30           v_start := v_start + 1;
 31           v_numchars := v_numchars - 2;
 32        END IF;
 33
 34        IF v_start > end_in OR v_numchars < 1
 35        THEN
 36           RETURN NULL;
 37        ELSE
 38           RETURN (SUBSTR (string_in, v_start, v_numchars));
 39        END IF;
 40     END IF;
 41  END;
 42  /

Function created.

SQL>








27.26.Utility Function
27.26.1.Get nearest day
27.26.2.Compare date offset in a function
27.26.3.Create a procedure to count employees
27.26.4.To number or null
27.26.5.Removes all numeric digits from the string passed in.
27.26.6.Generic function utilizing dynamic SQL to return the number of rows in the specified table.
27.26.7.Get the Max date
27.26.8.String between function
27.26.9.Add day to month
27.26.10.Date time calculation function
27.26.11.Table Count function
27.26.12.Word count function
27.26.13.Define your own varchar to date function
27.26.14.Get the next business day
27.26.15.Format money
27.26.16.Date calculation: business days between
27.26.17.Convert Comma-separated values to table collection
27.26.18.Function to convert celsius to fahrenheit
27.26.19.Function to convert fahrenheit to celsius
27.26.20.Get circle area