20th Example - Calculate Employee Salaries on PL/SQL

A company has many employees with various status, married and not married. A married employees would get salaries larger than the unmarried (at same level). Employees who are married will get married allowance. If you are married and have children will receive child support anyway. Here's an example of the calculation, if married will get salary + benefits of marriage, if you have children then salary + benefits + n * benefits of children otherwise will only get salary.
The following PL/SQL block to perform the calculation:

        nama VARCHAR2(32);
        status VARCHAR2(8);
        menikah VARCHAR2(1);
        nAnak NUMBER := 0;
        gaji NUMBER;
        tNikah NUMBER := 0.1;
        tAnak NUMBER := 0.05;
        nama := '&input_nama';
        status := '&input_status'; -- SINGLE/MARRIED
        nAnak := &input_nAnak;
        gaji := &input_gaji;--gaji pokok
        IF status = 'MARRIED' THEN
           IF nAnak = 0 THEN
             gaji := gaji + tNikah*gaji;
             gaji := gaji + tNikah*gaji + nAnak*gaji*tAnak;
           END IF;
        END IF;
        DBMS_OUTPUT.PUT_LINE ('Gaji '||nama||' = '||gaji);

On above PL/SQL, the salary calculation that will automatically make additions if the status MARRIED. Eg the employees' basic salaries is 1000 and status MARRIED then salary earned is 1100. If the status is married with 1 child, the salary earned is 1150. If the status is SINGLE salary earned is 1000.

The best thing about blogs, they just keep going

No comments

Powered by Blogger.