I have started learning PL SQL stored procedure and i have 2 interesting queestion to ask.
In following example I execute employer_details
and it return id and name of employee if found. every thing works fine but this procedure is not dynamic but table specific
CREATE OR REPLACE PROCEDURE employer_details
IS
CURSOR table_cur IS
SELECT id, name FROM employee where id in(12,23,34); -- point 1
table_rec table_cur%rowtype;
BEGIN
OPEN table_cur;
LOOP
fetch table_cur into table_rec;
EXIT WHEN table_cur%notfound;
dbms_output.put_line(employee.id || ' ' ||employee.name); -- point 2
END LOOP;
END;
/
First question: Can we make it dynamic with following signature
CREATE OR REPLACE PROCEDURE employer_details (tablename IN VARCHAR, ID in INTEGER, target IN INTEGER)
change line in procedure
SELECT * FROM tablename where tablename.ID > target ; (point 1)
I tried it but "table or view does not exist" error appeard (i am working with Oracle/Toad)
Second question: Can we see all columns as output,
dbms_output.put_line(employee.id || ' ' ||employee.name); (point 2)
not only 2 columns but all column (*)