PL/SQL function stops running after loop - oracle

I feel like this code has been working all day but all of a sudden it doesn't work anymore and I can't seem to find the solution.
This Loop is inside a big function so I'll only post this:
FOR i in 0..t_strGroups.count
LOOP
newStudentNumber := newStudentNumber || t_strGroups(i) || ' ';
dbms_output.put_line(newStudentNumber); -- this outputs fine
END LOOP;
dbms_output.put_line('test'); --this line doesn't output
When testing where the function stopped working I found that after this loop I can no longer output lines. Does anyone know what might have happened here?
Thanks in advance!

After thinking a bit more about this I found the answer.
In the loop I loop from 0 to t_strGroups.count. Because the first position of my collection is 0. but collection.count returns the ammount of values in the collection.
I have 5 values in my collection so collection.count returns 5. however, the last value in my collection has position 4. So when the loops gets to itteration 5 the code will crash. Since position 5 does not exist.
I guess it is just stupid of mine to overlook this. And I thought about removing this question. But I decided to post this answer. Maybe it can help someone some day!
EDIT:
According to the comment of Jeffrey Kemp the code doesn't crash it raises a NO_DATA_FOUND Exception. So it would also be smart to write an exception handler for that.

Related

Is there something I'm doing wrong to pick up this error?

