Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

2 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

-- QUES 1

DECLARE

DAY VARCHAR(15);

BEGIN

DAY :='SATURDAY';

IF DAY IN ('SATURDAY', 'SUNDAY') THEN

-- IF DAY ='SATURDAY' OR DAY ='SUNDAY'

DBMS_OUTPUT.PUT_LINE ('THE DAY IS '||DAY||'. IT FALLS ON THE WEEKENDS.');

ELSE

DBMS_OUTPUT.PUT_LINE ('THE DAY IS '||DAY||'. IT DOES NOT FALLS ON THE WEEKENDS.');

END IF;

END;

--QUES2

DECLARE

GRADE CHAR(1);

BEGIN

GRADE :='C';

CASE GRADE

WHEN 'A' THEN dbms_output.Put_line('Your Grade is: Outstanding');

WHEN 'B' THEN dbms_output.Put_line('Your Grade is: Excellent');

WHEN 'C' THEN dbms_output.Put_line('Your Grade is: Very Good');

WHEN 'D' THEN dbms_output. Put_line('Your Grade is: Average');

WHEN 'F' THEN dbms_output.Put_line('Your Grade is: Poor');

ELSE dbms_output.Put_line('No such grade in the list.');

END CASE;

END;
-- QUES 3

DECLARE

get_ctr CHAR(1) := 9;

BEGIN

IF ( get_ctr >= 'A' AND get_ctr <= 'Z' )OR ( get_ctr >= 'a'AND get_ctr <= 'z' )

THEN

dbms_output.Put_line ('IT IS A LETTER');

ELSIF get_ctr BETWEEN '0' AND '9' THEN

dbms_output.Put_line ('TI IS A NUMBER');

ELSE

dbms_output.Put_line ('IT IS NEITHER A NUMBER NOR A LETTER');

END IF;

END;

-- QUES 4

DECLARE

temp NUMBER := 100;

scale CHAR := 'C';

new_temp NUMBER;

new_scale CHAR;

BEGIN

IF scale != 'C'AND scale != 'F' THEN

dbms_output.Put_line ('The scale you input is not a valid scale');

new_temp := 0;

new_scale := 'C';

ELSIF scale = 'C' THEN


new_temp := ( ( 9 * temp ) / 5 ) + 32;

new_scale := 'F';

ELSE

new_temp := ( ( temp - 32 ) * 5 ) / 9;

new_scale := 'C';

END IF;

dbms_output.Put_line ('THE NEW TEMERTURATURE IN '

||new_scale

||' IS: '

||new_temp);

END;

-- QUES5

DECLARE

i NUMBER(3);

j NUMBER(3);

BEGIN

dbms_output.Put_line('THE PRIME NUMBERS BETWEEN 1 TO 100 ARE:');

dbms_output.new_line;

i := 2;

LOOP

j := 2;

LOOP

EXIT WHEN( ( MOD(i, j) = 0 )

OR ( j = i ) );

j := j + 1;

END LOOP;

IF( j = i )THEN
dbms_output.Put(i||' ');

END IF;

i := i + 1;

exit WHEN i = 50;

END LOOP;

dbms_output.new_line;

END;

-- QUES 6

DECLARE

emp_min_salary NUMBER(6,0);

emp_max_salary NUMBER(6,0);

emp_mid_salary NUMBER(6,2);

tmp_salary EMPLOYEES.SALARY%TYPE;

tmp_emp_id EMPLOYEES.EMPLOYEE_ID%TYPE := 167;

tmp_emp_name EMPLOYEES.FIRST_NAME%TYPE;

BEGIN

SELECT min_salary,

max_salary

INTO emp_min_salary,

emp_max_salary

FROM JOBS

WHERE JOB_ID = (SELECT JOB_ID

FROM EMPLOYEES
WHERE EMPLOYEE_ID = tmp_emp_id);

emp_mid_salary := (emp_min_salary + emp_max_salary) / 2;

SELECT salary,first_name

INTO tmp_salary,tmp_emp_name

FROM employees

WHERE employee_id = tmp_emp_id;

IF tmp_salary < emp_mid_salary THEN

UPDATE employees

SET salary = emp_mid_salary

WHERE employee_id = tmp_emp_id;

ELSE

UPDATE employees

SET salary = salary + salary * 10 /100

WHERE employee_id = tmp_emp_id;

END IF;

IF tmp_salary > emp_mid_salary THEN

DBMS_OUTPUT.PUT_LINE('The employee '||tmp_emp_name||' ID ' || TO_CHAR(tmp_emp_id) ||

' works in salary ' || TO_CHAR(tmp_salary) ||

' which is higher than mid-range of salary ' || TO_CHAR(emp_mid_salary));

ELSIF tmp_salary < emp_mid_salary THEN

DBMS_OUTPUT.PUT_LINE('The employee '||tmp_emp_name||' ID ' || TO_CHAR(tmp_emp_id) ||

' works in salary ' || TO_CHAR(tmp_salary) ||

' which is lower than mid-range of salary ' || TO_CHAR(emp_mid_salary));

ELSE

DBMS_OUTPUT.PUT_LINE('The employee '||tmp_emp_name||' ID ' || TO_CHAR(tmp_emp_id) ||

' works in salary ' || TO_CHAR(tmp_salary) ||

' which is equal to the mid-range of salary ' || TO_CHAR(emp_mid_salary));

END IF;
END;

-- QUES7

DECLARE

num1 NUMBER := 020;

BEGIN

IF num1 < 0 THEN

DBMS_OUTPUT.PUT_LINE ('ENTERED NUMBER '||num1||' IS A NEGATIVE NUMBER');

ELSIF num1 = 0 THEN

DBMS_OUTPUT.PUT_LINE ('ENTERED NUMBER '||num1||' IS ZERO');

ELSE

DBMS_OUTPUT.PUT_LINE ('ENTERED NUMBER '||num1||' IS A POSITIVE NUMBER');

END IF;

END;

You might also like