I am having trouble figuring out the syntax of passing variables in PL/SQL. I have 2 variables, startDate and endDate, that I want to populate from a table then pass as parameters to a function. I can declare and populate the variables but I cannot seem to figure out how to pass the suckers.
This is all happening inside a SQL query window in PL/SQL developer. The code will eventually get stored as an ad-hoc query for others to load into an IDE and run on demand.
I have tried the following two methods both of which fail with different exceptions.
First Try
DECLARE startDate DATE; endDate DATE;
BEGIN
SELECT MIN(e.start_date) INTO startDate FROM employees e WHERE e.state = 'NY';
SELECT MAX(e.end_date) INTO endDate FROM employees e WHERE e.state = 'NY';
SELECT * FROM my_package.my_function(i_start_date => :startDate, i_end_date => :endDate);
END;
Exception: PLS-00428: an INTO clause is expected in this SELECT statement
Second Try
DECLARE startDate DATE; endDate DATE;
BEGIN
SELECT MIN(e.start_date) INTO startDate FROM employees e WHERE e.state = 'NY';
SELECT MAX(e.end_date) INTO endDate FROM employees e WHERE e.state = 'NY';
END;
SELECT * FROM my_package.my_function(i_start_date => :startDate, i_end_date => :endDate);
Exception: PLS-00103: Encountered the symbol "SELECT"