473,805 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PROC Problem : Select for update

Hello,
I am working with Oracle 9Ri2 version on Linux AS 2.1 for IA64.

I have a problem when i try to lanch the following program :
EXEC SQL PREPARE MyStmt FROM
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR
UPDATE;

EXEC SQL DECLARE MyCursor CURSOR FOR MyStmt;

EXEC SQL OPEN MyCursor;

EXEC SQL DESCRIBE MyStmt into q_APP;
EXEC SQL FETCH MyCursor into :Var1;

EXEC SQL CLOSE MyCursor;

When I don't use the PREPARE Statement i don't have problem. But when
i add the PREPARE statement program crached when it try to Open Cursor
( EXEC SQL OPEN MyCursor)

Thank you for your help.
Jul 19 '05 #1
4 13815
rb*******@hotma il.com (Oracle 9Ri2 AS 2.1 IA 64) wrote in message news:<7f******* *************** ****@posting.go ogle.com>...
Hello,
I am working with Oracle 9Ri2 version on Linux AS 2.1 for IA64.

I have a problem when i try to lanch the following program :
EXEC SQL PREPARE MyStmt FROM
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR
UPDATE;

EXEC SQL DECLARE MyCursor CURSOR FOR MyStmt;

EXEC SQL OPEN MyCursor;

EXEC SQL DESCRIBE MyStmt into q_APP;
EXEC SQL FETCH MyCursor into :Var1;

EXEC SQL CLOSE MyCursor;

When I don't use the PREPARE Statement i don't have problem. But when
i add the PREPARE statement program crached when it try to Open Cursor
( EXEC SQL OPEN MyCursor)

Thank you for your help.


Try using PL/SQL

declare
cursor work_cur is
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR UPDATE;
begin
for x in work_cur loop
update tab1 set champ1 = 'test'
where current of work_cur;

end loop;

commit;
end;
/
Jul 19 '05 #2
J
rb*******@hotma il.com (Oracle 9Ri2 AS 2.1 IA 64) wrote in message news:<7f******* *************** ****@posting.go ogle.com>...
Hello,
I am working with Oracle 9Ri2 version on Linux AS 2.1 for IA64.

I have a problem when i try to lanch the following program :
EXEC SQL PREPARE MyStmt FROM
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR
UPDATE;

EXEC SQL DECLARE MyCursor CURSOR FOR MyStmt;

EXEC SQL OPEN MyCursor;

EXEC SQL DESCRIBE MyStmt into q_APP;
EXEC SQL FETCH MyCursor into :Var1;

EXEC SQL CLOSE MyCursor;

When I don't use the PREPARE Statement i don't have problem. But when
i add the PREPARE statement program crached when it try to Open Cursor
( EXEC SQL OPEN MyCursor)

Thank you for your help.


You don't need a prepare as u are not using any bind variables.
Also i wonder why u are using describe . its not needed.

Best Regards
J
Jul 19 '05 #3
r0***@insightbb .com (Wario) wrote in message news:<92******* *************** ****@posting.go ogle.com>...
rb*******@hotma il.com (Oracle 9Ri2 AS 2.1 IA 64) wrote in message news:<7f******* *************** ****@posting.go ogle.com>...
Hello,
I am working with Oracle 9Ri2 version on Linux AS 2.1 for IA64.

I have a problem when i try to lanch the following program :
EXEC SQL PREPARE MyStmt FROM
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR
UPDATE;

EXEC SQL DECLARE MyCursor CURSOR FOR MyStmt;

EXEC SQL OPEN MyCursor;

EXEC SQL DESCRIBE MyStmt into q_APP;
EXEC SQL FETCH MyCursor into :Var1;

EXEC SQL CLOSE MyCursor;

When I don't use the PREPARE Statement i don't have problem. But when
i add the PREPARE statement program crached when it try to Open Cursor
( EXEC SQL OPEN MyCursor)

Thank you for your help.


Try using PL/SQL

declare
cursor work_cur is
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR UPDATE;
begin
for x in work_cur loop
update tab1 set champ1 = 'test'
where current of work_cur;

end loop;

commit;
end;
/

Why use the declare?

begin
for x in (
SELECT CHAMP1
FROM TAB1
WHERE CHAMP2="4"
AND CHAMP3 = "C" FOR UPDATE
)
loop
update tab1 set champ1 = 'test'
where current of work_cur;

end loop;

commit;
end;
Jul 19 '05 #4
> >
Try using PL/SQL

declare
cursor work_cur is
SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR UPDATE;
begin
for x in work_cur loop
update tab1 set champ1 = 'test'
where current of work_cur;

end loop;

commit;
end;
/

Why use the declare?

begin
for x in (
SELECT CHAMP1
FROM TAB1
WHERE CHAMP2="4"
AND CHAMP3 = "C" FOR UPDATE
)
loop
update tab1 set champ1 = 'test'
where current of work_cur;

end loop;

commit;
end;


Danes,

I like declares. In this case I use it to add readability, as long as
performance is not affected. Your suggestion works great though.

Wario
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
4284
by: EmbersFire | last post by:
I'm using a stored proceedure which should update a number of rows in a table depending on a key value supplied (in this case 'JobID'). But what's happening is when I call the proc from within the program, only one row gets updated. So When I call the proc from Query Analyser, all rows get updated. When I call the proc from within the program, only one row gets updated
6
1616
by: CJM | last post by:
I've created a Stored Procedure which adds a new record and updates some more records and then returns the primary key for the added record. The SP seems to work OK, but I'm having problems getting at the returned key in my ASP code: "Item cannot be found in the collection corresponding to the requested name or ordinal." A common error, but in this case I can't see why... I output the SQL
4
2298
by: CSDunn | last post by:
Hello, I have a combo box (Combo7) that needs to call a function during the After Update event of the combo box. The function resides in an Access 2000 ADP Module called MMAnswerData_code. The following is the code of the function: Public Function SubFormRS(FrmTarget As Object) Forms!frmAD_OpeningForm!FrmTarget.RecordSource = "EXEC dbo.AdSubFormRecSource " & Forms!frmAD_OpeningForm!SubFormFilter
0
2357
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has to be based on either a View or a Table. I can almost always use a View, and it helps to do this since I can have better control over the size of the RecordSet of the subform. There are times when the use of a Stored Procedure would give me...
14
1839
by: Roy | last post by:
Apologies for the cross-post, but this truly is a two-sided question. Given the option of creating Looping statements within a stored proc of sql server or in the code-behind of an .net webpage, which would you choose and why? Reason I ask is I created a webpage which essentially runs through a litany of loops to determine which stored proc to kick off. This is written in the code-behind. It occurred to me that I could probably just...
1
2339
by: Phil Mc | last post by:
Trying to call a stored proc but some times don't want to have values inserted in some fields. Hi I am rewriting a VBS script which called a stored proc in a SQL server db. The proc takes a number of values both char and floats. Sometime it is a requirement that the stored proc will not be given a values for some of the floats.
10
4275
by: syntego | last post by:
I think I have discovered a bug in the handling of null values (vs NULL values) passed as parameters to a stored proc. I have always believed that the database handled NULL and null the same. The following statement returns the expected results: select case when NULL is null then 'SAME' else 'DIFFERENT' end from sysibm.sysdummy1; returns SAME.
4
1428
by: Trevor Bishop | last post by:
I'm having problems calling my second proc (MyProcedure2) from within an existing proc. MyProcedure2 does not seeem to fire this way. My code is below. Help appreciated. Thanks, Trevor ALTER procedure dbo.MyProcedure1 (@newsletterid int) AS
3
1467
by: ocmeng | last post by:
Dear All, I am kinda new to Oracle and need to work on a stored proc to update some data. However, I am getting compilation error for the following stored proc and got no idea on how to resolve it. ====================================== CREATE or REPLACE procedure RemoveDupID as begin for ind in (select cor_id, incor_id from duplicateID) loop update account_master set last_edited_by = ind.cor_id where last_edited_by = ind.incor_id;...
2
2401
by: JeffRoughgarden | last post by:
To minimize the very large number of stored procedures typically associated with an application, I have gotten in the habit of combining a select, insert, update, and delete all in one procedure, and passing an argument to indicate which to use. (I use default values for all input params to avoid having to declare them for selects and deletes.) So I'll have just one PersonAdmin proc instead of PersonGet, PersonInsert, PersonUpdate, and...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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,...
0
10360
jinu1996
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...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7646
isladogs
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...
0
6876
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();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.