Friday, June 14, 2013

15th Example - Count the Discount Price on PL/SQL

Leave a Comment
At a store or a supermarket, the payment process is at the cashier. Cashier operator will do scanning of the item code by a barcode reader. The process of calculating the value of the groceries are automatically performed by the application at the cashier. Some items might get some discount if purchased. Here is an example of a block PL / SQL to perform automatic calculations that give a discount on an item of goods that are bought:

        harga NUMBER;
        diskon NUMBER;
        bayar NUMBER;
        harga := &input_harga;--obtained from barcode reader
        diskon := harga * 0.1; --10%
        bayar := harga - diskon;
        DBMS_OUTPUT.PUT_LINE ('Harga Barang = '||harga);
        DBMS_OUTPUT.PUT_LINE ('Diskon 10% = '||diskon);
        DBMS_OUTPUT.PUT_LINE ('Total Bayar = '||bayar);

There are 3 variables: harda with NUMBER data type, diskon with NUMBER data type and bayar with NUMBER data types. In the contents, the harga variable will be filled by substitution variable named input_harga. Diskon variable will contain a value that is 10% discount of the price. Harga Variable will contain the item price after discount. Those variables then displayed by using the command dbms_output.put_line ();. Suppose input_harga 1000 then the bayar will contain the value 900.
If You Enjoyed This, Take 5 Seconds To Share It


Post a Comment