Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function doesn't work

Status
Not open for further replies.

dkwong

MIS
Dec 27, 2001
76
CA
Why can I not assign a SQL statement to a variable? Thanks!

Code:
CREATE OR REPLACE FUNCTION Lookup(id_no IN NUMBER, table_name IN VARCHAR2)
  RETURN VARCHAR2
IS
BEGIN
	 IF table_name = "vendor"
	 THEN
	 	 return_value := (SELECT vendor_number_tx FROM table_name WHERE vendor_id_no = id_no;)	
		 
	 ELSEIF table_name = "contract"
	 THEN
	 	 return_value := (SELECT contract_num_tx FROM table_name WHERE contract_id_no = id_no;)    

	 END IF;
	 
	 RETURN return_value

END Lookup;
 
Try this

CREATE OR REPLACE FUNCTION Lookup(id_no IN NUMBER,table_name IN VARCHAR2)
RETURN VARCHAR2 IS
BEGIN
IF table_name = 'vendor'
THEN
SELECT vendor_number_tx
INTO return_value
FROM vendor
WHERE vendor_id_no = id_no;
ELSEIF table_name = 'contract'
THEN
SELECT contract_num_tx
INTO return_value
FROM contract
WHERE contract_id_no = id_no;
END IF;

RETURN return_value
END;
 
Thanks! It worked after I added the semi-colon to RETURN return_value and declared return_value in the declaration section.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top