Skip to content
Advertisement

Modifying a value in a table using PL/SQL

I have only just begun to learn procedures in SQL. I have hit a bit of a wall and can’t seem to come to a fix. I am trying to create a procedure that will allow me to pass the item description and a percentage of how much I would like to increase that items price. This is the code I have got so far:

The procedure will compile but will not accept my calling block:

The error report I receive:

Any help would be greatly appreciated, Thankyou.

Advertisement

Answer

It’s not advisable to hit the ITEM table twice. Firstly, in a multi-user system, the details could have changed between your initial query and the update. Secondly it’s inefficient, as it does twice as much work as it needs to.

I would simplify it to something like this:

I have included an escape character to allow callers to treat wildcard characters % and _ as literals if they need to.

I’ve converted the percentage to a multiplication factor, so for example 50 percent becomes 1.5, rather than multiplying the price by the percentage, dividing by 100, and adding the original price, as I find that clearer arithmetically, but that’s just my personal preference.

You used a p prefix for one of your two parameters (pItemDesc) and also for a local variable (pItemPrice). Code becomes confusing if variables are named like parameters and parameters are named like variables, so I recommend choosing one naming strategy and sticking with it.

Notice that code is easier to follow, work with and fix if it is neatly laid out, so I strongly recommend formatting like a programmer.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement