0

I don't know how to execute or test this procedure. I'm new in that area. Thanks in advance.

Table Prices has id,price, datePrice and productId. Table Products has id, currentprice and name

        create or replace PROCEDURE "currentprice"
        (idproduct IN NUMBER) AS
        currentprice products.current_price%type;
        BEGIN
         SELECT price INTO currentprice 
         FROM prices
         WHERE productId=idprice AND datePrice=(select max(datePrice) FROM prices WHERE 
          productId=idprice AND datePrice<=SYSDATE);

          UPDATE products
          SET currentprice = currentprice 
          WHERE id=idproduct;
           END;
4
  • Does this answer your question? How to execute an oracle stored procedure? Commented Dec 21, 2019 at 17:54
  • Nope. I get error "no data found" after executed that Commented Dec 21, 2019 at 17:59
  • Oracle errors usually start with a code like ORA, PLS or SP2. How did you call it exactly, and what was the whole error message? The query of prices might fail with no data found if there was no price stored for the specified idproduct (or productId - was that a typo?) Commented Dec 22, 2019 at 16:06
  • OK. I figured out somehow where is my mistake. I get PL/SQL procedure successfully completed. Now I need to test this. Commented Dec 22, 2019 at 17:14

2 Answers 2

1
Begin
 "currentprice"(1);
End;
/

Commit;

Execute with F5 in SQL Developer, then query your table data to see the new prices.

I recommend you rename your procedure to currentprice - no quotes...you'll save yourself a lot of trouble.

You can also browse to the procedure in SQL Developer and open it, then use the Execute button.

Sign up to request clarification or add additional context in comments.

Comments

0

I renamed procedure - no quotes. No data found again.

I have trigger which call that procedure

     create or replace TRIGGER currentprice2
       AFTER INSERT OR UPDATE OR DELETE ON Prices
       DECLARE
       s NUMBER:=priceproduct.id;
       BEGIN
        currentprice(s);
       END;

Also, I have package. Maybe I made mistake with package parameter id.

      create or replace PACKAGE priceproduct IS
      id products.id%TYPE;
      END priceproduct;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.