Can't Find Document
D. Becker, June 08, 2004 - 12:57 pm UTC
Tried finding the document (Note:258112.1) on MetaLink in various ways. I couldn't retrieve it. Would you give us the gist of the document?
June 08, 2004 - 1:30 pm UTC
A "SELECT <column> INTO <variable> ..." causing exception TOO_MANY_ROWS (ORA-1422) will initialize the variable if it is exactly the same datatype/precision as the column selected.
in 7.3.4 , the behaviour was different. First its checked whether Select statament is going to return one OR many rows and accordingly the variable is initialised whereas in Oracle 8 and onwards, pl/sql does the initial fetch, populates the variable and then check whether more rows are to be fetched.
WORKAROUND to get the same functionality as that of 7.3.4:-
-----------------------------------------------------------
Declare the variable and column with different datatypes as shown below
declare
dummy number(5); -- different type than emp.empno ..number(4)
begin
dbms_output.put_line('Body: dummy='||dummy);
select empno into dummy from emp;
exception when too_many_rows then
dbms_output.put_line('Exception: dummy='||dummy);
dbms_output.put_line(sqlerrm);
end;
/
Tariq, September 02, 2016 - 4:39 am UTC
Declare
w_ename varchar2(10);
Begin
Begin
select ename
into w_ename
from emp
where deptno = 20;
Exception when too_many_rows then
null;
when no_data_found then
null;
end;
dbms_output.put_line('w_ename --> '||w_ename);
end;
see the output in 2 different DB version
11.2.0.4 :
w_ename --> SMITH
PL/SQL procedure successfully completed.
12.1.0.2 :
w_ename -->
PL/SQL procedure successfully completed.
may I know the reason
September 02, 2016 - 3:55 pm UTC
Well, in 12.1.0.2 either:
- The enames are null
- There aren't any rows for deptno 20
- There is more than one row for deptno 20
What do you see if you run:
select * from emp where deptno = 20;
in your 12 database?