Home » SQL & PL/SQL » SQL & PL/SQL » Need answer for below block
Need answer for below block [message #643948] Fri, 23 October 2015 02:05 Go to next message
rajesh_oracle
Messages: 2
Registered: October 2015
Junior Member
DECLARE
TYPE name_rec
IS
RECORD
(
first_name VARCHAR2(20),
last_name VARCHAR2(25));
TYPE names IS VARRAY(250) OF name_rec;
v_names names :=names();


BEGIN
v_names:= names();

FOR i IN 1..5
LOOP
v_names.extend;
v_names(i).First_name :='FIRST_NAME'||I;
v_names(i).last_name :='LAST_NAME'||I;

DBMS_OUTPUT.PUT_LINE(v_names(i).first_name || '---' || v_names(i).last_name);
END LOOP;

END;


Current Output is
-------------------
anonymous block completed
FIRST_NAME1---LAST_NAME1
FIRST_NAME2---LAST_NAME2
FIRST_NAME3---LAST_NAME3
FIRST_NAME4---LAST_NAME4
FIRST_NAME5---LAST_NAME5

NEED OUTPUT AS
---------------------
anonymous block completed
FIRST_NAME A---LAST_NAME F
FIRST_NAME B---LAST_NAME G
FIRST_NAME C ---LAST_NAME H
FIRST_NAME E---LAST_NAME I
FIRST_NAME F---LAST_NAME J
Re: Need answer for below block [message #643949 is a reply to message #643948] Fri, 23 October 2015 02:13 Go to previous message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

Note we don't do homework but we can help you.
1/ To convert a number to a character you have CHR function
2/ To convert a character to a number you have ASCII function (this will give you the ASCII code for A
3/ The difference between the first and last names in a line is the number of iterations of your loop
(4/ Between C and E there is D)

Previous Topic: Unique hash based on user database objects.
Next Topic: Is there a limitation of connect by for Partitioned tables
Goto Forum:
  


Current Time: Wed Jun 24 05:26:42 CDT 2026