Skip to content

Commit

Permalink
Merge pull request #47 from punitsakre23/PunitSakre
Browse files Browse the repository at this point in the history
Added PL/SQL code files
  • Loading branch information
TharinduDilshan authored Oct 20, 2021
2 parents 9dbf511 + 7592c6b commit a4c2936
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
36 changes: 36 additions & 0 deletions PLSQL/ConditionalConstructs.txt
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
35 changes: 35 additions & 0 deletions PLSQL/CursorForLoop
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
---------------------------------
29 changes: 29 additions & 0 deletions PLSQL/Variables_DataTypes_PrintStatements.txt
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

0 comments on commit a4c2936

Please sign in to comment.