Skip to content
Advertisement

Creating and calling a function in a pl/sql program

I created a function to return a rental ID that is then used in an anonymous PL/SQL program that calculates the total cost of the rental given the price of the tool rented and the number of time units it was rented for. (ex. $5 tool rented for 4 hours = $20 rental total).

The code to create the function is:

The code to call the function is:

The program works properly if I use rental ID 1 as the parameter or any rental ID that doesn’t exist; however, for all of the other valid rental ID’s, I still get the same total is when passing rental ID 1.

Does anyone have an idea of what’s causing this? I know that using a function to return the rental ID (returned_rentalID) is redundant and not necessary; however, this is an exercise to become comfortable creating and calling functions so it’s necessary.

I really, truly appreciate any insight provided!

Below is some sample code for the tables I’m using:

Advertisement

Answer

First of all, thanks for including sample data. I changed your second select statement into an ANSI join and received different values for 1,2,and3:

I could not fully duplicate your results as there is no return_count function included in your example.

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