Question

Please help with the following code. I keep getting error ORA-06533: Subscript beyond count. I am...

Please help with the following code. I keep getting error ORA-06533: Subscript beyond count. I am trying to get the first 10 records in the emp table listed in reverse. I also get error ORA-6512. Please help.

DECLARE
CURSOR e_emp is
SELECT ename, sal FROM emp;
type namesarray IS VARRAY(10) OF emp.ename%type;
type salarray IS VARRAY(10) OF emp.sal%type;
names namesarray := namesarray();
salary salarray := salarray();
counter integer := 10;
BEGIN
FOR n IN REVERSE e_emp LOOP
counter := counter - 1;
names.extend;
salary.extend;
names(counter) := n.ename;
salary(counter) := n.sal;
dbms_output.put_line('Emp Name: '||names(counter)||', Salary:'|| salary(counter));
END LOOP;
END;

/

This is what I get when I run it in SQLPLUS:


SQL> DECLARE
2 CURSOR e_emp is
3 SELECT ename, sal FROM emp;
4 type namesarray IS VARRAY(11) OF emp.ename%type;
5 type salarray IS VARRAY(11) OF emp.sal%type;
6 names namesarray := namesarray();
7 salary salarray := salarray();
8 counter integer := 10;
9 BEGIN
10 FOR n IN REVERSE e_emp LOOP
11 counter := counter - 1;
12 names.extend;
13 salary.extend;
14 names(counter) := n.ename;
15 salary(counter) := n.sal;
16 dbms_output.put_line('Emp Name: '||names(counter)||', Salary:'|| salary(counter));
17 END LOOP;
18 END;
19 /
DECLARE
*
ERROR at line 1:
ORA-06533: Subscript beyond count
ORA-06512: at line 14

0 0
Add a comment Improve this question Transcribed image text
Answer #1


SQL> DECLARE
2 CURSOR e_emp is
3 SELECT ename, sal FROM emp;
4 type namesarray IS VARRAY(11) OF emp.ename%type;
5 type salarray IS VARRAY(11) OF emp.sal%type;
6 names namesarray := namesarray();
7 salary salarray := salarray();
8 counter integer := 10;
9 BEGIN
10 FOR n IN REVERSE e_emp LOOP
11 counter := counter - 1;
12 names.extend;
13 salary.extend;
14 names(counter) := n.ename;
15 salary(counter) := n.sal;
16 dbms_output.put_line('Emp Name: '||names(counter)||', Salary:'|| salary(counter));
17 END LOOP;
18 END;
19 /

At line no 6,7 array has been initializes. and in reversed loop is is extending one by one and adding value the array.

but counter starts from 10, initially name will have size 1. but here code is trying to use names(counter) := n.ename;

name(10):=n.ename

thats why that error is coming.

Solution.

first try to add name sal to respective array in ascending order only. then reverse all the array.

Add a comment
Know the answer?
Add Answer to:
Please help with the following code. I keep getting error ORA-06533: Subscript beyond count. I am...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please Explain why I am getting this error from the code below. ORA-06550: line 1, column...

    Please Explain why I am getting this error from the code below. ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'P_PRODUCT_INFORMATION' I have tried changing everything. Code is below. Table to use: CREATE TABLE ProductTable(     ProductID INTEGER NOT NULL primary key,     ProductName VARCHAR(50) NOT NULL,     ListPrice NUMBER(10,2),     Category INTEGER NOT NULL ); / INSERT INTO ProductTable VALUES(299,'Chest',99.99,10); INSERT INTO ProductTable VALUES(300,'Wave Cruiser',49.99,11); INSERT INTO ProductTable VALUES(301,'Megaland Play Tent',59.99,11); INSERT...

  • I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>"...

    I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>" at line 1, column 169." and "ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist." I do not know why this isn't working. Here is my code: DTCCDatabase.java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * This program creates the CoffeeDB database. */ public class DTCCDatabase {    public static void main(String[] args)...

  • I have most of the code for this assignment but need some help getting the rest....

    I have most of the code for this assignment but need some help getting the rest. Go to bottom to see what I have. Please help me figure out the foreach loops and the put() statement. In this assignment, you will be using a new data structure, HashMaps, to repeat Assignment 8.3. Main Method (5 points) Declare and initialize an HashMap with values of type of type Employee, and keys of type integer. In a while loop, keep initializing objects...

  • Please help in C: with the following code, i am getting a random 127 printed in...

    Please help in C: with the following code, i am getting a random 127 printed in front of my reverse display of the array. The file i am pulling (data.txt) is: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 when the reverse prints, it prints: 127 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 not sure why...please...

  • Been working on this program for hours and keep getting error. PLEASE help and show a...

    Been working on this program for hours and keep getting error. PLEASE help and show a working output, Thank you Step 2: Declaring variables Examining the problem we need to have 2 variable to store integer input given by the user.     int x,y; Step 3: setting up Scanner object and scanning the inputs import java.util.Scanner; Create Scanner class object by using following syntax Scanner=new Scanner(System.in); /* give some name to the object which ever you want */ Ask the...

  • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

    I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

  • please could you help me with the error i am getting while running this program void setup (){ Serial.begin (9600) //tu...

    please could you help me with the error i am getting while running this program void setup (){ Serial.begin (9600) //turn on serial monitor DHT11 sensor.begin (); initialize humidity sensor DHT11 Sensor pinMode (10, OUTPUT); //Must declare 10 an output and reserve it SD.begin (4): //Initialize the SD card reader void loop () DHT11 sensor.readTemperature ); // Read Temperature from DHT11 temp = hum DHT11 sensor.readHumidity ); //Read humidity FILE WRITE) SD.open ("PTData.txt"; mySensorData if (mySensorData) Serial.print ("The Temp is:...

  • I am getting an error that the variable num was not declared in the scope on...

    I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...

  • I am having trouble figuring out what is wrong with my code. This is the error...

    I am having trouble figuring out what is wrong with my code. This is the error I get for the last for loop. TypeError: list indices must be integers or slices, not list. This is the code: for line in fhr: ls = line.split(',') customer_list.append([ls[0], ls[1], ls[2], ls[3], ls[4], ls[5], ls[6], int(ls[7]), ls[8], ls[9], ls[10].strip('\n')]) from operator import itemgetter customer_list.sort(key=itemgetter(7), reverse=True) print(customer_list) writepath = './loan-data-output-v1.csv' fwh = open(writepath, 'w', encoding='utf-8') fwh.write('Name' +','+ 'State' +','+'Age' +','+'Annual Income'+','+   'Loan Type' +','+' Loan...

  • Can someone please help me. i keep getting an error in my code. I need it...

    Can someone please help me. i keep getting an error in my code. I need it to be on three seperate files! attached is my assignment and my code. c++ The class date Type implements the date in a program. Write the class functions as specified in the UML class diagram. The values for the month, day, and year should be validated (in the class functions) before storing the date into the data members. Set the invalid member data to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT