I would like to create a Oracle FUNCTION that will return unique listings of location types once a site_id is passed to it with carriage return as a separator (char13)
I took a first crack at the code, but I don't know how to handle multi row return. As it would happen in this case.
CREATE TABLE SITE (
SITE_ID INTEGER,
LOCATION VARCHAR2(50)
);
INSERT ALL
INTO SITE (SITE_ID, LOCATION) VALUES (3, "CHICAGO")
INTO SITE (SITE_ID, LOCATION) VALUES (3, "DALLAS")
INTO SITE (SITE_ID, LOCATION) VALUES (4, "LA")
INTO SITE (SITE_ID, LOCATION) VALUES (5, "KANSAS CITY")
INTO SITE (SITE_ID, LOCATION) VALUES (6, "RIO")
INTO SITE (SITE_ID, LOCATION) VALUES (4, "NEW YORK")
SELECT * FROM DUAL;
CREATE OR REPLACE FUNCTION UNIQUE_LOCATION (P_siteid INTEGER)
RETURN VARCHAR2(50)
IS
V_LOCATION VARCHAR2(50);
BEGIN
SELECT DISTINCT LOCATION INTO V_LOCATION FROM SITE WHERE SITE_ID=P_siteid;
RETURN V_LOCATION;
END UNIQUE_LOCATION;
Any help will be highly appreciated.
Thx.
Al
I took a first crack at the code, but I don't know how to handle multi row return. As it would happen in this case.
CREATE TABLE SITE (
SITE_ID INTEGER,
LOCATION VARCHAR2(50)
);
INSERT ALL
INTO SITE (SITE_ID, LOCATION) VALUES (3, "CHICAGO")
INTO SITE (SITE_ID, LOCATION) VALUES (3, "DALLAS")
INTO SITE (SITE_ID, LOCATION) VALUES (4, "LA")
INTO SITE (SITE_ID, LOCATION) VALUES (5, "KANSAS CITY")
INTO SITE (SITE_ID, LOCATION) VALUES (6, "RIO")
INTO SITE (SITE_ID, LOCATION) VALUES (4, "NEW YORK")
SELECT * FROM DUAL;
CREATE OR REPLACE FUNCTION UNIQUE_LOCATION (P_siteid INTEGER)
RETURN VARCHAR2(50)
IS
V_LOCATION VARCHAR2(50);
BEGIN
SELECT DISTINCT LOCATION INTO V_LOCATION FROM SITE WHERE SITE_ID=P_siteid;
RETURN V_LOCATION;
END UNIQUE_LOCATION;
Any help will be highly appreciated.
Thx.
Al