take one table is t1 and in that column name is f1
f1 column values are
200
5000
3000
7000
300
600
100
400
800
400
i want display the values asc and desc in a single output.
sample output is
f1.a
100
200
300
400
500
600
etc......
and f1.d is
5000
4000
3000
2000
1000
etc...

Answer Posted / suresh

declare
type xyz is ref cursor return t1%rowtype;
c1 xyz;
e t1%rowtype;
begin
open c1 for select f1 from t1 order by f1 asc;
dbms_output.put_line('ascending order result');
dbms_output.put_line('---------------------');
loop
fetch c1 into e;
exit when c1%notfound;
dbms_output.put_line(e.f1);
end loop;
dbms_output.put_line('---------------------');
dbms_output.put_line('descending order result');
dbms_output.put_line('---------------------');
close c1;
open c1 for select f1 from t1 order by f1 desc;
loop
fetch c1 into e;
exit when c1%notfound;
dbms_output.put_line(e.f1);
end loop;
close c1;
end;

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we use the cursor's to create the collection in PL/SQL?

520


What is trigger explain with example?

552


How can you maintain the integrity of your database on instances where deleting an element in a table result in the deletion of the element(s) within another table?

665


How do you declare a user-defined exception?

530


How do you know if a relationship is 2nf?

520






Why should I use postgresql?

566


Are there any features that are decommissioned in 11g that are not present in 11g?

1593


Is a foreign key always unique?

534


Why do we use procedures?

519


Is pl sql still used?

511


How to place comments in pl/sql?

604


Can delete statement be rollbacked?

527


How do you optimize a stored procedure in sql?

502


Does truncate release storage space?

560


Explain the difference between 'between' & 'and' operators in sql

531