-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from punitsakre23/PunitSakre
Added PL/SQL code files
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
DECLARE | ||
|
||
v_COUNTRY_ID COUNTRIES.COUNTRY_ID%TYPE := 'ENG'; | ||
v_COUNTRY_NAME COUNTRIES.COUNTRY_NAME%TYPE := 'England'; | ||
v_REGION_ID REGIONS.REGION_ID%TYPE; | ||
v_REGION_NAME REGIONS.REGION_NAME%TYPE := 'USA'; | ||
v_COUNT PLS_INTEGER; | ||
|
||
BEGIN | ||
|
||
SELECT COUNT(COUNTRY_NAME) | ||
INTO v_COUNT | ||
FROM COUNTRIES | ||
WHERE COUNTRY_NAME = v_COUNTRY_NAME; | ||
|
||
IF (v_COUNT = 0) THEN | ||
|
||
SELECT REGION_ID | ||
INTO v_REGION_ID | ||
FROM REGIONS | ||
WHERE REGION_NAME = v_REGION_NAME; | ||
|
||
INSERT INTO COUNTRIES | ||
VALUES (v_COUNTRY_ID, v_COUNTRY_NAME, v_REGION_ID); | ||
COMMIT; | ||
|
||
ELSE | ||
|
||
DBMS_OUTPUT.PUT_LINE('Country Already Exists'); | ||
|
||
END IF; | ||
|
||
END; | ||
|
||
--Output | ||
--Country Already Exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
DECLARE | ||
|
||
v_DEPT_ID EMPLOYEES.DEPARTMENT_ID%TYPE := 32; | ||
|
||
CURSOR CUR_EMP_DETAILS | ||
IS | ||
SELECT employee_ID, salary, hire_date FROM EMPLOYEES WHERE DEPARTMENT_ID = v_DEPT_ID; | ||
|
||
BEGIN | ||
|
||
FOR rec_EMPINFO IN CUR_EMP_DETAILS LOOP | ||
|
||
DBMS_OUTPUT.PUT_LINE ('Employee ID: ' || rec_EMPINFO.EMPLOYEE_ID); | ||
DBMS_OUTPUT.PUT_LINE ('Salary: ' || rec_EMPINFO.SALARY); | ||
DBMS_OUTPUT.PUT_LINE ('Hire DatIN e: ' || rec_EMPINFO.HIRE_DATE); | ||
DBMS_OUTPUT.PUT_LINE ('-------------------------------'); | ||
|
||
END LOOP; | ||
|
||
EXCEPTION | ||
|
||
WHEN OTHERS THEN | ||
DBMS_OUTPUT.PUT_LINE('Some error occured' || SQLERRM); | ||
|
||
END; | ||
|
||
--Output | ||
--Employee ID: 456 | ||
--Salary: 78000 | ||
--Hire Date: 25-MAY-01 | ||
--------------------------------- | ||
--Employee ID: 236 | ||
--Salary: 65000 | ||
--Hire Date: 12-DEC-99 | ||
--------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
DECLARE | ||
|
||
v_EMPLOYEE_ID NUMBER(6) := 912; | ||
v_FIRST_NAME VARCHAR2(20); | ||
v_PHONE_NUMBER VARCHAR2(25); | ||
v_EMAIL VARCHAR2(30); | ||
v_DEPARTMENT_ID NUMBER(2); | ||
|
||
BEGIN | ||
|
||
SELECT FIRST_NAME, PHONE_NUMBER, EMAIL, DEPARTMENT_ID | ||
INTO v_FIRST_NAME, v_PHONE_NUMBER, v_EMAIL, v_DEPARTMENT_ID | ||
FROM EMPLOYEES | ||
WHERE EMPLOYEE_ID = v_EMPLOYEE_ID; | ||
|
||
DBMS_OUTPUT.PUT_LINE ('Employee ID: ' || v_EMPLOYEE_ID); | ||
DBMS_OUTPUT.PUT_LINE ('First Name: ' || v_FIRST_NAME); | ||
DBMS_OUTPUT.PUT_LINE ('Phone Number: ' || v_PHONE_NUMBER); | ||
DBMS_OUTPUT.PUT_LINE ('Email: ' || v_EMAIL); | ||
DBMS_OUTPUT.PUT_LINE ('Department ID: ' || v_DEPARTMENT_ID); | ||
|
||
END; | ||
|
||
--Output | ||
--Employee ID: 912 | ||
--First Name: Bryan | ||
--Phone Number: 180.240.1010 | ||
--Email: BRYANS | ||
--Department ID: 11 |