I am new to Ti-basic, and I am trying to code it. I'm trying to make this 'special type of input' program. It is kind of like input, but it will show the word as it is being pressed (and there is no need to put in alpha)
Here is the code so far that I believe is pertaining to the error
:{41,42,43,51,52,53,54,55,61,62,63,64,65,71,72,73,74,75,81,82,83,84,85,91,92,93,94,102,103,103}→∟KEYS
:"ABCDEFGHIJKLMNOPQRSTUVWXYZθ :?"→Str7
:0→K
:""→Str1
:
:Repeat K=105
:getKey→K
:If max(∟KEYS-K)
:prgmFINDIND
:.........
:End
Inside prgmFINDIND, This is the code
:1+sum(not(cumSum(∟KEYS=K)))→I
://I is used later on in the code. It isn't pertaining to the problem.
I have done some testing with pause on this already, and I found the problem was in the if statement. It returns an 'INVALID DIM' error.
Anybody know what's wrong?
In this part (edited a bit)
Repeat K=105
getKey->K
If max(|LKEYS=K
prgmFINDIND
Str1+sub(Str7,I,1->Str1
End
prgmFINDIND is only called if the key that was pressed is in the list, otherwise the index I is not changed (and possibly implicitly zero, or whatever other value that was left there).
Pressing GOTO on the INVALID DIM actually goes to Str1+sub(Str7,I,1->Str1, indicating that a bad index was used to index into Str7.
It could be fixed by using an If/Then block, which can cover more than one statement:
Repeat K=105
getKey->K
If max(|LKEYS=K
Then
prgmFINDIND
Str1+sub(Str7,I,1)->Str1
End
End

Very simple procedure statement from school slide. I want to know how it works

create or replace procedure HelloWorld(s varchar)
as
begin
dbms_output.put_line(s);
end;
-------- click execute button now
exec HelloWorld('Hello');
The codes above is from the school slide. The first code is shown as 'procedure created' which means good to go. When I execute it by using 'exec HelloWorld(‘Hello’);', it shows errors. May I ask some of question regarding this code please?
1) Why it does not work when I execute it?
2) I know that 's' is a parameter, and 'varchar' is the datatype for 's'. However, the code requires that print 's'. As I can see, there is nothing to assigned on 's'. Then, how can the code runs the value of 's' in 'dbms_output.put_line(s);'?
3)Can anybody just explain what is the basic function for each single word?

why does sorting a table in Lua doesn't work

I have a piece of Lua code that generate an error and I don't understand how to solve it.
.............................
local last_num = 0
local channelTable={}
for num in channels.each_number() do -- channels.each_number() returns 1.number in each call
channelTable[last_num] =num;
last_num = last_num +1;
end
table.sort(channelTable);
based on lua documentation I can use the function sort to sort the saved numbers in channelTable. the error that I get is:
attempt to index global 'table'
Any idea how can I solve this, or should implement bubble sort?
thanks for any hint!
Either you haven't loaded the table library or you have overwritten it by accident.
The error message seems truncated: it should say why indexing failed.
The error you are seeing indicates that the table library is not available. It's unlikely that this core library isn't part of your Lua environment, so it's likely you have assigned something to table elsewhere in your code.
I think the issue may be that you are expecting channels.each_number() to be called in each iteration of the loop. If I'm not mistaken, I think it only gets called the first time the program goes through the loop. Whatever you use in thefor..in loop needs to be a table, I believe. So I guess the problem is that your table isn't being generated as you want it to. Try doing this:
print('number of items in channelTable = ' .. #channelTable)
If it comes out to 0, then what I said is probably the problem.

Basic for loop in Python 3

I'm a beginner to Python and I'm having some trouble with this. I have to make a for loop out of this problem. Can anyone explain how I would go about this?
nextNValues (startValue, increment, numberOfValues)
This function creates a string of numberOfValues values, starting with startValue and
counting by increment. For example, nextNValues (5, 4, 3) would generate a string of
(not including the comments):
5 - the start value
9 - counting by 4, the increment
13 - stopping after 3 lines of output, the numberOfValues
You could use range(startValue,startValue+(increment*numberofValues),increment).
for i in range(numberOfValues):
print startValue + i * increment
I am not sure if that is exactly what you are looking for... but it is my suggestion based on the information you have posted.
It would probably be easiest to write a for loop with an index like i and use that to add i*increment ti start value and save the resulting value to a list. Have the loop run numberOfValues times. If this is homework it would be better for you to write out the actual code for yourself

VHDL integer'image Returns "0"

Here is my dilemma:
I'm very new to programming in VHDL, and I'm currently working on an independent study project for a university class. I've made some descent headway, but I've run into an issue I haven't been able to solve.
What I'm trying to do is to display a "register" (or registers) on an LCD monitor and have it update periodically. For the time being, these values will always be integer numbers.
I have code written which displays numbers properly on the screen if that value is passed as a variable that is never altered or as a hard-coded value. However, I want to update a variable by adding to it, then pass that to my function and display it.
Essentially what I'm trying to do is this:
Every 'x' clock ticks, increment a register's value, pass that to my update_screen function which returns a new screen, and then display that further below. However, once I increment or change through reassignment (doesn't seem to matter if it is variable or a signal), all I see is '0' on the screen.
So... The following code properly updates my display unless I uncomment the commented lines. At that point, it just shows '0'.
--currentRegVal := currentRegVal + 1;
--screenVal <= 25;
-- screen holds the values for the current screen
-- The second argument is the row on the screen to be updated
-- The third argument is the value to display there
screen := update_screen(screen, 1, currentRegVal);
screen := update_screen(screen, 0, screenVal + 25);
The problem seems to be stemming from the integer'image attribute (or more accurately, my understanding of it). When I pass in a hardcoded value or a variable that hasn't been altered, it returns what I expect. However, as soon as I modified the variable/signal in ANY way it seems to return the string "0".
Below is my update_screen function:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is
-- A function may declare local variables. These do not retain their values between successive calls,
-- but are re-initialised each time. Array-type parameters may be unconstrained:
constant screenWidth: integer := screen'length(2);
constant strRegVal: string := integer'image(regVal);
constant strRegLen: integer := strRegVal'length;
variable newScreen: screenData := screen;
begin
for dex in 1 to screenWidth loop
if dex <= strRegLen then
newScreen(reg, dex-1) := strRegVal(dex);
else
newScreen(reg, dex-1) := ' ';
end if;
-- The next two ifs were my attempt to figure out what
-- was going on...
--The value itself never seems to be 0... the screen is not all 5's
if regVal = 0 then
newScreen := (others => (others => '5'));
end if;
-- But the string value is "0" if the variable/signal is ever modified...
-- 'd' shows up in the designated row.
if strRegVal = "0" then
newScreen(reg*3, 1) := 'd';
end if;
end loop;
return newScreen;
end update_screen;
A couple important points (added 2011-07-26):
I'm using the Quartus II free (web) edition to design/compile my project.
The code which is updating the variables is in a process.
At the time of the original posting, the only steps I had taken were to compile my code and program an Altera DE2 FPGA board with the result (I wasn't sure how to perform any kind of simulations).
Thanks in advance for any help and advice. Also, as I said, I'm new to VHDL programming, so if there is a much better way to do something I'm doing here, please let me know. I would also greatly appreciate useful links to any resources about the language itself.
Update (2011-07-26):
I downloaded GHDL as Martin Thompson suggested, but I have not actually used it yet because I'm not sure how to go about doing so with my current Quartus II project (or if I even can). I'll have to do some reading before it is useful to me. However, yesterday I managed to install ModelSim-Altera which works directly with Quartus II and allowed me to perform some simulation.
I did my best to set up some waveforms that would allow me to test, and I was at least able to examine the execution of the code which I believed to be failing. However, during simulation, I've verified in multiple ways that the "screen" object does contain the value I want it to contain after the *screen_update* function runs. When running on the Altera DE2, however, it still fails.
Note: I did verify that the screen actually does update by directly setting the value of a particular element on the screen to different values depending on whether or not the currentRegVal is even or odd.
I'll plan on posting some code tomorrow, but for now:
What reasons are there that simulation would provide different results? My guess is something to due with timing, but it is really just a guess. If I am correct, how can I go about trying to resolve the issue?
I guess the problem is related to the fact that you declared strRegVal as a constant. I think it should better be a variable, e.g. something like this might work:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is
...
variable strRegVal: string;
variable strRegLen: integer;
...
begin
strRegVal := integer'image(regVal);
strRegLen := strRegVal'length;
...
end update_screen;
Assuming this code is in a process:
screenVal <= 25;
-... snip...
screen := update_screen(screen, 0, screenVal + 25);
screenVal won't have updated to a new value yet (unless some time passes - a wait statement between the write and the read)

Resources