Say I have a table as:
 create table product
(
  prod_code number(3),
  prod_name varchar2(20),
  prod_dept varchar2(20)
);
I want to write a procedure which takes in two parameters:
param_1 = col_name
param_2 = col_value
The procedure needs to check if the column exists and if it does then returns the row(s) with the values equal to param_2.
Example:
Say the procedure name is getproddetails and the parameters passed are like this:
execute getproddetails('prod_id', 40)
When I pass these two values then it should return the entire row with prod_id=40. 
I can check weather the column exists or not but how to return the entire row(s) based on the values?
Any help would be great. I have written the following code but it doesn't work:
create or replace procedure getproductdetails(p_colname varchar2, p_value number)
is
  v_column_exists number :=0;
  cursor c1 is select * from product where p_colname = p_value;
  myrow c1%rowtype;
    BEGIN
    select count(*) into v_column_exists
    from user_tab_cols
    where column_name = p_colname and table_name = 'PRODUCT';
   if(v_column_exists > 0) then
     open c1;
      loop
        fetch c1 into myrow;
        exit when c1%notfound;
        dbms_output.put_line(myrow.prod_name || ' ' || myrow.prod_cost);
      end loop;
    else
      dbms_output.put_line('Column Not Found');
    end if;
   end getproductdetails;
Note that I am displaying only 2 columns but there are like 8 to 9 columns.
 
     
    