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
Can we use the cursor's to create the collection in PL/SQL?
What is trigger explain with example?
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?
How do you declare a user-defined exception?
How do you know if a relationship is 2nf?
Why should I use postgresql?
Are there any features that are decommissioned in 11g that are not present in 11g?
Is a foreign key always unique?
Why do we use procedures?
Is pl sql still used?
How to place comments in pl/sql?
Can delete statement be rollbacked?
How do you optimize a stored procedure in sql?
Does truncate release storage space?
Explain the difference between 'between' & 'and' operators in sql