Skip to content

Instantly share code, notes, and snippets.

@bobby5892
Created April 7, 2019 19:35
Show Gist options
  • Select an option

  • Save bobby5892/0db3fbf791b3a9d08bd8bf69eddfb369 to your computer and use it in GitHub Desktop.

Select an option

Save bobby5892/0db3fbf791b3a9d08bd8bf69eddfb369 to your computer and use it in GitHub Desktop.
CREATE TABLE FULL_NAME (
full_name_char VARCHAR2(50), birthdate DATE
);
INSERT INTO FULL_NAME (full_name_char,birthdate) VALUES('ROBERT/MOORE','03-SEP-1983');
DECLARE
splitPosition NUMBER(2) := NULL;
full_name_char VARCHAR2(50) := NULL;
-- output vars requested by Pam
v_first_name VARCHAR2(50) := NULL;
v_last_name VARCHAR2(50) := NULL;
-- No instruction on what to use in this
v_birth_date DATE := NULL;
birth_last_of_month DATE := NULL;
BEGIN
SELECT full_name_char INTO full_name_char FROM FULL_NAME;
SELECT birthdate INTO v_birth_date FROM FULL_NAME;
-- Find the /
SELECT INSTR(full_name_char,'/', 1, 1) "Instring" INTO splitPosition FROM DUAL;
-- Get First Name
SELECT SUBSTR(full_name_char,0,(splitPosition-1)) "Substring" INTO v_first_name FROM DUAL;
-- Get Last Name
SELECT SUBSTR(full_name_char,(splitPosition+1),(length(full_name_char))) "Substring" INTO v_last_name FROM DUAL;
-- Get Last day of birth Month
SELECT LAST_DAY(v_birth_date) "Last" INTO birth_last_of_month FROM DUAL;
DBMS_OUTPUT.PUT_LINE('Split Position: ' || splitPosition || ' First: ' || v_first_name || ' Last: ' || v_last_name || ' Length: ' || length(full_name_char));
DBMS_OUTPUT.PUT_LINE('Length of Name:' || length(full_name_char) || 'Last Day of Birth Month:' || birth_last_of_month);
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment