Update statement in a procedure
update pol_notification a
set obj_id = v_presv_client_id
where a.obj_id=v_client_id and a.obj_type='client' ;
update pol_notification a
set obj_id = v_address_id
where a.obj_id=v_address_id and a.obj_type='address' ;
I am using these two update statements in one procedure but the tables are not being updated.
Any reason for that. Am i using the right statements?
Here is the procedure.....
CREATE OR REPLACE PROCEDURE SP_LOAD_CLIDUPDATA( )
BEGIN
DECLARE v_client_id integer ;
DECLARE v_presv_client_id integer ;
DECLARE v_processed_client_id integer;
DECLARE v_address_id integer;
DECLARE V_NUMBER integer;
DECLARE v_counter integer DEFAULT 0;
DECLARE cur_update CURSOR FOR
SELECT client_id,presv_client_id,nvl(processed_client_id,0),nvl(address_id,0)
FROM cli_dup_data ;
DECLARE cur_num CURSOR FOR
SELECT count(*) FROM cli_dup_data ;
open cur_num;
fetch cur_num into V_NUMBER;
close cur_num;
OPEN cur_update;
loop
IF v_counter = V_NUMBER THEN
end loop;
END IF;
FETCH cur_update INTO v_client_id,v_presv_client_id,v_processed_client_id,v_address_id;
if v_client_id = 0 then
COMMIT; --Commit transactions at batch level only
ELSE
If v_processed_client_id <> v_client_id then -- client_id is already processed
update pol_notification a set obj_id = v_presv_client_id --Update client_id
where a.obj_id=v_client_id and a.obj_type='client';
update pol_notification a set obj_id = v_address_id -- Update address_id
where a.obj_id=v_address_id and a.obj_type='address';
update pol_notify_history b set obj_id=v_presv_client_id,
client_seq_nbr_i = 1
where b.obj_id = v_client_id and b.obj_type='client';
update pol_notify_history b set obj_id = v_address_id
where b.obj_id = v_client_id and b.obj_type = 'address';
update pol_int_name set client_id = v_presv_client_id --Update client_id
where client_id=v_client_id;
update cli_dup_data set processed_client_id=v_client_id --Keep a record of updated client_id in processed_client_id
where client_id=v_client_id;
end if;
END IF;
set v_counter = v_counter+1;
END loop ;
CLOSE cur_update;
Similar Messages
-
How to use Update Statement in ODI Procedure
Hi,
How can I use an update statement inside an ODI procedure.
ThanksHi,
You do not need the BEGIN and END. ODI procedures are free text, so you can simply write your update statement, as you would in toad/sql developer etc etc. Just make sure you set the Technology and the logical schema. It is how ever best practice to also use the API:
<%=odiRef.getSchemaName("YOUR_LOGICAL_SCHEMA_NAME", "D")%>. to prefix tables. This way, you select data from different schema's in the same instance (as long a your user has the correct privs).
Cheers
Bos
Edited by: Bos on Jun 22, 2011 3:09 PM -
Update Statement in ODI Procedure
Hi All,
I want to update a value in a table through ODI procedure
I Created a procedure,added new step,given details like Technology,Context,Schema in Command on target
on the command:
i was trying with:-
update table_name
set column_name1='value1'
where column_name2='value2'
and also i tried with:-
begin
UPDATE Schema_name.Table_name SET column_name1='value1' WHERE column_name2='value2';
end;
in both cases i am unable to update the value in the table
Please suggest me
Thanks in AdvanceHi,
Thanks for the reply
I fixed that problem
It was caused due to Database error
Thanks -
How to add the update statement in this procedure?
I have one table usersubscription (userid,newsletterid,deleted)
I got one string from user e.g. ('1,2,3') and userid = 14
I wrote proceduer that will insert this records in to usersubscription table;
userid newsletterid deleted
14 1 n
14 2 n
14 3 n
default value of deleted column is 'n'.
my procedure is as follows;
CREATE OR REPLACE PROCEDURE usersubscription_procd1 (vuserid in number, vnewsletterid IN VARCHAR2)
AS
I NUMBER;
J NUMBER;
VAL VARCHAR2(100);
BEGIN
I := 1;
J := 1;
WHILE INSTR(vnewsletterid,',',I) != 0 LOOP
VAL := SUBSTR(vnewsletterid,I,INSTR(vnewsletterid,',',I)-J);
I := INSTR(vnewsletterid,',',I)+1;
J := I;
INSERT INTO usersubscription (usersubcriptionid,userid,newsletterid)
VALUES (usersubscription_seq.nextval,vuserid,VAL);
END LOOP;
VAL := SUBSTR(vnewsletterid,I,LENGTH(vnewsletterid));
INSERT INTO usersubscription (usersubcriptionid,userid,newsletterid)
VALUES (usersubscription_seq.nextval,vuserid,VAL);
END;
Now one requirement is that when new string comes for same userid e.g.('1,4,5') userid = 14
then the deleted column for 1 and 2 newsletterid changes to 'y';
please tell me the solution.
Prathamesh.Hi,
Before your loop, you can make something else like :
SQL> select * from test;
USERID NEWSLETTERID D
14 1 n
14 2 n
14 3 n
SQL> update test
2 set deleted = 'y'
3 where instr('1,4,5',newsletterid,1) = 0
4 and userid = 14;
2 ligne(s) mise(s) à jour.
SQL> select * from test;
USERID NEWSLETTERID D
14 1 n
14 2 y
14 3 y
SQL> HTH,
Nicolas. -
About update statement in procedure
I have one table usersubscription (userid,newsletterid,deleted)
I got one string from user e.g. ('1,2,3') and userid = 14
I wrote proceduer that will insert this records in to usersubscription table;
userid newsletterid deleted
14 1 n
14 2 n
14 3 n
default value of deleted column is 'n'.
my procedure is as follows;
CREATE OR REPLACE PROCEDURE usersubscription_procd1 (vuserid in number, vnewsletterid IN VARCHAR2)
AS
I NUMBER;
J NUMBER;
VAL VARCHAR2(100);
BEGIN
I := 1;
J := 1;
WHILE INSTR(vnewsletterid,',',I) != 0 LOOP
VAL := SUBSTR(vnewsletterid,I,INSTR(vnewsletterid,',',I)-J);
I := INSTR(vnewsletterid,',',I)+1;
J := I;
INSERT INTO usersubscription (usersubcriptionid,userid,newsletterid)
VALUES (usersubscription_seq.nextval,vuserid,VAL);
END LOOP;
VAL := SUBSTR(vnewsletterid,I,LENGTH(vnewsletterid));
INSERT INTO usersubscription (usersubcriptionid,userid,newsletterid)
VALUES (usersubscription_seq.nextval,vuserid,VAL);
END;
Now one requirement is that when new string comes for same userid e.g.('1,4,5') userid = 14
then the deleted column for 2 and 3 newsletterid changes to 'y';
please tell me the solution.
Prathamesh.Read my suggestion into your other post : Re: how to add the update statement in this procedure?
And please, for more readable forum, do not post twice the same subject, use reply button (or edit) to discuss.
Nicolas. -
What will happen if i have given an update statement?
hi
If i have given an update statement in a procedure will exceptions work on it and what is the back ground process if I give an update statement?
regds
ChandraHello
If you create a procedure that performs a table update, the update is subject to the same transaction model as it would be if you just executed the sql statement on it's own. Exceptions will be raised in the same way as they would if you executed the statement on it's own. You can however handle the exceptions in whatever way you see fit by using the EXCEPTION keyword in your procedure. As for the background process, it depends what you mean. In your procedure, when the update statement is executed, control will not return to the procedure until the statement has finished, so if the update takes 5 seconds to run, your procedure will be waiting 5 seconds for it complete before it can continue with any other statements.
HTH -
Hi,
I'm having trouble getting my SP to work. I've searched this forum for a similar post, but haven't found it.
Can anyone please let me know what I'm doing wrong here?
Thanks!
CREATE OR REPLACE PROCEDURE updadminproc
(pdate IN CHANGE_CONTROL_ADMIN.CLOSEDATE%TYPE,
pact IN CHANGE_CONTROL_ADMIN.ACTIVE%TYPE,
pstat1 IN CHANGE_CONTROL_ADMIN.STATUS1%TYPE,
pstat2 IN CHANGE_CONTROL_ADMIN.STATUS2%TYPE,
padmcomm IN CHANGE_CONTROL_ADMIN.ADM_NOAPROVE%TYPE)
(cctrlid IN NUMBER)
IS
BEGIN
-- UPDATE STATEMENT
UPDATE CHANGE_CONTROL_ADMIN
SET CLOSEDATE = pdate, ACTIVE = pact, STATUS1 = pstat1, STATUS2 = pstat2, ADM_NOAPROVE = padmcomm
WHERE CHANGE_CTRL_ID = cctrlid;
COMMIT;
END updadminproc;
/Here are the errors I get that it's showing:
LINE/COL ERROR
7/2 PLS-00103: Encountered the symbol "(" when expecting one of the
following:
; is with authid as cluster order using external
deterministic parallel_enable pipelined
8/2 PLS-00103: Encountered the symbol "IS" when expecting one of the
following:
returnMessage was edited by:
user515689when I change it accordingly as to how you suggest, the procedure (in SQL Plus) gets created just fine, but then I get an Oracle error when calling the SP.
PLS-00306: wrong number or types of arguments in call to 'UPDADMINPROC'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)Any ideas? Since it reads wrong no. of arguments?
My Java call statement looks like the following:
CallableStatement cstmt = connection.prepareCall("{call updadminproc (?,?,?,?,?)}");
cstmt.setDate(1,cldt);
cstmt.setInt(2,actboxval);
cstmt.setString(3,status1);
cstmt.setString(4,status2);
cstmt.setString(5,fincomments);
cstmt.executeUpdate();I mean, I'm not trying to update the ID no., just associate the record with the ID number (cctrlid).
Thanks.
Ok, I got it....even though not updating the ID # itself, I had to add it to the cstmt object.
As in ....
cstmt.setString(5,fincomments);
cstmt.setInt(6,ctid2);
cstmt.executeUpdate();
Message was edited by:
user515689 -
Executing a Variable in a Stored Procedure containing an Update Statement
Hi,
I have created a Stored Procedure, it has one input parameter. Inside the Stored Procedure there are 5 other variables are declared, based on the input parameter 4 of these variables are populated.
Fifth variable is a a concatenation of text and some of these variables and creates a dynamic Update Statement. Once it is created I want to execute this variable but it is not executing.
Could someone please help me in knowing how to execute a variable within a stored procedure that contains an update statement.
Thanks for your help.
Thanks
Vineesh
vineesh1701If you have set up the variable so that it contains a valid sql update, it should work. For example, see below, which does do an update
use tempdb
go
Create Table #Test(i int);
Insert #Test(i) Values(1);
go
Create Procedure TestProc As
Begin
Declare @SQL nvarchar(250);
Set @SQL = 'Update #Test Set i = 2';
--Print @SQL;
Exec sp_executesql @SQL;
End
go
Exec TestProc
-- Test Result
Select * From #Test;
go
Drop Procedure TestProc;
go
Drop Table #Test;
One thing I would recommend while testing is that you print out or select the variable that contains the dynamic sql. (Like the above code where I have a print statement. That lets you see exactly what you are executing and if there is any problem
with the update command.
As Naomi said, to get anything more than general help, you will probably have to show us your code and the parameter values you are passing when you execute the stored proc.
Tom -
Dynamic SQL statement in a Procedure
Hi,
is it possible to use a variable in place of a column name in a sql statement inside a procedure. Or to create the whole statement as a sql statement and execute it (preferrably with parameters - rather than concatinating the values).
Thanks for any help or direction
ElliotTurns out you can do the following very nicely (dynamic sql with parameterized values)
Declare
id number(10,0);
sql_stmt varchar2(300);
fieldName varchar2(30);
fieldValue varchar2(100);
id := 30;
fieldName := 'somecolumn';
fieldValue := 'some value';
sql_stmt := 'UPDATE myTable SET ' || fieldName || ' = :1 WHERE id = :2';
EXECUTE IMMEDIATE sql_stmt USING fieldValue, id; -
Where clause in UPDATE statement is ignored
I have the following procedure that updates a field in a table. The only problem is that all rows in the table are updated like the update statement doesn't have a where clause. When I hard code the number (733) in the where clause it works as expected. Even if I don't alias the table name it still updates all rows in the table. Any ideas?
DECLARE
extlinkid CONSTANT NUMBER := 733;
newURL CONSTANT VARCHAR2(250) := 'mailto:[email protected]';
BEGIN
UPDATE SCHEMA.TABLE A
SET A.URL = newURL
WHERE (A.EXTLINKID = extlinkid);
commit;
END;Oracle is resolving your variable extlinkid as the column in the table, so your UPDATE statement is equivalent to:
UPDATE schema.table a
SET a.url = newurl
WHERE (a.extlinkid = a.extlinkid);Which, of course, matches every record in the table. You need to change the name of your variable to something that is not a column name.
TTFN
John -
Problem in Update statement using Execute Immediate
Hi All,
I am facing problem in update statement.
I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
But it is not updating any thing there in the table.
I have created a query like :
update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
Execute immediate update_query using V_Id;
commit;
But it is not updating the table.
I have a question , is execute immediate only does insert and delete?
Thanks
AshokSQL> select * from t;
TID P
101 N
SQL> declare
2 V_Id number := 101;
3 Table_Name varchar2(30) := 'T';
4 update_query varchar2(1000);
5 begin
6 update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
7 Execute immediate update_query using V_Id;
8 commit;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> select * from t;
TID P
101 Y -
JDBC Sender Adapter, Update statement
Hi ALL,
I have a JDBC to proxy scenario. We have stored procedure in the database that executess and sends the data to SAP.
Also the same store procedure updates the field Status_ID to distinguish between read and unread records. Status_ID acts as a Flag.
Now because the Stored procedure itself does what 'Update SQL Statement' in sender JDBC adapter does, what shall I put in 'Update SQL Statement' as it is not needed, but it's a mandatory field??
XIer
Message was edited by:
XIerDo you need that update in the sender jdbc adaptor to do anything....?
Dint think so..
Change your update statement to update Status_ID if its not updated..and if the sql procedure has run already then its not going to be updated ..as it already is.......
Regards
Ravi Raman -
Dynamic UPDATE statement with parameters for column names.
Hello,
On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
On the other hand, in this Re: execute immediate with dynamic column name update and many other
posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
WHERE ST IN
(SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||P_ST||' = CO.ST AND
CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
EXECUTE IMMEDIATE dynSQL ;
Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
The compiling works fine and I use Oracle 11g.
http://psoug.org/definition/EXECUTE_IMMEDIATE.htmOK I extracted from all of your posts so far that I have to use "bind-variables with :"
From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
set serveroutput on format wraped;
DECLARE
dynSQL VARCHAR2(5000);
P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
P_ST VARCHAR2 (100) :='32132';
BEGIN
dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||:P_ST||' = CO.ST AND
CO.'||:P_ENT_E_G_NAME||' > '||:P_ENT_E_G_WE||' AND
CO.'||:P_ENT_B_G_NAME||'
< '||:P_ENT_E_G_WE||')';
--this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
dbms_output.enable;
dbms_output.put(dynSQL);
--EXECUTE IMMEDIATE dynSQL;
END;Problem:I think I figured it out, the dates that I parse into the query need additional ' -
Hi
I have this procedure in may oracle 9.2. but it show me this error message in the forall statement.-
Error: PLS-00382: wrong type in expression.
why ???
==============================0
PROCEDURE pr_com_upd_prim_carg
-- MODIFICATION HISTORY
-- Person Date Comments
-- diazh 22/09/06
v_mon_carg cargas_credito.mon_carg%TYPE;
v_fec_carg cargas_credito.fec_carg%TYPE;
v_num_line tmp_comi_liq.num_line%TYPE;
v_num_cont tmp_comi_liq.num_cont%TYPE;
v_cant_cuotas_perc comi_def_linea.cant_cuotas_perc%TYPE;
v_existe VARCHAR2 (1);
-- Declare program variables as shown above
CURSOR c_recarg
IS
SELECT --dl.num_line, dl.num_cont, dl.cant_cuotas_perc
FROM comi_def_linea dl
WHERE dl.cod_estado = 'APROB' AND dl.cod_clco = 'PREPA' AND dl.fec_prim_carga IS NULL;
type t_recarg is table of comi_def_linea%rowtype index by binary_integer;
v_recarg t_recarg;
BEGIN
p_usuario := p_user;
p_periodo := TO_CHAR (p_fec_ini, 'YYYYMM');
pr_inserta_ctrl (3, 'PR_COM_UPD_PRIM_CARG');
printlg ('PR_COM_UPD_PRIM_CARG... Iniciado ', v_logfile);
printlg ('PR_COM_UPD_PRIM_CARG... Iniciado conteo de registros en cargas_credito ',
v_logfile);
BEGIN
SELECT DISTINCT '1'
INTO v_existe
FROM cargas_credito
WHERE fec_carg > (p_fec_ini - (1 / (3600 * 24))) AND fec_carg < (p_fec_fin + 1);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
printlg ('PR_COM_UPD_PRIM_CARG(1): Error ' || SQLERRM, v_logfile);
END;
printlg ('PR_COM_UPD_PRIM_CARG... Finalizado conteo de registros en cargas_credito ',
v_logfile
OPEN c_recarg;
loop
FETCH c_recarg
bulk collect into v_recarg limit 500;
exit when c_recarg%notfound;
for i in v_recarg.first .. v_recarg.last loop
IF v_recarg(i).cant_cuotas_perc = 0
THEN
pr_retorna_prim_carga (v_recarg(i).num_line, v_recarg(i).num_cont, v_existe/*esta es una variable cualquiera*/, v_recag(i).fec_prim_carga, v_recarg(i).mto_prim_carga);
END IF;
end loop;
forall i in v_recarg.first .. v_recarg.last
update comi_def_linea
SET fec_prim_carga = v_recarg(i),
mto_prim_carga = v_recarg(i)
WHERE num_line = v_recarg(i) AND num_cont = v_recarg(i);
v_recarg.delete;
END LOOP;
CLOSE c_recarg;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
printlg ( 'PR_COM_UPD_PRIM_CARG(3): Error '
|| SQLERRM
|| ' '
|| 'procesando linea '
|| v_num_line
|| '-'
|| v_num_cont,
v_logfile
END; -- PR_COM_UPD_PRIM_CARGThe type is a row type so for update statement you have to refer to column.
v_recar(i).num_cont.
pl/sql table type(i).columname That wouldn't work either (at least in 9iR2):
DECLARE
TYPE emp_type IS TABLE OF emp%ROWTYPE
INDEX BY BINARY_INTEGER;
emp_tab emp_type;
BEGIN
FORALL i IN 1 .. emp_tab.LAST
UPDATE emp
SET sal = emp_tab (i).sal
WHERE empno = emp_tab (i).empno;
END;
Error at line 4
ORA-06550: line 9, column 20:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 9, column 20:
PLS-00382: expression is of wrong type
ORA-06550: line 10, column 22:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 10, column 22:
PLS-00382: expression is of wrong type
ORA-06550: line 9, column 20:
PL/SQL: ORA-22806: not an object or REF
ORA-06550: line 8, column 7:
PL/SQL: SQL StatemenMessage was edited by:
michaels -
i am using 'For Update' statement to lock a record in a table and then updating that table through another update statement, like this in a procedure in my Developer Suite 9i application:-
1)SELECT TOTAL_OUTSTANDING INTO TEMP_OUTSTANDING FROM PPBS_DISTRIBUTOR_MASTER where distributor_id=:rh.distributor_id
FOR UPDATE OF TOTAL_OUTSTANDING NOWAIT;
2)UPDATE PPBS_distributor_master set total_outstanding = total_outstanding - to_number(:RH.instrument_amount)
where distributor_id = :RH.distributor_id;
This update in the 2nd statement is skipping sometimes. I have heard that a post-update trigger fires always even if this statement in the procedure is skipping. Can i put these 2 statements in a block level 'post-update' trigger and be assured that the 'Update' statement will fire always. Please help in solving the doubt as it is urgent.
Regards.Excuse me, to avoid confusion, my previous note should be read as:
I) Put your 1) FOR satatement in block's on-lock trigger;
II) Put your 2) in block's on-update trigger;
Don't put your 1) and 2) in one procedure!
Maybe you are looking for
-
Overhead Percentage is not getting updated in KONX
Hi All, The Overhead percentage which we maintain in KZZ2 is not getting updated in KONX table. Can anybody suggest whether the OH percentage is available in KONX table only or anyother table also? Or Is there any program which needs to be run to upd
-
We are a DVD replicator in San Jose, CA. http://www.newcyberian.com. Lately we receive so many DVD masters from our clients that do not have PCM or AC3 audio stream. They play fine on most DVD players but we know that's a violation of the DVD spec. I
-
My music and tv libraries are gone after downloading version 7.2
Help! My music and tv libraries are not there when I open itunes. My son's library is available on his account on the same computer but mine is not. I'm not sure what to do. HP Windows XP
-
Aperture brush/preview problems?
I've been using Aperture 3.4 for a while with no problems. Today when uploading and editing my latest batch of pictures, I find the thumbnails look a little weird. They have pink lines and static where I used brushes. Originally, it looked like it wa
-
Is there any other options to CHECKSUM?
For a data cleansing process I'm working on, I'm creating a new key, based on a combination of name + address. I wanted to use something in TSQL that will allow me to create an unique key based on an string. What's the most modern solution for the q