Here are the instructions:
A company wants to allow customers to do product search by selecting a product name or description, and then typing a search term. Using native dynamic SQL, create a procedure name SEARCH_SP that returns a product name, description, and price base on users’ search criteria. The procedure needs handle multiple rows being returned.
Here is the code I have so far.
CREATE OR REPLACE PROCEDURE search_sp (product_name IN VARCHAR2,
description IN VARCHAR2,
price_based IN NUMBER
)
AS
BEGIN
SELECT customer.product.name, customer.description, customer.price
FROM dbo.customer
WHERE customer.description = @SEARCH.customer.product.name = @SEARCH
END;
/
EXECUTE IMMEDIATE plsql_block
USING IN OUT new_product_name, new_description, new_price_based;
END;
/
I'm getting compilation errors and more. Any help or suggestions will be greatly appreciated.
Dynamic SQL? What for? To make your life more miserable than it should be? What's wrong with a straight SQL?
I'd suggest a function. Why? You're supposed to return the result. If it is a procedure, it has to have an
OUTparameter. If that's so, then it's a function.Here's how I'd do it; see how it works, use it (and improve) if you want. I don't think I'll get involved into anything dynamic here, sorry.
As I don't have your tables, I'll use Scott's sample schema. Here's data I'm interested in:
Code that searches through it looks like this:
Let's test it:
Looks OK to me.