{"id":118,"date":"2025-03-06T12:43:06","date_gmt":"2025-03-06T12:43:06","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=118"},"modified":"2025-03-06T12:43:06","modified_gmt":"2025-03-06T12:43:06","slug":"pl-sql-block-for-employee-salary","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2025\/03\/06\/pl-sql-block-for-employee-salary\/","title":{"rendered":"Pl\/Sql Block For Employee Salary"},"content":{"rendered":"\n<p>Pl\/Sql Block For Employee Salary.<\/p>\n\n\n\n<p><strong>(a) Create the table <code>EmpDetails<\/code> and insert 5 records:<\/strong><\/p>\n\n\n\n<p>&#8212; Create the EmpDetails table<br>CREATE TABLE EmpDetails (<br>EmpId NUMBER PRIMARY KEY,<br>EmpName VARCHAR2(100),<br>BasicSalary NUMBER,<br>DA NUMBER,<br>NetPAY NUMBER<br>);<\/p>\n\n\n\n<p>&#8212; Insert 5 records into the EmpDetails table<br>INSERT INTO EmpDetails (EmpId, EmpName, BasicSalary, DA, NetPAY) VALUES (1, &#8216;Alpha Beta&#8217;, 45000, 0, 0);<br>INSERT INTO EmpDetails (EmpId, EmpName, BasicSalary, DA, NetPAY) VALUES (2, &#8216;Alps Connect&#8217;, 55000, 0, 0);<br>INSERT INTO EmpDetails (EmpId, EmpName, BasicSalary, DA, NetPAY) VALUES (3, &#8216;Alpesh Purohit&#8217;, 60000, 0, 0);<br>INSERT INTO EmpDetails (EmpId, EmpName, BasicSalary, DA, NetPAY) VALUES (4, &#8216;IT Prashnavali&#8217;, 40000, 0, 0);<br>INSERT INTO EmpDetails (EmpId, EmpName, BasicSalary, DA, NetPAY) VALUES (5, &#8216;Code with Alpesh&#8217;, 70000, 0, 0);<\/p>\n\n\n\n<p>&#8212; Commit the changes<br>COMMIT;<\/p>\n\n\n\n<p><strong>(b) Write a PL\/SQL block to calculate DA (125% of BasicSalary) and NetPay:<\/strong><\/p>\n\n\n\n<p>BEGIN<br>FOR emp IN (SELECT EmpId, BasicSalary FROM EmpDetails) LOOP<br>&#8212; Calculate DA as 125% of BasicSalary<br>UPDATE EmpDetails<br>SET DA = emp.BasicSalary * 1.25,<br>NetPAY = emp.BasicSalary + (emp.BasicSalary * 1.25)<br>WHERE EmpId = emp.EmpId;<br>END LOOP;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>COMMIT;<\/code><\/pre>\n\n\n\n<p>END;<\/p>\n\n\n\n<p><strong>(c) Write a PL\/SQL block that accepts <code>EmpId<\/code> from the user and fetches that employee&#8217;s salary from the table, and checks if the salary is more than 50,000:<\/strong><\/p>\n\n\n\n<p>DECLARE<br>v_EmpId NUMBER;<br>v_BasicSalary NUMBER;<br>BEGIN<br>&#8212; Accept EmpId from user<br>v_EmpId := &amp;EmpId; &#8212; This will prompt the user to enter the EmpId<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Fetch BasicSalary for the given EmpId\nSELECT BasicSalary INTO v_BasicSalary\nFROM EmpDetails\nWHERE EmpId = v_EmpId;\n\n-- Check if BasicSalary is more than 50,000\nIF v_BasicSalary &gt; 50000 THEN\n    DBMS_OUTPUT.PUT_LINE('Salary is more than 50,000');\nELSE\n    DBMS_OUTPUT.PUT_LINE('Salary is less than or equal to 50,000');\nEND IF;<\/code><\/pre>\n\n\n\n<p>END;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pl\/Sql Block For Employee Salary. (a) Create the table EmpDetails and insert 5 records: &#8212; Create the EmpDetails tableCREATE TABLE EmpDetails (EmpId NUMBER PRIMARY KEY,EmpName VARCHAR2(100),BasicSalary NUMBER,DA NUMBER,NetPAY NUMBER); &#8212; Insert 5 records into the EmpDetails tableINSERT INTO EmpDetails (EmpId, EmpName, BasicSalary, DA, NetPAY) VALUES (1, &#8216;Alpha Beta&#8217;, 45000, 0, 0);INSERT INTO EmpDetails (EmpId, EmpName, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":101,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,42],"tags":[25,26,43],"class_list":["post-118","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bca","category-concept-of-rdbms","tag-bca","tag-bca-paper-solution","tag-concept-of-rdbms"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/118\/revisions\/119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/101"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}