Make an update statement from a proc
That is, how is possible to call an update statement from
within a procedure?
I have tried
execute update TT_Livraison set ...
without success.
Any idea?
In a procedure, you just include the SQL statement
CREATE OR REPLACE PROCEDURE foo ...
AS
BEGIN
UPDATE <<some table>>
SET ...
END;Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Similar Messages
-
Generate update statement from select results
I'm trying to generate an update statement based off select statement results. A very basic example,
SELECT ListID FROM DListing WHERE Status = 2
Results return 3 rows.
1234
2345
3456
How can I take those results and turn them into WHERE criteria for UPDATE statement?
Generated UPDATE statement should look like this.
UPDATE DListing SET Status = 1 WHERE ListID IN (1234,2345,3456)
I have started by creating a temp table to hold my SELECT results, but I don't know how to get those results into format for IN condition. Right now I get 3 UPDATE statements with 1 ListID in each IN condition.
CREATE TABLE #TempStatusUpdate(ListID INT)
INSERT INTO #TempStatusUpdate
SELECT ListID FROM DListing WHERE Status = 2
SELECT 'UPDATE DListing SET Status = 1 WHERE ListID IN (' + CONVERT(VARCHAR(30),ListID) + ') AND Status = 2'
DROP TABLE #TempStatusUpdateSo what wrong with
UPDTATE DListing
SET Status = 1
WHERE ListID IN (SELECT ListID FROM #TempStatusUpdate)
Erland Sommarskog, SQL Server MVP, [email protected] -
Delete/update statements insite stored proce
I know this is probably fairly simple for some of you, but I am brand new to Oracle-SQL. In Sybase you can have the following stored procedure and works:
create procedure foo as
begin
create table ...
create index...
delete x
where ....
update x
where ...
end
In oracle everytime I need to execute a DML comand in a stored proc do I have to use execute immediate ('delete x...')?
thanks> the above is not an application code, it is a simple
and dirty maybe way to transfer some data from
microsoft access to oracle. so, i need a quick and
disrty way to transfer this data.
I would have been using a SQL*Plus script myself to do this and not a stored procedure.
> is it there a limit of how many tables i can cerate
inside my stored proc using:
execute immediate('CREATE TABLE xxx AS select * from
yyy.... ?
No. Of course not.
Just keep in mind that each DDL is an implicit commit.
> i have a stored proc that creates couple tables with
the method shown above but the compiler compains for
the second create table zzz as select * from .... any
idea why?
DDL statement and error number are? -
SQL UPDATE statement in MS Excel
Hi All,
I have a request to perform a column update in ap_invoices_all table. There are around 1000 rows to be updated. The input is in the form of MS Excel.
Can somebody suggest how to make an update statement using MS Excel.
My query using excel should look like below:
UPDATE AP_INVOICES_ALL
SET description = '',
last_update_date = ,
last_updated_by =
WHERE org_id =
AND vendor_site_id =
AND invoice_num = ''
Regards,
Radhika.>
Can somebody suggest how to make an update statement using MS Excel.
>
as a way:
-- create heterogeneous service for ms excel
-- create dblink for this service
-- do update like
UPDATE AP_INVOICES_ALL
SET description = (
with t as
select value_for_description,
org_id,
vendor_site_id,
invoice_num
from sheet@dblink_to_excel
select t.value_for_description
from t t
where s.org_id = t.org_id
and s.vendor_site_id = t.vendor_site_id
and s.invoice_num = t.invoice_num
)other way:
-- create heterogeneous service for ms excel
-- create dblink for this service
-- insert for some temporary table
-- do update like above but based on temp table -
Updating data without using update statement
Hi,
A quick question...
Can any table data could be updated without using update statement from backend.
Just wanted to make sure.
Thanks in advance.Hi,
What is your definition of Update?
Since your question is vague and you dont explain what exactly you mean.
here are my thoughts
1) A record can be deleted and isnerted with new values.Where the nes values have only few columns changed from previous ones.
2) I use pl/sql developer.If i need to update i can write select.. for update.Change the values (as in notepad)Commit.
This is infact a update but with nice UI
3) even your application can update data in your tables, if you code it and give correct privileges to the userRegards,
Bhushan -
Help with this update statement..
Hi everyone,
I am trying to update a column in a table .I need to update that column
with a function that takes patient_nbr and type_x column values as a parameter.
That table has almost "300,000" records. It is taking long time to complete
almost 60 min to 90 min.
Is it usual to take that much time to update that many records?
I dont know why it is taking this much time.Please help with this update statement.
select get_partner_id(SUBSTR(patient_nbr,1,9),type_x) partner_id from test_load;
(it is just taking 20 - 30 sec)
I am sure that it is not the problem with my function.
I tried the following update and merge statements .Please correct me if i am wrong
in the syntax and give me some suggestions how can i make the update statement fast.
update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
merge into test_load a
using (select patient_nbr,type_x from test_load) b
on (a.patient_nbr = b.patient_nbr)
when matched
then
update
set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
there is a index on patient_nbr column
and the statistics are gathered on this table.Hi Justin,
As requested here are the explain plans for my update statements.Please correct if i am doing anything wrong.
update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
"PLAN_TABLE_OUTPUT"
"Plan hash value: 3793814442"
"| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |"
"| 0 | UPDATE STATEMENT | | 274K| 4552K| 1488 (1)| 00:00:18 |"
"| 1 | UPDATE | TEST_LOAD | | | | |"
"| 2 | TABLE ACCESS FULL| TEST_LOAD | 274K| 4552K| 1488 (1)| 00:00:18 |"
merge into test_load a
using (select patient_nbr,type_x from test_load) b
on (a.patient_nbr = b.patient_nbr)
when matched
then
update
set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
"PLAN_TABLE_OUTPUT"
"Plan hash value: 1188928691"
"| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |"
"| 0 | MERGE STATEMENT | | 274K| 3213K| | 6660 (1)| 00:01:20 |"
"| 1 | MERGE | TEST_LOAD | | | | | |"
"| 2 | VIEW | | | | | | |"
"|* 3 | HASH JOIN | | 274K| 43M| 7232K| 6660 (1)| 00:01:20 |"
"| 4 | TABLE ACCESS FULL| TEST_LOAD | 274K| 4017K| | 1482 (1)| 00:00:18 |"
"| 5 | TABLE ACCESS FULL| TEST_LOAD | 274K| 40M| | 1496 (2)| 00:00:18 |"
"Predicate Information (identified by operation id):"
" 3 - access("A"."patient_nbr"="patient_nbr")"Please give some suggestions..
what's the best approach for doing the updates for huge tables?
Thanks -
Unable to execute an update statement using CallableStatement
Hi there,
I'm trying to run an update statement from JUnit using java.sql.CallableStatement and oracle.jbo.server.DBTransaction.
String updateSql =
"update footable set barcol=TO_DATE('12-SEP-09','dd-MM-yy') where bazcol = 505";
try {
statement =
applnModule.getDBTransaction().createCallableStatement(updateSql,
2);
int executeUpdate = statement.executeUpdate();
AppsLogger.write(this,
"# records UPDATED ------------------>" + executeUpdate,
AppsLogger.SEVERE);
} catch (SQLException s) {
s.printStackTrace();
Assert.fail("Encountered SQL Exception: " + s);
} finally {
try {
if (statement != null)
statement.close();
} catch (SQLException s) {
}Below is the exception I get when I run the above code. There is no problem with the SQL - it works fine from SQLDeveloper.
java.lang.AssertionError: Encountered SQL Exception: java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
org.junit.Assert.fail(Assert.java:91)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.invokeTestMethod(AtfJUnit4JTestCaseClassRunner.java:362)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.runMethods(AtfJUnit4JTestCaseClassRunner.java:272)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner$1.run(AtfJUnit4JTestCaseClassRunner.java:265)
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.run(AtfJUnit4JTestCaseClassRunner.java:262)Edited by: 911023 on Oct 2, 2012 11:28 AM
Edited by: 911023 on Oct 2, 2012 11:30 AMUsing case statement.
UPDATE gor_gold_post
SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END,
b49n = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END
WHERE tariff_code IN (169, 135, 136);Note: Code not tested. -
Update statement getting ORA-00904 invalid identifier
I am getting this ORA error when I try to conduct an update statement from a column value in one table to a like-named column in another table.
For instance, in my select, shown below, this query runs like a champ, returning all of my records
SELECT
b.ID,
b.ZIP, a.ZIP,
a.NAME,
a.LOCATION
FROM TBL_ARCHIVE a
INNER JOIN TBL_UAT b ON
a.ID = b.ID
WHERE
b.ID > 470000 And b.ID <470100;However, if I try to run an update statement with any of the following, I get this error. It seems so strange to me that I'd get an error using the same columns in the update statement, but would return the desired results effectively from the select statement!
one version of UPDATE
UPDATE TBL_ARCHIVE a
SET a.ZIP = TBL_UAT.ZIP
WHERE TBL_UAT.ID = a.ID;and another
UPDATE TBL_ARCHIVE
SET a.ZIP =
(SELECT b.ZIP
FROM TBL_UAT b
WHERE b.ID <472500 And b.ID >471000)
FROM TBL_ARCHIVE a
WHERE a.ID = b.ID)
WHERE ID IN
(SELECT ID
FROM TBL_UAT b
WHERE b.ID <472500 And b.ID >471000
);^ - this one produces a SQL not properly ended. Error ORA-00933: SQL command not properly ended.
I'm really unsure though, how what I thought was a fairly basic update statement wouldn't work. I'm using Oracle 11g but through either Toad or SQL Plus. I've gotten these same errors in both.
Though MS Access runs slow as snails, I can manage to run the update statement successfully with it, a thousand records or so at a time. Problem is, I've got about 300K records needing updating.
I've looked around for similar problems but haven't found one where someone wasn't either using a reserved word for a column, which I'm not, I don't believe, or a problem that really dealt with this error in the context of an update statement.
But I'd welcome any enlightenment on this.rp0428 wrote:
UPDATE TBL_ARCHIVE a
SET a.ZIP = TBL_UAT.ZIP
WHERE TBL_UAT.ID = a.ID;That isn't a valid query and neither is the other one.
Please post the actual query you are using and the actual complete error message you are getting (everything about the error that is displayed).^^
That is NOT a valid query?
How else would you have an UPDATE statement created to set the value of a column in table A to the value of a (in this case, same named) column in table B?
And keep them in order to update the records appropriately?
I'll append the create statements momentarily.
Thanks!
CREATE TABLE TBL_UAT
( ID NUMBER(6),
ZIP VARCHAR2(10 BYTE) ) and
CREATE TABLE TBL_ARCHIVE
( ID NUMBER(6) NOT NULL, NAME VARCHAR2(50 BYTE),
EMAIL VARCHAR2(50 BYTE),
LOCATION VARCHAR2(50 BYTE),
DEPARTMENT VARCHAR2(50 BYTE),
PRIORITY VARCHAR2(50 BYTE),
APPROVING_MGR_NAME VARCHAR2(50 BYTE),
TYPE1 VARCHAR2(50 BYTE),
TYPE2 VARCHAR2(50 BYTE),
CONTACT_NAME VARCHAR2(50 BYTE),
CONTACT_PHN_NO VARCHAR2(50 BYTE),
LOAN_NUM VARCHAR2(50 BYTE),
REF_ID VARCHAR2(50 BYTE),
BORROWER_NAME VARCHAR2(50 BYTE),
ADDRESS VARCHAR2(50 BYTE),
CITY VARCHAR2(50 BYTE),
ST VARCHAR2(50 BYTE),
ZIP VARCHAR2(10 BYTE),
SALE_DATE DATE,
COMMENTS VARCHAR2(800 BYTE),
TIME_REQ DATE,
ACCTLOC VARCHAR2(50 BYTE),
OTHER_ACCTLOC VARCHAR2(50 BYTE)) Hope this can be of assistance.
Thanks, folks!
Edited by: user515689 on Feb 7, 2012 11:59 AM -
How to call UPDATE statements in the timesten
Hi i want to know how can i call UPDATE statements from the c program
as of now i am using SQLPREPARE and SQLEXECUTE for the same.
but i get the following error.
Is there any special way of calling UPDATE and INSERT routines.
As my select statements are doing fine, but i m getting error with UPDATE and INSERT. I am getting the following error
Can Anyone guide me ?
========================================================
[TimesTen][TimesTen 6.0.4 ODBC Driver][TimesTen]TT5102: Cannot load backend library 'libttorD.a' for Cache Connect. OS error message 'Symbol resolution failed
for /disk3/users/timesten/TimesTen/TT_EUDEV10G/lib/libttorD.a because:
Symbol ora_ldap_unbind (number 224) is not exported from dependent
module /disk1/users/oracle/product/9.2.0/lib/libclntsh.a[shr.o].
Symbol ora_ldap_memfree (number 225) is not exported from dependent
module /disk1/users/oracle/product/9.2.0/lib/libclntsh.a[shr.o].
Symbol
*** ODBC Error/Warning = S1000, Additional Error/Warning = 5102
*** (Note: error message was truncated.
Disconnecting from the data source...
==========================================================Hi,
It looks like you are using either :
1. A READONLY CACHE GROUP with PassThrough > 0.
or
2. An SWT CACHE GROUP
Is that correct? This looks like a mismatch between the TT Oracle library and the version of the Oracle client that you have installed (or maybe a bad setting of LD_LIBRARY_PATH).
What is the exact version of TimesTen you are using (output of ttVersion command)?
What is the exact version of Oracle?
Thanks, Chris -
Update statement problem !!
Hi,
I need some specific features for my school project and BDB is almost providing me with this functionality. In my project, I want to provide the user with the functionality to provide the update statements from the user screen. I want to then take the user input in a java variable for manipulation of the xml data and display the end result. The only option I have for the user is to provide the xquery updates with the following syntax: ( I need this syntax for update statements as I use a parser to convert the user input to involve fuzziness):
"insert nodes <b4>inserted child</b4> after doc('dbxml:/test.dbxml/book)/Bookstore";
Now I am trying to run these with the below Code but I am not actually getting the required output. Can somebody help me to debug or fix this code for my requirement. I use the following xml data :
<Bookstore>
<Book>
<book_ID>1</book_ID>
<title>Harry Potter and the Order of the Phoenix</title>
<subtitle/>
<author>
<author_fname>J.K.</author_fname>
<author_lname>Rowling</author_lname>
</author>
<price>9.99<;;/price>
<year_published>2004</year_published>
<publisher>Scholastic, Inc.</publisher>
<genre>Fiction</genre>
<quantity_in_stock>28997</quantity_in_stock>
<popularity>20564</popularity>
</Book>
</Bookstore>
I have track points in my code to find the mistake and I get the following ouput.
Track 3
Track 3.1
Track 3.2-----
The code I use fails to compile the xquery statement with .prepare API.
import java.io.*;
import com.sleepycat.db.*;
import com.sleepycat.dbxml.*;
public class phone{
public static void main(String[] args)
String document1 = "C:/Documents and Settings/cjmadall/Desktop/BDB/book.xml";
String docName = "book";
XmlManager myManager = null;
XmlContainer myContainer = null;
try {
myManager = new XmlManager();
myContainer = myManager.openContainer("test.dbxml");
String myQuery = "insert nodes <b4>inserted child</b4> after doc('dbxml:/test.dbxml/book)/Bookstore";
// This Works and displays the entire document-> String myQuery = "collection('test.dbxml')";
// This Doesnt Work, ends with the above output -> String myQuery = "insert nodes <newNode>Some new text</newNode> after collection("dbxml:/test.dbxml")/Bookstore";
// collection('test.dbxml')/Bookstore";
System.out.println("Track 3 ");
XmlQueryContext managerContext = myManager.createQueryContext();
System.out.println("Track 3.1 ");
// Get a context for the document queries
// XmlQueryContext documentContext = myManager.createQueryContext();
System.out.println("Track 3.2 ");
// Prepare the XmlManager query
*XmlQueryExpression managerQuery = myManager.prepare(myQuery, managerContext);*
System.out.println("Track 3.3 ");
// Perform the query.
XmlResults results = managerQuery.execute(managerContext, 0);
// Display the result set
System.out.println("Track 3.4 ");
XmlValue value;
while ((value = results.next()) != null){
System.out.println(value.asString());
System.out.println("Track 3.5 ");
results.delete();
managerQuery.delete();
// documentContext.delete();
managerContext.delete();
} catch (XmlException e) {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (myContainer != null) {
myContainer.close();
if (myManager != null) {
myManager.close();
} catch (XmlException ce) {
// Exception handling goes here
}//end finally
Thanks.I was using a old version of BDB and the latest version fixed this issue.
-
Update statement not working inside DBMS_PARALLEL_EXECUTE
CREATE OR REPLACE procedure
proc_table_mask_par2 (p_tblName in varchar2
,p_strmCount in number)
IS
| Name: proc_table_mask
| Version: 1.0
| Function: The procedure generates the block which will mask the table based on inputrs from
MSK_INVENTORY_COLS table
| Modification History:
| Ver: Date: Who: What:
| 1.0 2012-11-26 HB Created
vtbl_Name varchar2(100);
vtbl_Count number(19,0);
vStrm_row_count number(19,0);
vCurs_count number(19,0) := 1;
vsql varchar2(30000);
vsql1 varchar2(30000);
vstragg varchar2(4000);
v_try number;
v_status number;
v_status1 number;
vtaskName varchar2(100) := 'Mask job for '||p_tblName ;
pstartnum number(19,0);
pendnum number(19,0);
v_prim_key varchar2(100);
--retries_in PLS_INTEGER DEFAULT 2;
--l_attempts PLS_INTEGER := 1;
begin
-- Use function Stragg to get the update statement from MSK_INVENTORY_COLS
select stragg(MIC.COLUMN_NAME || ' = ' || MIC.FUNCTION_NAME|| '(' ||MIC.COLUMN_NAME||')') into vstragg from MSK_INVENTORY_COLS mic
WHERE MIC.TABLE_NAME = p_tblName;
EXECUTE IMMEDIATE 'select count(1) from '||p_tblName into vtbl_Count;
--DBMS_OUTPUT.PUT_LINE ( 'vtbl_Count : ' ||vtbl_Count);
vStrm_row_count := round( vtbl_Count/p_strmCount);
dbms_output.put_line(' vStrm_row_count : ' || vStrm_row_count);
-- Update statement
vsql := vsql ||chr(10) || ' UPDATE '|| p_tblName || ' /*+ parallel ( '||p_tblName ||', '||p_strmCount||') */ ' ;
vsql := vsql ||chr(10) || ' SET '|| vstragg;
vsql := vsql ||chr(10) || ' , lock_id = -1 ' ;
vsql := vsql ||chr(10) || 'WHERE ROWID BETWEEN :starting_rowid AND :ending_rowid' ;
vsql := vsql ||chr(10) || ' and lock_id <> -1 ; ' ;
dbms_output.put_line (' vsql : ' || vsql);
DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName);
DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID (task_name => vtaskName
, table_owner => SYS_CONTEXT ('USERENV', 'SESSION_USER') --USER
, table_name => p_tblName
, by_row => TRUE
, chunk_size => vStrm_row_count
DBMS_PARALLEL_EXECUTE.RUN_TASK (task_name => vtaskName
, sql_stmt => vsql
, language_flag => DBMS_SQL.native
, parallel_level => p_strmCount
-- Only resume for the following
-- INVALID_STATE_FOR_REDSUME ORA - 29495
-- Attempts to resume execution, but the task is not in FINISHED_WITH_ERROR or CRASHED state
-- Constant value for CRASHED = 8
-- Constant value for FINISHED_WITH_ERROR = 7
v_try := 0;
v_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
dbms_output.put_line (' v_status : ' || v_status);
dbms_output.put_line (' v_try : ' || v_try);
WHILE(v_try < 2 and v_status != DBMS_PARALLEL_EXECUTE.FINISHED and ((v_status = 7) or( v_status = 8) ))
LOOP
v_try := v_try + 1;
DBMS_OUTPUT.PUT_LINE (' Why am I getting into this loop : ' );
DBMS_PARALLEL_EXECUTE.RESUME_TASK(vtaskName);
v_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
END LOOP;
DBMS_PARALLEL_EXECUTE.DROP_TASK(vtaskName);
exception
when
others then
raise;
dbms_output.put_line(sqlerrm);
end;
Gurus
I am executing the procedure above using the following anonymous block.
DECLARE
P_TBLNAME VARCHAR2(32767);
P_STRMCOUNT NUMBER;
BEGIN
P_TBLNAME := 'EMPLOYEE_DIM';
P_STRMCOUNT := 10;
A516907.PROC_TABLE_MASK_PAR2 ( P_TBLNAME, P_STRMCOUNT );
COMMIT;
END;
I have used dbms_output for getting values for the following variables. When I check the values the update does not seem to be working.
vStrm_row_count : 60143
vsql :
UPDATE EMPLOYEE_DIM /*+ parallel ( EMPLOYEE_DIM, 10) */
SET
BUSINESS_TITLE_NM = FN_TITLE_DRM_ENCRYPTNSUM(BUSINESS_TITLE_NM),COST_CENTER_CD =
FN_COSTCTR_DRM_ENCRYPTNSUM(COST_CENTER_CD),DIRECT_MGR_NM =
FN_DRM_REG_ADDR_TEXT(DIRECT_MGR_NM),FIRST_NM =
FN_FNM_DRM_ENCRYPTNSUM(FIRST_NM),LAST_FIRST_FULL_NM =
FN_DRM_REG_ADDR_TEXT(LAST_FIRST_FULL_NM),LAST_FIRST_MIDDLE_FULL_NM =
FN_DRM_REG_ADDR_TEXT(LAST_FIRST_MIDDLE_FULL_NM),LAST_NM =
FN_LNM_DRM_ENCRYPTNSUM(LAST_NM),PHONE_NO =
FN_PHONE_DRM_ENCRYPTNSUM(PHONE_NO),PRIMARY_EMAIL_ADDRESS_NM =
FN_EMAIL_DRM_ENCRYPTNSUM(PRIMARY_EMAIL_ADDRESS_NM)
, lock_id = -1
WHERE ROWID
BETWEEN :starting_rowid AND :ending_rowid
and lock_id <> -1 ;
v_status : 4
v_try : 0I tried to do the update using chunk sql and ran the procedure again..No updates are made.
CREATE OR REPLACE procedure
proc_table_mask_chunk_sql (p_tblName in varchar2
,p_strmCount in number)
IS
| Name: A516907.proc_table_mask
| Version: 1.0
| Function: The procedure generates the block which will mask the table based on inputrs from
MSK_INVENTORY_COLS table
| Modification History:
| Ver: Date: Who: What:
| 1.0 2012-11-26 HB Created
vtbl_Name varchar2(100);
vtbl_Count number(19,0);
vStrm_row_count number(19,0);
vCurs_count number(19,0) := 1;
vsql varchar2(1000);
vsql_pk varchar2(1000);
vstragg varchar2(4000);
vtaskName varchar2(100) := 'Mask Data in table '||p_tblName ;
pstartnum number(19,0);
pendnum number(19,0);
upd_st number(19,0) := 1;
v_prim_key varchar2(100);
l_try NUMBER;
l_status NUMBER;
begin
DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName);
-- Use function Stragg to get the update statement from MSK_INVENTORY_COLS
select stragg(MIC.COLUMN_NAME || ' = ' || MIC.FUNCTION_NAME|| '(' ||MIC.COLUMN_NAME||')') into vstragg from MSK_INVENTORY_COLS mic
WHERE MIC.TABLE_NAME = p_tblName;
select stragg(UCC.COLUMN_NAME) COLUMN_NAME into v_prim_key
from user_constraints uc , user_cons_Columns ucc
where UC.CONSTRAINT_TYPE = 'P'
and UC.CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
and UCC.TABLE_NAME = p_tblName;
vsql_pk := 'SELECT distinct ' || v_prim_key || ','|| v_prim_key || ' FROM ' || p_tblName;
DBMS_OUTPUT.PUT_LINE ( 'vsql_pk : ' ||vsql_pk);
--EXECUTE IMMEDIATE ' select stragg(COLUMN_NAME ||''=''||FUNCTION_NAME||''(''||COLUMN_NAME||'')'') from MSK_INVENTORY_COLS WHERE TABLE_NAME = ' ||p_tblName INTO vstragg ;
--EXECUTE IMMEDIATE 'select count(1) from vtbl_Name' into vtbl_Count;
EXECUTE IMMEDIATE 'select count(1) from '||p_tblName into vtbl_Count;
--DBMS_OUTPUT.PUT_LINE ( 'vtbl_Count : ' ||vtbl_Count);
vStrm_row_count := round( vtbl_Count/p_strmCount);
DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_SQL(vtaskName, vsql_pk, false);
--DBMS_OUTPUT.PUT_LINE ( 'vStrm_row_count : ' ||vStrm_row_count);
--EXECUTE IMMEDIATE 'SELECT MIN( '||v_prim_key||') from ' ||p_tblName into pstartnum;
----dbms_output.put_line (' pstartnum : ' || pstartnum);
--pendnum := vStrm_row_count;
----dbms_output.put_line (' pendnum : ' || pendnum);
-- Update statement
vsql := vsql ||chr(10) || ' UPDATE '|| p_tblName || ' /*+ parallel ( '||p_tblName ||', '||p_strmCount||') */ ' ;
vsql := vsql ||chr(10) || ' SET '|| vstragg;
vsql := vsql ||chr(10) || ' , lock_id = -1 WHERE ' ;
vsql := vsql ||chr(10) || v_prim_key|| ' BETWEEN :start_id and :end_id ';
vsql := vsql ||chr(10) || ' and lock_id <> -1 ; ' ;
--DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName||'_'||upd_st);
DBMS_PARALLEL_EXECUTE.RUN_TASK ( vtaskName
, vsql
, DBMS_SQL.native
, parallel_level => p_strmCount
L_try := 0;
L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
WHILE(l_try < 2 and L_status != DBMS_PARALLEL_EXECUTE.FINISHED and ((L_status = 7) or( L_status = 8) ))
Loop
L_try := l_try + 1;
DBMS_PARALLEL_EXECUTE.RESUME_TASK(vtaskName);
L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
END LOOP;
end;
Block run :
DECLARE
P_TBLNAME VARCHAR2(32767);
P_STRMCOUNT NUMBER;
BEGIN
P_TBLNAME := 'EMPLOYEE_DIM';
P_STRMCOUNT := 10;
A516907.PROC_TABLE_MASK_CHUNK_SQL ( P_TBLNAME, P_STRMCOUNT );
COMMIT;
END;
/ -
I'm having a problem updating a row on a backend database using a dataset which contains the datacolumns as parameters with a TableMapping object. I'm using this in conjunction with the ODT.net tool.
I've used this technique hundreds of times with a SQL Server backend, with no problems whatsoever. I'm not doing anything different.
Here is the SQL I'm executing:
<code>
PROCEDURE proc_prUpdate
p_CALLID IN CALL.CALLID%TYPE,
p_STARTTIME IN CALL.STARTTIME%TYPE,
p_STANDARD IN CALL.STANDARD%TYPE,
p_DURATION IN CALL.DURATION%TYPE,
p_VOYCALLID IN CALL.VOYCALLID%TYPE,
p_LESID IN CALL.LESID%TYPE,
p_SERVICETYPE IN CALL.SERVICETYPE%TYPE,
p_MESCATEGORY IN CALL.MESCATEGORY%TYPE,
p_MOBILE IN CALL.MOBILE%TYPE,
p_REGIONID IN CALL.REGIONID%TYPE,
p_TXCHANNEL IN CALL.TXCHANNEL%TYPE,
p_RXCHANNEL IN CALL.RXCHANNEL%TYPE,
p_SPOTBEAM IN CALL.SPOTBEAM%TYPE,
p_TERMINALID IN CALL.TERMINALID%TYPE,
p_RETURNID IN CALL.RETURNID%TYPE,
p_TELEPHONENUMBER IN CALL.TELEPHONENUMBER%TYPE,
p_PID IN CALL.PID%TYPE,
p_TIMEDURATION IN CALL.TIMEDURATION%TYPE,
p_LESNAME IN CALL.LESNAME%TYPE,
p_MESNAME IN CALL.MESNAME%TYPE,
p_CITY IN CALL.CITY%TYPE,
p_COUNTRY IN CALL.COUNTRY%TYPE,
p_TARGETID IN CALL.TARGETID%TYPE,
p_MESID IN CALL.MESID%TYPE,
p_DBSERVERID IN CALL.DBSERVERID%TYPE
AS
BEGIN
update CALL set
STARTTIME = p_STARTTIME, STANDARD = p_STANDARD, DURATION = p_DURATION, VOYCALLID = p_VOYCALLID, LESID = p_LESID, SERVICETYPE = p_SERVICETYPE, MESCATEGORY = p_MESCATEGORY, MOBILE = p_MOBILE, REGIONID = p_REGIONID, TXCHANNEL = p_TXCHANNEL, RXCHANNEL = p_RXCHANNEL, SPOTBEAM = p_SPOTBEAM, TERMINALID = p_TERMINALID, RETURNID = p_RETURNID, TELEPHONENUMBER = p_TELEPHONENUMBER, PID = p_PID, TIMEDURATION = p_TIMEDURATION, LESNAME = p_LESNAME, MESNAME = p_MESNAME, CITY = p_CITY, COUNTRY = p_COUNTRY, TARGETID = p_TARGETID, MESID = p_MESID, DBSERVERID = p_DBSERVERID
where CALLID = p_CALLID;
END;
</code>
The following is in the generated code for the DataAdapter. Here are all the parameters for the update command:
<code>
Dim OracleParameter29 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter30 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter31 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter32 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter33 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter34 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter35 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter36 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter37 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter38 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter39 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter40 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter41 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter42 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter43 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter44 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter45 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter46 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter47 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter48 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter49 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter50 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter51 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter52 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter53 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParamete
</code>
The following is the code for the parameter list in the generated code:
<code>
Me.updateOracleCommand1.CommandText = "CALL_PKG.PROC_PRUPDATE"
Me.updateOracleCommand1.CommandType = System.Data.CommandType.StoredProcedure
Me.updateOracleCommand1.Connection = Me.oracleConnection1
OracleParameter29.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter29.ParameterName = "P_CALLID"
OracleParameter29.SourceColumn = "P_CALLID"
OracleParameter30.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Date
OracleParameter30.ParameterName = "P_STARTTIME"
OracleParameter30.SourceColumn = "P_STARTTIME"
OracleParameter31.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter31.ParameterName = "P_STANDARD"
OracleParameter31.SourceColumn = "P_STANDARD"
OracleParameter32.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter32.ParameterName = "P_DURATION"
OracleParameter32.SourceColumn = "P_DURATION"
OracleParameter33.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter33.ParameterName = "P_VOYCALLID"
OracleParameter33.SourceColumn = "P_VOYCALLID"
OracleParameter34.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter34.ParameterName = "P_LESID"
OracleParameter34.SourceColumn = "P_LESID"
OracleParameter35.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter35.ParameterName = "P_SERVICETYPE"
OracleParameter35.SourceColumn = "P_SERVICETYPE"
OracleParameter36.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter36.ParameterName = "P_MESCATEGORY"
OracleParameter36.SourceColumn = "P_MESCATEGORY"
OracleParameter37.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter37.ParameterName = "P_MOBILE"
OracleParameter37.SourceColumn = "P_MOBILE"
OracleParameter38.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter38.ParameterName = "P_REGIONID"
OracleParameter38.SourceColumn = "P_REGIONID"
OracleParameter39.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter39.ParameterName = "P_TXCHANNEL"
OracleParameter39.SourceColumn = "P_TXCHANNEL"
OracleParameter40.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter40.ParameterName = "P_RXCHANNEL"
OracleParameter40.SourceColumn = "P_RXCHANNEL"
OracleParameter41.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter41.ParameterName = "P_SPOTBEAM"
OracleParameter41.SourceColumn = "P_SPOTBEAM"
OracleParameter42.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter42.ParameterName = "P_TERMINALID"
OracleParameter42.SourceColumn = "P_TERMINALID"
OracleParameter43.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter43.ParameterName = "P_RETURNID"
OracleParameter43.SourceColumn = "P_RETURNID"
OracleParameter44.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter44.ParameterName = "P_TELEPHONENUMBER"
OracleParameter44.SourceColumn = "P_TELEPHONENUMBER"
OracleParameter45.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter45.ParameterName = "P_PID"
OracleParameter45.SourceColumn = "P_PID"
OracleParameter46.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter46.ParameterName = "P_TIMEDURATION"
OracleParameter46.SourceColumn = "P_TIMEDURATION"
OracleParameter47.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter47.ParameterName = "P_LESNAME"
OracleParameter47.SourceColumn = "P_LESNAME"
OracleParameter48.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter48.ParameterName = "P_MESNAME"
OracleParameter48.SourceColumn = "P_MESNAME"
OracleParameter49.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter49.ParameterName = "P_CITY"
OracleParameter49.SourceColumn = "P_CITY"
OracleParameter50.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter50.ParameterName = "P_COUNTRY"
OracleParameter50.SourceColumn = "P_COUNTRY"
OracleParameter51.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter51.ParameterName = "P_TARGETID"
OracleParameter51.SourceColumn = "P_TARGETID"
OracleParameter52.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter52.ParameterName = "P_MESID"
OracleParameter52.SourceColumn = "P_MESID"
OracleParameter53.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter53.ParameterName = "P_DBSERVERID"
OracleParameter53.SourceColumn = "P_DBSERVERID"
Me.updateOracleCommand1.Parameters.Add(OracleParameter29)
Me.updateOracleCommand1.Parameters.Add(OracleParameter30)
Me.updateOracleCommand1.Parameters.Add(OracleParameter31)
Me.updateOracleCommand1.Parameters.Add(OracleParameter32)
Me.updateOracleCommand1.Parameters.Add(OracleParameter33)
Me.updateOracleCommand1.Parameters.Add(OracleParameter34)
Me.updateOracleCommand1.Parameters.Add(OracleParameter35)
Me.updateOracleCommand1.Parameters.Add(OracleParameter36)
Me.updateOracleCommand1.Parameters.Add(OracleParameter37)
Me.updateOracleCommand1.Parameters.Add(OracleParameter38)
Me.updateOracleCommand1.Parameters.Add(OracleParameter39)
Me.updateOracleCommand1.Parameters.Add(OracleParameter40)
Me.updateOracleCommand1.Parameters.Add(OracleParameter41)
Me.updateOracleCommand1.Parameters.Add(OracleParameter42)
Me.updateOracleCommand1.Parameters.Add(OracleParameter43)
Me.updateOracleCommand1.Parameters.Add(OracleParameter44)
Me.updateOracleCommand1.Parameters.Add(OracleParameter45)
Me.updateOracleCommand1.Parameters.Add(OracleParameter46)
Me.updateOracleCommand1.Parameters.Add(OracleParameter47)
Me.updateOracleCommand1.Parameters.Add(OracleParameter48)
Me.updateOracleCommand1.Parameters.Add(OracleParameter49)
Me.updateOracleCommand1.Parameters.Add(OracleParameter50)
Me.updateOracleCommand1.Parameters.Add(OracleParameter51)
Me.updateOracleCommand1.Parameters.Add(OracleParameter52)
Me.updateOracleCommand1.Parameters.Add(OracleParameter53)
</code>
Here is the code I'm running to try the update:
<code>
OracleDataAdapter1.TableMappings.Add("Table", "CALL")
OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value = Call11._Call.Item(0).CALLID
OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value = Call11._Call.Item(0).STANDARD
Call11._Call.Item(0).STARTTIME = DataGrid1.Item(0, 1)
Call11._Call.Item(0).STANDARD = DataGrid1.Item(0, 2)
Call11._Call.Item(0).DURATION = DataGrid1.Item(0, 3)
Call11._Call.Item(0).LESID = DataGrid1.Item(0, 4)
Call11._Call.Item(0).SERVICETYPE = DataGrid1.Item(0, 5)
Call11._Call.Item(0).MESCATEGORY = DataGrid1.Item(0, 6)
Call11._Call.Item(0).MOBILE = DataGrid1.Item(0, 7)
Call11._Call.Item(0).REGIONID = DataGrid1.Item(0, 8)
Call11._Call.Item(0).MESID = DataGrid1.Item(0, 22)
Call11._Call.Item(0).CALLID = Convert.ToInt32(TextBox1.Text)
OracleDataAdapter1.Update(Call11)
</code>
I shouldn't need to add the above lines:
<code>
OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value = Call11._Call.Item(0).CALLID
OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value = Call11._Call.Item(0).STANDARD
</code>
, but I added them to show you the value of the parms going in.
When debugging, the following is my output:
?Call11._Call.Item(0).RowState
Modified
?Call11._Call.Rows.Count
1
You can see that the rowstate is set to "Modified" and the rowcount is 1
?OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value
8612967 {Long}
[Long]: 8612967 {Long}
?OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value
"B" {String}
String: "B"
The above, are the values of the first & third parms before the "Update" statement is executed.
?OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value
{System.DBNull}
[System.DBNull]: {System.DBNull}
?OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value
{System.DBNull}
[System.DBNull]: {System.DBNull}
The above are the values of the first & third parms after the "Update" statement is executed.
<code>
OracleDataAdapter1.Update(Call11)
</code>
Notice the values are NULL. why???
Below, is the value of my TableMapping object:
?OracleDataAdapter1.TableMappings.Count
1
?OracleDataAdapter1.TableMappings.Item(0)
{System.Data.Common.DataTableMapping}
ColumnMappings: {System.Data.Common.DataColumnMappingCollection}
DataSetTable: "CALL"
SourceTable: "Table"
The datatable name of the strongly typed dataset I am using is "CALL".
When I change the update statement from:
<code>
OracleDataAdapter1.Update(Call11)
</code>
to
<code>
OracleDataAdapter1.UpdateCommand.ExecuteNonQuery()
</code>
the update works (using the latter), but returns a -1 for the records affected (-1 typically means the command can't decipher the action of the command that just took place).
I might add that I successfully executed a similiar "update" the same way via a dataset prior to what I'm trying to do here.
Why isn't the backend datasource being updated? I do not get any errors during the update statement execpt for the -1 for the records affected?I shortened the package spec to the following:
<code>
PROCEDURE proc_prUpdate
p_CALLID IN CALL.CALLID%TYPE,
p_STANDARD IN CALL.STANDARD%TYPE
</code>
I shortened the package body to the following:
<code>
PROCEDURE proc_prUpdate
p_CALLID IN CALL.CALLID%TYPE,
p_STANDARD IN CALL.STANDARD%TYPE
AS
BEGIN
update CALL set
STANDARD = p_STANDARD
where CALLID = p_CALLID;
END;
</code>
When I execute the update statement from the associated data adapter, it updates the db correctly, but still gives me a -1 for the records affected.
When I execute the exact same sql with the record inside a strongly typed dataset, it doesn't update and I still get the -1 for the records affected.
While debugging, the following output is shown for the parameter list:
?daORA.UpdateCommand.Parameters.Item(0)
{Oracle.DataAccess.Client.OracleParameter}
ArrayBindSize: Nothing
ArrayBindStatus: Nothing
CollectionType: None
DbType: Decimal
Direction: Input
IsNullable: False
Offset: 0
OracleDbType: Decimal
ParameterName: "P_CALLID"
Precision: 0
Scale: 0
Size: 0
SourceColumn: "P_CALLID"
SourceVersion: Original
Status: Success
Value: 8612967 {Long}
?daORA.UpdateCommand.Parameters.Item(1)
{Oracle.DataAccess.Client.OracleParameter}
ArrayBindSize: Nothing
ArrayBindStatus: Nothing
CollectionType: None
DbType: String
Direction: Input
IsNullable: False
Offset: 0
OracleDbType: Varchar2
ParameterName: "P_STANDARD"
Precision: 0
Scale: 0
Size: 0
SourceColumn: "P_STANDARD"
SourceVersion: Current
Status: Success
Value: "c" {String}
?ds.Tables(0).Rows(0).RowState
Modified
Two questions:
Even though it updates successfully in the first iteration, how come I get the -1 for the records affected?
In the second iteration, how come it is not updating the backend datasource and how come I still get the -1 for the records affected? You can see that the rowstate is set to modified.
Is there a problem with the ODP.Net data provider not being able to update a backend datasource with values inside of a datatable during a "da.update" statement?
With MS SQL Server data provider, it updates the data flawlessly when I put the tables inside of a MS SQL Server. -
Update problem from a dataset with ODT.
I'm having a problem updating a row on a backend database using a dataset which contains the datacolumns as parameters with a TableMapping object. I'm using this in conjunction with the ODT.net tool.
I've used this technique hundreds of times with a SQL Server backend, with no problems whatsoever. I'm not doing anything different.
Here is the SQL I'm executing:
<code>
PROCEDURE proc_prUpdate
p_CALLID IN CALL.CALLID%TYPE,
p_STARTTIME IN CALL.STARTTIME%TYPE,
p_STANDARD IN CALL.STANDARD%TYPE,
p_DURATION IN CALL.DURATION%TYPE,
p_VOYCALLID IN CALL.VOYCALLID%TYPE,
p_LESID IN CALL.LESID%TYPE,
p_SERVICETYPE IN CALL.SERVICETYPE%TYPE,
p_MESCATEGORY IN CALL.MESCATEGORY%TYPE,
p_MOBILE IN CALL.MOBILE%TYPE,
p_REGIONID IN CALL.REGIONID%TYPE,
p_TXCHANNEL IN CALL.TXCHANNEL%TYPE,
p_RXCHANNEL IN CALL.RXCHANNEL%TYPE,
p_SPOTBEAM IN CALL.SPOTBEAM%TYPE,
p_TERMINALID IN CALL.TERMINALID%TYPE,
p_RETURNID IN CALL.RETURNID%TYPE,
p_TELEPHONENUMBER IN CALL.TELEPHONENUMBER%TYPE,
p_PID IN CALL.PID%TYPE,
p_TIMEDURATION IN CALL.TIMEDURATION%TYPE,
p_LESNAME IN CALL.LESNAME%TYPE,
p_MESNAME IN CALL.MESNAME%TYPE,
p_CITY IN CALL.CITY%TYPE,
p_COUNTRY IN CALL.COUNTRY%TYPE,
p_TARGETID IN CALL.TARGETID%TYPE,
p_MESID IN CALL.MESID%TYPE,
p_DBSERVERID IN CALL.DBSERVERID%TYPE
AS
BEGIN
update CALL set
STARTTIME = p_STARTTIME, STANDARD = p_STANDARD, DURATION = p_DURATION, VOYCALLID = p_VOYCALLID, LESID = p_LESID, SERVICETYPE = p_SERVICETYPE, MESCATEGORY = p_MESCATEGORY, MOBILE = p_MOBILE, REGIONID = p_REGIONID, TXCHANNEL = p_TXCHANNEL, RXCHANNEL = p_RXCHANNEL, SPOTBEAM = p_SPOTBEAM, TERMINALID = p_TERMINALID, RETURNID = p_RETURNID, TELEPHONENUMBER = p_TELEPHONENUMBER, PID = p_PID, TIMEDURATION = p_TIMEDURATION, LESNAME = p_LESNAME, MESNAME = p_MESNAME, CITY = p_CITY, COUNTRY = p_COUNTRY, TARGETID = p_TARGETID, MESID = p_MESID, DBSERVERID = p_DBSERVERID
where CALLID = p_CALLID;
END;
</code>
The following is in the generated code for the DataAdapter. Here are all the parameters for the update command:
<code>
Dim OracleParameter29 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter30 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter31 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter32 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter33 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter34 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter35 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter36 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter37 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter38 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter39 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter40 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter41 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter42 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter43 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter44 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter45 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter46 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter47 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter48 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter49 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter50 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter51 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter52 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter
Dim OracleParameter53 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParamete
</code>
The following is the code for the parameter list in the generated code:
<code>
Me.updateOracleCommand1.CommandText = "CALL_PKG.PROC_PRUPDATE"
Me.updateOracleCommand1.CommandType = System.Data.CommandType.StoredProcedure
Me.updateOracleCommand1.Connection = Me.oracleConnection1
OracleParameter29.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter29.ParameterName = "P_CALLID"
OracleParameter29.SourceColumn = "P_CALLID"
OracleParameter30.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Date
OracleParameter30.ParameterName = "P_STARTTIME"
OracleParameter30.SourceColumn = "P_STARTTIME"
OracleParameter31.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter31.ParameterName = "P_STANDARD"
OracleParameter31.SourceColumn = "P_STANDARD"
OracleParameter32.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter32.ParameterName = "P_DURATION"
OracleParameter32.SourceColumn = "P_DURATION"
OracleParameter33.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter33.ParameterName = "P_VOYCALLID"
OracleParameter33.SourceColumn = "P_VOYCALLID"
OracleParameter34.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter34.ParameterName = "P_LESID"
OracleParameter34.SourceColumn = "P_LESID"
OracleParameter35.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter35.ParameterName = "P_SERVICETYPE"
OracleParameter35.SourceColumn = "P_SERVICETYPE"
OracleParameter36.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter36.ParameterName = "P_MESCATEGORY"
OracleParameter36.SourceColumn = "P_MESCATEGORY"
OracleParameter37.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter37.ParameterName = "P_MOBILE"
OracleParameter37.SourceColumn = "P_MOBILE"
OracleParameter38.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter38.ParameterName = "P_REGIONID"
OracleParameter38.SourceColumn = "P_REGIONID"
OracleParameter39.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter39.ParameterName = "P_TXCHANNEL"
OracleParameter39.SourceColumn = "P_TXCHANNEL"
OracleParameter40.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter40.ParameterName = "P_RXCHANNEL"
OracleParameter40.SourceColumn = "P_RXCHANNEL"
OracleParameter41.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter41.ParameterName = "P_SPOTBEAM"
OracleParameter41.SourceColumn = "P_SPOTBEAM"
OracleParameter42.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter42.ParameterName = "P_TERMINALID"
OracleParameter42.SourceColumn = "P_TERMINALID"
OracleParameter43.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter43.ParameterName = "P_RETURNID"
OracleParameter43.SourceColumn = "P_RETURNID"
OracleParameter44.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter44.ParameterName = "P_TELEPHONENUMBER"
OracleParameter44.SourceColumn = "P_TELEPHONENUMBER"
OracleParameter45.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter45.ParameterName = "P_PID"
OracleParameter45.SourceColumn = "P_PID"
OracleParameter46.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter46.ParameterName = "P_TIMEDURATION"
OracleParameter46.SourceColumn = "P_TIMEDURATION"
OracleParameter47.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter47.ParameterName = "P_LESNAME"
OracleParameter47.SourceColumn = "P_LESNAME"
OracleParameter48.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter48.ParameterName = "P_MESNAME"
OracleParameter48.SourceColumn = "P_MESNAME"
OracleParameter49.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter49.ParameterName = "P_CITY"
OracleParameter49.SourceColumn = "P_CITY"
OracleParameter50.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2
OracleParameter50.ParameterName = "P_COUNTRY"
OracleParameter50.SourceColumn = "P_COUNTRY"
OracleParameter51.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter51.ParameterName = "P_TARGETID"
OracleParameter51.SourceColumn = "P_TARGETID"
OracleParameter52.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Char
OracleParameter52.ParameterName = "P_MESID"
OracleParameter52.SourceColumn = "P_MESID"
OracleParameter53.OracleDbType = Oracle.DataAccess.Client.OracleDbType.Decimal
OracleParameter53.ParameterName = "P_DBSERVERID"
OracleParameter53.SourceColumn = "P_DBSERVERID"
Me.updateOracleCommand1.Parameters.Add(OracleParameter29)
Me.updateOracleCommand1.Parameters.Add(OracleParameter30)
Me.updateOracleCommand1.Parameters.Add(OracleParameter31)
Me.updateOracleCommand1.Parameters.Add(OracleParameter32)
Me.updateOracleCommand1.Parameters.Add(OracleParameter33)
Me.updateOracleCommand1.Parameters.Add(OracleParameter34)
Me.updateOracleCommand1.Parameters.Add(OracleParameter35)
Me.updateOracleCommand1.Parameters.Add(OracleParameter36)
Me.updateOracleCommand1.Parameters.Add(OracleParameter37)
Me.updateOracleCommand1.Parameters.Add(OracleParameter38)
Me.updateOracleCommand1.Parameters.Add(OracleParameter39)
Me.updateOracleCommand1.Parameters.Add(OracleParameter40)
Me.updateOracleCommand1.Parameters.Add(OracleParameter41)
Me.updateOracleCommand1.Parameters.Add(OracleParameter42)
Me.updateOracleCommand1.Parameters.Add(OracleParameter43)
Me.updateOracleCommand1.Parameters.Add(OracleParameter44)
Me.updateOracleCommand1.Parameters.Add(OracleParameter45)
Me.updateOracleCommand1.Parameters.Add(OracleParameter46)
Me.updateOracleCommand1.Parameters.Add(OracleParameter47)
Me.updateOracleCommand1.Parameters.Add(OracleParameter48)
Me.updateOracleCommand1.Parameters.Add(OracleParameter49)
Me.updateOracleCommand1.Parameters.Add(OracleParameter50)
Me.updateOracleCommand1.Parameters.Add(OracleParameter51)
Me.updateOracleCommand1.Parameters.Add(OracleParameter52)
Me.updateOracleCommand1.Parameters.Add(OracleParameter53)
</code>
Here is the code I'm running to try the update:
<code>
OracleDataAdapter1.TableMappings.Add("Table", "CALL")
OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value = Call11._Call.Item(0).CALLID
OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value = Call11._Call.Item(0).STANDARD
Call11._Call.Item(0).STARTTIME = DataGrid1.Item(0, 1)
Call11._Call.Item(0).STANDARD = DataGrid1.Item(0, 2)
Call11._Call.Item(0).DURATION = DataGrid1.Item(0, 3)
Call11._Call.Item(0).LESID = DataGrid1.Item(0, 4)
Call11._Call.Item(0).SERVICETYPE = DataGrid1.Item(0, 5)
Call11._Call.Item(0).MESCATEGORY = DataGrid1.Item(0, 6)
Call11._Call.Item(0).MOBILE = DataGrid1.Item(0, 7)
Call11._Call.Item(0).REGIONID = DataGrid1.Item(0, 8)
Call11._Call.Item(0).MESID = DataGrid1.Item(0, 22)
Call11._Call.Item(0).CALLID = Convert.ToInt32(TextBox1.Text)
OracleDataAdapter1.Update(Call11)
</code>
I shouldn't need to add the above lines:
<code>
OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value = Call11._Call.Item(0).CALLID
OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value = Call11._Call.Item(0).STANDARD
</code>
, but I added them to show you the value of the parms going in.
When debugging, the following is my output:
?Call11._Call.Item(0).RowState
Modified
?Call11._Call.Rows.Count
1
You can see that the rowstate is set to "Modified" and the rowcount is 1
?OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value
8612967 {Long}
[Long]: 8612967 {Long}
?OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value
"B" {String}
String: "B"
The above, are the values of the first & third parms before the "Update" statement is executed.
?OracleDataAdapter1.UpdateCommand.Parameters.Item(0).Value
{System.DBNull}
[System.DBNull]: {System.DBNull}
?OracleDataAdapter1.UpdateCommand.Parameters.Item(2).Value
{System.DBNull}
[System.DBNull]: {System.DBNull}
The above are the values of the first & third parms after the "Update" statement is executed.
<code>
OracleDataAdapter1.Update(Call11)
</code>
Notice the values are NULL. why???
Below, is the value of my TableMapping object:
?OracleDataAdapter1.TableMappings.Count
1
?OracleDataAdapter1.TableMappings.Item(0)
{System.Data.Common.DataTableMapping}
ColumnMappings: {System.Data.Common.DataColumnMappingCollection}
DataSetTable: "CALL"
SourceTable: "Table"
The datatable name of the strongly typed dataset I am using is "CALL".
When I change the update statement from:
<code>
OracleDataAdapter1.Update(Call11)
</code>
to
<code>
OracleDataAdapter1.UpdateCommand.ExecuteNonQuery()
</code>
the update works (using the latter), but returns a -1 for the records affected (-1 typically means the command can't decipher the action of the command that just took place).
I might add that I successfully executed a similiar "update" the same way via a dataset prior to what I'm trying to do here.
Why isn't the backend datasource being updated? I do not get any errors during the update statement execpt for the -1 for the records affected?I shortened the package spec to the following:
<code>
PROCEDURE proc_prUpdate
p_CALLID IN CALL.CALLID%TYPE,
p_STANDARD IN CALL.STANDARD%TYPE
</code>
I shortened the package body to the following:
<code>
PROCEDURE proc_prUpdate
p_CALLID IN CALL.CALLID%TYPE,
p_STANDARD IN CALL.STANDARD%TYPE
AS
BEGIN
update CALL set
STANDARD = p_STANDARD
where CALLID = p_CALLID;
END;
</code>
When I execute the update statement from the associated data adapter, it updates the db correctly, but still gives me a -1 for the records affected.
When I execute the exact same sql with the record inside a strongly typed dataset, it doesn't update and I still get the -1 for the records affected.
While debugging, the following output is shown for the parameter list:
?daORA.UpdateCommand.Parameters.Item(0)
{Oracle.DataAccess.Client.OracleParameter}
ArrayBindSize: Nothing
ArrayBindStatus: Nothing
CollectionType: None
DbType: Decimal
Direction: Input
IsNullable: False
Offset: 0
OracleDbType: Decimal
ParameterName: "P_CALLID"
Precision: 0
Scale: 0
Size: 0
SourceColumn: "P_CALLID"
SourceVersion: Original
Status: Success
Value: 8612967 {Long}
?daORA.UpdateCommand.Parameters.Item(1)
{Oracle.DataAccess.Client.OracleParameter}
ArrayBindSize: Nothing
ArrayBindStatus: Nothing
CollectionType: None
DbType: String
Direction: Input
IsNullable: False
Offset: 0
OracleDbType: Varchar2
ParameterName: "P_STANDARD"
Precision: 0
Scale: 0
Size: 0
SourceColumn: "P_STANDARD"
SourceVersion: Current
Status: Success
Value: "c" {String}
?ds.Tables(0).Rows(0).RowState
Modified
Two questions:
Even though it updates successfully in the first iteration, how come I get the -1 for the records affected?
In the second iteration, how come it is not updating the backend datasource and how come I still get the -1 for the records affected? You can see that the rowstate is set to modified.
Is there a problem with the ODP.Net data provider not being able to update a backend datasource with values inside of a datatable during a "da.update" statement?
With MS SQL Server data provider, it updates the data flawlessly when I put the tables inside of a MS SQL Server. -
Optimizing an update statement
I have the following update statement that I want to run everyday to perform a logical lock on records that are older than so many days. Here is my query
Update treatment
set locked_flag = 'Y'
where treatment_date <= sysdate -90
and locked_flag = 'N';
There is an index on the treatment_date and locked_flag columns. Using the <= on the date causes this index to not be used. This table has 3+ million records, and I am updating about 1,500 a day. I would really like to prevent this update statement from doing a full table scan.
Thanks.jspinelli wrote:
I have the following update statement that I want to run everyday to perform a logical lock on records that are older than so many days. Here is my query
Update treatment
set locked_flag = 'Y'
where treatment_date <= sysdate -90
and locked_flag = 'N';
If you can't change the code then the advice to create a histogram on column locked_flag and an index on (locked_flag, treatment_date) could be sufficient to solve the problem,
The nicest solution, though is probably to create a function-based index:
create index treatment_fbi on treatment(case locked_flag when 'N' then treatment_date else null end);
execute dbms_stats.gather_table_stats({table_owner},'treatment',method_opt=>'for all hidden columns size 1')Then change the code to
Update treatment set
locked_flag = 'Y'
where case locked_flag when 'N' then treatment_date else null end <= sysdate - 90If I've got my case statements right, this gives you an index which is as small as it can be (it will hold the treatment_date for just those rows where locked_flag = 'N') and will allow the optimizer to see that you want to update a very small fraction of the data.
The only trouble will be if the rows to be updated are very widely scattered through the table - in which case the optimizer might think that even this optimal index isn't worth using.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
"For every expert there is an equal and opposite expert"
Arthur C. Clarke -
Update databse from internal table statement not using index
Hi Guys,
We are updating a databse table from a file. The file has a couple of fields which have data different from what the database has (non-primary fields :). We upload the file data into an internal table and then update the database table from internal table. At a time, internal table is supposed to have 10,000 records. I did SQL trace and found that the update statement is not making use of the databse index.
Should not the update statement here be using the table index (for primary key)?
Regards,
Munish... as often there are recommendations in this forum which makes me wonder, how people overestimate their knowledge!!!
Updates and Deletes do of course use indexes, as can be seen in the SQL Trace (use explain).
Inserts don't use indexes, because in many databases inserts are just done somewhere, But also with the INSERT, the primary key is the constraint for the uniqueness condition, duplicate keys are not allowed.
Coming to the original question, what is you actually coding for the update?
What is the table, which fields are in the internal table and what are the indexes?
Siegfried
Maybe you are looking for
-
How can I save pages as a document with the new Mavericks version of pages?
Is there any way to save a pages document as a Microsoft document? Additionally, is there any way to save a numbers document as an Excel document? Since I have downloaded the new Mavericks software with the new Pages, Numbers, and Keynote, I can't s
-
Registering 9i database with oid of 10gAS(10.1.2.0.2)
Hi all, I want to register 9i database(9.2.0.8) with oid of 10gAS(10.1.2.0.2) which is on another server. can anyone please provide me detail steps or the document id number in metalink. Thanks
-
Get old Aperture library into iPhoto without need to upgrade Aperture first?
I've my photo libraries in an old Aperture format. I didn't upgrade to Aperture 3, because I didn't get a new Mac until recently. Now with Yosemite my old Aperture app can't be installed anymore (neither old iPhoto). So I've not an old Aperture libra
-
How to get a server chain certificate
Hi all, I'm installing SSL on Bea Logic server 6.0, but i dont know how to get a server chain certificate. Does any body know how to get this certificate? Also, I read in the e-docs site that we can use utility der2pem and vice versa to convert betwe
-
Changing the EJB connection not under OC4J
Dear all, I am facing a problem that after I deploy an ejb from Jdev and using teh connection from the Jdev. It is working fine, however I found that the EJB is totally depends on the connection which I have setup from Jdev but not from the OC4J conn