1

I am trying to execute the procedure that I created, however whenever I do EXEC ProductLineSale; it tells me Error(456,1): PLS-00103: Encountered the symbol "EXEC"

ALTER TABLE Product

ADD SalePrice DECIMAL(6,2); 

CREATE OR REPLACE PROCEDURE ProductLineSale 

AS 

BEGIN 

UPDATE Product
SET SalePrice = 0.90 * ProductStandardPrice
WHERE ProductStandardPrice >= 400;

 UPDATE Product
SET SalePrice = 0.85 * ProductStandardPrice
WHERE ProductStandardPrice < 400;

END;

EXEC ProductLineSale;

select *
FROM Product;
0

4 Answers 4

1

You're missing a '/' - this tells SQL Developer that your stored procedure declaration is finished and you're ready to compile it.

Add a '/' after the END; and before the EXECUTE.

--create table product (id integer,
--                      productstandardprice number(7,2));
--                      
--insert into product values (1, 19.95, 0);
--insert into product values (2, 7995.99);
alter table PRODUCT add SALEPRICE decimal(6, 2);

create or replace procedure PRODUCTLINESALE as
begin
  update PRODUCT
     set
    SALEPRICE = 0.90 * PRODUCTSTANDARDPRICE
   where PRODUCTSTANDARDPRICE >= 400;

  update PRODUCT
     set
    SALEPRICE = 0.85 * PRODUCTSTANDARDPRICE
   where PRODUCTSTANDARDPRICE < 400;

end;
/

exec PRODUCTLINESALE;

select *
  from PRODUCT;

I selected the create and everything after with my cursor, and then hit F5

enter image description here

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

Comments

0

You are missing / before EXEC to close PROCEDURE

See why we need forward slash:

For other PL/SQL blocks, including Procedures, Functions, Packages and Triggers, because they are multiple line programs, Oracle need a way to know when to run the block, so we have to write a forward slash at the end of each block to let Oracle run it.

6 Comments

I tried this, but I still am getting the same error.
@alphaX Add / before
Add the / before what?
@alphaX before execute, so previous statement is closed
EXECUTE is a SQL*Plus command. EXEC is an accepted abbreviation of exactly the same thing.
|
0

You need to enclose it with Begin and End

ALTER TABLE Product

ADD SalePrice DECIMAL(6,2); 

CREATE OR REPLACE PROCEDURE ProductLineSale 

AS 

BEGIN 

UPDATE Product
SET SalePrice = 0.90 * ProductStandardPrice
WHERE ProductStandardPrice >= 400;

 UPDATE Product
SET SalePrice = 0.85 * ProductStandardPrice
WHERE ProductStandardPrice < 400;

END;

BEGIN
EXECUTE ProductLineSale;
END;

select *
FROM Product

3 Comments

I did this, but then I get the same error number but this time with the word Begin.
what is the name of your package ?
What do you mean the name of my package?
0

On a different note, you may have a single update statement which would be more efficient than two statements.

UPDATE product
SET saleprice =
          CASE
               WHEN productstandardprice >= 400 THEN 0.90 * productstandardprice
               WHEN productstandardprice < 400  THEN 0.85 * productstandardprice
          END;

Furthermore, It is advisable not to have another column in the table if it can be generated easily from existing columns. You should prefer VIRTUAL COLUMNS

So, you may redefine the saleprice column

ALTER TABLE product ADD (
      SalePrice    DECIMAL(6,2)  GENERATED ALWAYS AS (
               CASE
                    WHEN productstandardprice >= 400 THEN 0.90 * productstandardprice
                    WHEN productstandardprice < 400  THEN 0.85 * productstandardprice
               END
          )
);

Now, the column will automatically display the computed value when you run a select from the table

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.