I am very new to PL/SQL and would like to be able to take advantage of the procedural options of oracle SQL.
I have a query that I would like to transform into a PL/SQL query that takes the SKU you want and inputs whenever you have the word SKU in your query.
Example:
SELECT A.*, CT.CUSTOMER_ID, CT.ORDERS
FROM CUSTOMER_TABLE CT
RIGHT JOIN
(
SELECT OT.COLUMN_ID, OT.SKU, OT.ORDERS
FROM ORDERS_TABLE OT
WHERE OT.SKU = 123
)A
ON CT.ORDERS = OT.ORDERS
AND CT.SKU IS > 0
This is strictly an example so I know that what I am asking is pointless, however, if I had a lengthier query that contains more than 2 or 3 "SKU" inputs then I would like to have a variable/parameter for it.
My ideal code would be:
DECLARE
SKUS INTEGER := 123;
BEGIN
SELECT A.*, CT.CUSTOMER_ID
FROM CUSTOMER_TABLE CT
RIGHT JOIN
(
SELECT OT.COLUMN_ID, OT.SKU, OT.ORDERS
FROM ORDERS_TABLE OT
WHERE @SKUS
)A
ON CT.ORDERS = OT.ORDERS
AND @SKUS IS > 0
END;
/
I am not sure if that is proper syntax but I hope the idea makes sense of what I am asking.
Thank you!