Saturday, 9 March 2019

DBMS FINAL HANDS ON


PL SQL FINAL HACKERRANK CODE ASSESSMENT

1)
SET SERVEROUTPUT ON;

DECLARE
    CURSOR C1 IS SELECT * FROM EMPLOYEES;
    E EMPLOYEES%ROWTYPE;
    GRADE VARCHAR2(40);
BEGIN
    OPEN C1;
    LOOP
        FETCH C1 INTO E;
        EXIT WHEN C1%NOTFOUND;
        IF ( E.SALARY >= 30000 ) THEN
            GRADE := 'Senior manager';
        ELSIF ( E.SALARY >= 25000 ) THEN
            GRADE := 'Middle manager';
        ELSIF ( E.SALARY >= 20000 ) THEN
            GRADE := 'Junior manager';
        ELSE
            GRADE := 'Team member';
        END IF;

        dbmsoutput.putline(E.NAME || ' ' || GRADE);
    END LOOP;
END;
/


2)
SET SERVEROUTPUT ON;

DECLARE
    CURSOR C1 IS SELECT * FROM SCORES WHERE SCORE < 100;
    LINE SCORES%ROWTYPE;
    total NUMBER := 0;
    num NUMBER;
    flag NUMBER;

BEGIN
    OPEN C1;
    LOOP
        flag :=1;
        FETCH C1 INTO LINE;
        EXIT WHEN C1%NOTFOUND;
        num := LINE.SCORE;
        FOR i IN 2..sqrt(num)
        LOOP
            IF ( mod(num, i) = 0 ) THEN
                flag := 0;
                exit;
            END IF;
        END LOOP;
        IF ( flag=1 ) THEN
            total := total + LINE.SCORE;
        END IF;
    END LOOP;
    dbmsoutput.putline('Total=' || total);
END;
/


SQL CODE ASSESSMENT

1) DEPARTMENT WHIHC DOES NOT CONTAIN PROGRAMMER POEPLE

SELECT DISTINCT D.DEPTNAME FROM EMPLOYEES E JOIN DEPARTMENTS D ON E.DEPTID=D.DEPTID WHERE E.DEPTID NOT IN (SELECT E.DEPTID FROM EMPLOYEES E JOIN DEPARTMENTS D ON E.DEPTID=D.DEPTID WHERE E.EMPSKILL LIKE 'Programmer');

2) SOME OTHER QUESTION

SELECT DISTINCT D.DEPTNAME, E.EMPSKILL FROM EMPLOYEES E JOIN DEPARTMENTS D ON E.DEPTID = D.DEPTID;

9 comments:

  1. pl/sql hackerank solution.for two question.. last print line must be like this.

    dbms_output.put_line("---------------");

    change it brooo..

    ReplyDelete
  2. DBMS_OUTPUT.PUT_LINE use this for printing

    ReplyDelete
    Replies
    1. Hey above code is not working. Can u send me the accurate code?

      Delete
  3. Pl/SQL in first program it is giving wrong output
    In SQL code assessment in both program it is showing error as "D"."DEPTID": invalid identifier

    ReplyDelete
    Replies
    1. it should be d.DEPT_ID....The identifier name is wrongly typed

      Delete
  4. Structure of two tables in the database are as below.
    1) Department table:
    Dept_Id number(5) primary key,
    Sept_Name varchar2(20),
    Employee_strength number(4) not null.

    2)Employee table:
    E_Id number(5),
    E_Name varchar2(20),
    Designation varchar2(20),
    D_ID number(5) references Department table Dept_ID.

    Write a pl/sql to print the name the departments which has employees having the designation as "SE",
    if no record in the department table fulfilling the given conditions found ,code should print the message "No record found" and if the record found code has to print Department name.

    ReplyDelete
    Replies
    1. Hey please provide the above program answers .

      Delete
  5. please provide answers for plsql final assessment

    ReplyDelete




  6. The Employees table has the following structure:
    ID Number(3),primary key,
    Name Varchar2(20),
    Salary Number(8,2)

    The grade is calculated based on the salary of the employee as below:
    If salary>=30000,the grade is 'Senior manager'
    If salary <30000 and >=25000, the grade is 'Middle manager'

    otherwise the grade is 'Team member'

    Write the plsql anonymous block to fetch the name of the employee ?



    please provide answer for this today my cource will be ended up....

    NOTE:- The above code which u guyz have uploaded is not correct out of 100 im gettings 50 marks so thats is fail.As soon as possible please provide the answer.

    ReplyDelete

ASP.NET Core: How to implement Azure Active Directory (AAD) Authentication in ASP.NET Core

  In this tutorial, we will implement security for ASP.NET Core Application using Azure Active Directory (AAD).  In this tutorial, I will co...