Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
4
Indexable
Certainly! Below is the complete code for both the SQL query to trim the trailing spaces from the `FIRST_NAME` column in the `Employee` table and the PL/SQL program with a function to calculate the annual salary based on the monthly salary in Oracle.

First, here's the SQL query to trim trailing spaces:

```sql
SELECT RTRIM(FIRST_NAME) AS FIRST_NAME_CLEANED
FROM Employee;
```

Next, here's the PL/SQL program including the function definition and the anonymous block to demonstrate the function's usage:

```plsql
-- Function to calculate the annual salary
CREATE OR REPLACE FUNCTION Calculate_Annual_Salary (monthly_salary IN NUMBER)
RETURN NUMBER IS
  annual_salary NUMBER;
BEGIN
  annual_salary := monthly_salary * 12;
  RETURN annual_salary;
END;
/

-- Anonymous block to demonstrate the usage of the function
SET SERVEROUTPUT ON;
DECLARE
  monthly_salary_emp NUMBER := 5000; -- Assuming 5000 is the monthly salary
  annual_salary_emp NUMBER;
BEGIN
  annual_salary_emp := Calculate_Annual_Salary(monthly_salary_emp);
  DBMS_OUTPUT.PUT_LINE('Annual Salary: ' || annual_salary_emp);
END;
/
```

Ensure to execute the `CREATE OR REPLACE FUNCTION` part in Oracle to compile and store the function in the database. After that, you can run the anonymous block to see the output of the function.

Keep in mind, if you're using an environment like SQL Developer, the `SET SERVEROUTPUT ON;` command might not be needed, and you would typically use the interface's controls to enable the output from `DBMS_OUTPUT`.
Editor is loading...