Please excuse the basic nature of these questions - I'm just starting off.
This example is taken from Oracle PL/SQL 101 - Osborne/McGraw-Hill - ISBN
0-07-212606-X - page 314
Numbers to the left are line numbers for reference only. Hopefully I haven't
made any typing mistakes.
1. DECLARE
2. CURSOR product_cur IS
3. SELECT * FROM plsql101_produc t
4. FOR UPDATE OF product_price;
5. BEGIN
6. FOR product_rec IN product_cur
7. LOOP
8. UPDATE plsql101_produc t
9. SET product_price = (product_rec.pr oduct_price =
0.97)
10. WHERE CURRENT OF product_cur
11. END LOOP;
12. END;
Am I correct to say the following?
The way a cursor works is that once a record is fetched it is taken out of
the cursor. This works well until the last record is reached at which time
fetch will continue to return the last record in the cursor unless you use
the %FOUND and %NOTFOUND constructs to test for the last record?
The cursor loop used in the above example eliminates the need to open, close
and fetch. It also eliminates the need to check for the last record.
There is no formal declaration of the cursor name "product_re c" first used
on line 6. Is this an example of an implicit cursor of table-based record
type?
On line 9 how does PL/SQL know that there is a product_price field in the
cursor record? Is this also part of the implicit cursor definition?
Thanks
J. 2 13471
UNIXNewBie wrote: Please excuse the basic nature of these questions - I'm just starting off.
This example is taken from Oracle PL/SQL 101 - Osborne/McGraw-Hill - ISBN 0-07-212606-X - page 314
Numbers to the left are line numbers for reference only. Hopefully I haven't made any typing mistakes.
1. DECLARE
2. CURSOR product_cur IS
3. SELECT * FROM plsql101_produc t
4. FOR UPDATE OF product_price;
5. BEGIN
6. FOR product_rec IN product_cur
7. LOOP
8. UPDATE plsql101_produc t
9. SET product_price = (product_rec.pr oduct_price = 0.97)
10. WHERE CURRENT OF product_cur
11. END LOOP;
12. END;
Am I correct to say the following?
The way a cursor works is that once a record is fetched it is taken out of the cursor.
No, fetched is fetched - it "stays" until your fetch the next one.
This works well until the last record is reached at which time fetch will continue to return the last record in the cursor
No - just give it a try - oracle will generate an error
unless you use the %FOUND and %NOTFOUND constructs to test for the last record?
The cursor loop used in the above example eliminates the need to open, close and fetch. It also eliminates the need to check for the last record.
It's there: for x IN y : as long as there's an x fetched, do...
There is no formal declaration of the cursor name "product_re c" first used on line 6. Is this an example of an implicit cursor of table-based record type?
Ehhh - not sure about the semantics, but it sounds familiar. Undoubtedly
you'll get a concise, yes/no answer. On line 9 how does PL/SQL know that there is a product_price field in the cursor record? Is this also part of the implicit cursor definition?
You know, or need to know. As a programmer.
It is checked during compile, if the above is part of a procedure.
Inline...
--
Regards,
Frank van Bortel
Responses inline... The way a cursor works is that once a record is fetched it is taken out of the cursor.
IIRC, what you mean to say is that once a record is fetched it is popped out
of the "active set" (that is, the group of records meeting the query
requirements that are waiting to be fetched from the server) and fetched
into your execution context's (PGA) local memory.
This works well until the last record is reached at which time fetch will continue to return the last record in the cursor unless you use the %FOUND and %NOTFOUND constructs to test for the last record?
Well, with a cursor for loop like your code is using, the test for
CURSOR%NOTFOUND is implicit, so you'll never run into this problem.
However, if you have code that attempts to use fetch to pop a value off of
the active set into your execution context's memory, then the
CURSOR%NOTFOUND is set, but your local variables don't change - not even the
one you've fetched into. That's why you'll see the same item over and
over - fetch doesn't return the last item repeatedly (at least not as far as
I'm aware), you just keep reusing the same value which has not been replaced
by any newly fetched value. Try this code in SCOTT's schema, and you'll see
the last record repeated over several times because the loop (here, just a
normal while loop and not a cursor for loop) does not check for
CURSOR%NOTFOUND or CURSOR%FOUND:
declare
cursor c1 is select ename from emp;
myrec c1%rowtype;
x number(2) := 0;
begin
open c1;
fetch c1 into myrec;
while x < 40 loop
dbms_output.put _line (myrec.ename);
fetch c1 into myrec;
x := x + 1;
end loop;
end;
/ The cursor loop used in the above example eliminates the need to open,
close and fetch. It also eliminates the need to check for the last record.
/
Yes, the open, fetch, and close statements are implicit with the cursor for
loop syntax.
There is no formal declaration of the cursor name "product_re c" first used on line 6. Is this an example of an implicit cursor of table-based record type?
No, but you're close. It's not a table-based record type, but rather a
cursor-based record type. It's as though the DECLARE section had a line at
the end that read as follows:
PRODUCT_REC PRODUCT_CUR%ROW TYPE On line 9 how does PL/SQL know that there is a product_price field in the cursor record? Is this also part of the implicit cursor definition?
It knows this because of the implicit declaration of the product_rec
variable (see above).
Hope this helps!
Chris
_______________ _______________ _____
Chris Leonard, The Database Guy http://www.databaseguy.com
Brainbench MVP for Oracle Admin http://www.brainbench.com
MCSE, MCDBA, OCP, CIW
_______________ _______________ _____ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AK |
last post by:
I don't want any part of the previous discussion on Visual Basic
versus Visual Basic.Net.
My query is about using Visual Basic for Applications; and whether it
is better to use Visual Basic 6 or Visual Basic.Net as a springboard
for studying VBA.
I use Office 2000 and would like to use VBA as a tool to customize it.
I have zero programming experience.
I would like to read through and work on the examples of a beginners
|
by: Orange Free |
last post by:
I want to create a program that will ask a user a series of questions
and then generate a Microsoft Word document whose content is dictated
by the answers. I am not a professional programmer, and I understand
only a little about OO programming. Should I
a) stick to -- *gasp* -- Visual Basic to accomplish my goal;
b) use Python, with which I am somewhat familiar, and which I would
prefer to use; or
|
by: Michael Foord |
last post by:
#!/usr/bin/python -u
# 15-09-04
# v1.0.0
# auth_example.py
# A simple script manually demonstrating basic authentication.
# Copyright Michael Foord
# Free to use, modify and relicense.
# No warranty express or implied for the accuracy, fitness to purpose
|
by: Steven O. |
last post by:
First, this may not be the correct newsgroup. I have some relatively
basic questions on SQL. I tried to find a newsgroup that was
specifically just about SQL, and was surprised to find that all the
SQL-related newsgroups seem to be product related. But if I missed
something, and someone can steer me to a correct newsgroup, please do
so.
My specific questions:
1. I want to put comments in an SQL script. For example, I want
|
by: Ramesh |
last post by:
hi,
Let me ask some basic questions.
Can anybody explain me about the following questions:
1. When we have to create sn key? Whenever we compiled
Component we have to create or it is a one time process?
2. What information contained in sn key. I gone through
that it is having public key. How it is using this key to
intract with client.
3. When we have to run gacutil.exe file. Whenever we
| |
by: Jim H |
last post by:
If there is a site someone can point me to that answers such basic
questions, rather than taking up support's time posting answers, please let
me know.
I've developed C# .NET, unmanaged C++, and MFC applications. I have not
written any C++.NET apps yet and have some very basic questions.
Are managed C++ programs fully independent executables or are they still
processed at run time like C# and vb.net apps are? Is the finished product...
|
by: Fay Yocum |
last post by:
BEWARE beginner questions!!
I have some experience in Access but never as much as I want or need. I have
decided to get in on VB.Net. I would only
rate myself in Access as a Beginner/Intermediate VBA programmer. I have
decided to go at learning VB.Net in a
more organized manner. I have some questions where answers are not becoming
clear with VB.Net. So here goes.
1 All of the books I have accessed do basic one-two form examples...
|
by: software2006 |
last post by:
ASP And Visual Basic Interview questions and answers
I have listed over 100 ASP and Visual Basic interview questions and
answers
in my website
http://www.geocities.com/myinterviewquestions/ASPAndVisualBasic.htm
So please have a look and make use of it.
|
by: Goran Djuranovic |
last post by:
Hi all,
I am experiencing a strange thing happening with a "designer.vb" page. Controls I manually declare in this page are automatically deleted after I drop another control on a ".aspx" page.
- Why is this happening?
- Can I disable automatic declaration and have everything be declared manually?
- Any other options to fix this?
Thanks in advance.
Goran Djuranovic
|
by: LayneMitch via WebmasterKB.com |
last post by:
Hello.
This is a basic quiz. Only about 3 questions. I'm having issue with the
answer key which stays on a certain value regardless of acknowledging that
you have the correct answer for the first and moving on to the next answer.
Here's the code:
<html><head><title>Problem7</title>
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |