Examine the following PL/SQL code:
The server output is on for the session. Which statement is true about the execution of the code?
A.
It displays null if no employee with empioyee_id 123 exists.
B.
It produces the ora-01403: no data found error if no employee with empioyee_id 123 exists.
C.
It displays an error because the select into clause cannot be used to populate the PL/SQL record type.
D.
The code executes successfully even if no employee with empioyee_id 123 exists and displays Record Not Found.
B is correct
why is it wrong? kindly explain.
Above code is worng because these erreneous condition should have been written in exception block.
Also it will come under no data found exception as shown in option B. Hence option B is correct.
B
It will be D
D, no hay nada malo en el codigo, el SQL%NOTFOUND evita el error de ORA y emite el mensaje correspondiente
B is correct.
If you enter employee_id = 1; it will display you ORA-01403: no data found
Sorry, my fault, B is correct
why it will not show ‘Record not found’?
Answer should be D…..
CORRECT ANSWER IS B,THIS WILL WORK IF WE USE A CURSOR
declare
CURSOR sales_cur IS select * from employee where empno=’123′;
EMP_VAR EMPLOYEE%ROWTYPE;
begin
OPEN sales_cur;
LOOP
FETCH sales_cur INTO EMP_VAR ;
DBMS_OUTPUT.PUT_LINE(‘HH’);
EXIT WHEN sales_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(‘Hb’);
END LOOP;
CLOSE sales_cur;
end;
OUTPUT IS ‘HH’
B is correct answer
example
==========
SQL> select * from emp;
EMPNO ENAME B_SALARY DEPT_NO
———- ————— ———- ———-
1 raja 5000 10
2 mani 6000 10
3 mala 4000 20
4 lalit 2500 30
5 ragu 7500 20
6 sita 3500 20
7 sukumar 7500 30
8 prem 4500 40
9 prabhu 5500 40
10 mohankumar 25000 10
10 rows selected.
SQL> declare
2 v_name varchar2(15);
3 v_salary number(15);
4 begin
5 select ename,b_salary into v_name,v_salary from emp
6 where empno=&a;
7 if sql%notfound then
8 dbms_output.put_line(’empno is not valid’);
9 else
10 dbms_output.put_line(v_name||v_salary);
11 end if;
12 end;
13 /
Enter value for a: 1
old 6: where empno=&a;
new 6: where empno=1;
raja5000
PL/SQL procedure successfully completed.
SQL> /
Enter value for a: 11
old 6: where empno=&a;
new 6: where empno=11;
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 5
exception:
==========
exception is a plsql error that raised during execution.
predefined exception -is managed by oracle server that implicity raised
implicity raises following exception
too_many_rows – raised- when ->means more than one row
invalid_cursor-raised when-> cursor is invalid
no_data_found -raised when -> data is not available
zero_divide -raised when ->number divide by zero
so select statement in pl/sql does not contain the data so excption raised implicity
appear no_data_found.
B
B
SQL%NOTFOUND attribute is not useful with the PL/SQL SELECT INTO st-t, because:
If the SELECT INTO st-t returns no rows, PL/SQL raises the predefined exception NO_DATA_FOUND ORA-01403 immediately, before you can check SQL%NOTFOUND.
si es la B
aguevo que shi
can any one explain me why is B??
and why is’t A,C or D????
pleaseeeeeeeeeeee
Thanks for all
The Simple way is try
select raise exception ‘no data found’ before go through next instruction
so, if statement will not be executed
B, SQL%NOTFOUND is not exception attribute , for exception please kindly use no_data_found.
questions are 100% valid. some answers are wrong. got 95% marks in 1z0-144 exam. thanks guys 🙂
email me [email protected] for valid dumps guys.happy to help u. 🙂