Deadlock with "update... where ... in (select..."
Oracle 8.1.6
My procedure make this statement :
INSERT INTO TTO( USERID,ID,ID2,ID3 ) SELECT 3,2,1,0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM TTO WHERE ID = 0 AND USERID = 3)
When this procedure is executed with MS-Excel (Get external Data) with 2 users in same time -> Deadlock.
Why ??????
1)Session A locks row 101
2)Session B locks row 102
3)Session B requests a lock on row 101 and waits for session A to commit
5)Session A requests a lock on row 102 and waits for session B to commit
6)Oracle detects a deadlock, rolls back the statement on which it detected the deadlock, and reports an error.
I don't exactly see how you get a deadlock in the SQL you posted, but perhaps MS-Excel's "Get external Data" is doing something more behind the scenes.
Similar Messages
-
Insert Row is visible in other VO with excluded where-clause
Hi,
i found something that makes me a little bit confusing about ADF BC...
TestCase:
Env:
JDev 10.1.2
HR Schema / Table "regions"
All Objects created ´by ADF BC Wizards
- ViewObject A and ViewObject B based on Entity "Regions"
- ViewObject A with WHERE-CLAUSE region_id=10 at DesignTime
- ViewObject B with NO WHERE-CLAUSE (select * from regions)
JUnitTest:
public void testInsertRow()
ViewObject viewA = fixture1.getApplicationModule().findViewObject("RegionsAView");
ViewObject viewB = fixture1.getApplicationModule().findViewObject("RegionsBView");
System.out.println("ViewA:"+viewA.getRowCount()); //-->0
assertTrue("Must 0 ! region_id = 10",viewA.getRowCount() == 0);
Row row = viewB.createRow();
row.setAttribute("RegionId",new Number(99));
row.setAttribute("RegionName","NRW");
viewB.insertRow(row);
System.out.println("ViewB:"+viewB.getRowCount()); // -> 5
System.out.println("ViewA:"+viewA.getRowCount()); // -> 1
//this assert failt !
assertTrue("Must 0 ! where clause is region_id = 10 and insert region_id was 99 ",viewA.getRowCount() == 0);
Is this a bug or feature ? Can anybody explain that behavior ? thx :)
uliSee this article on my blog for an explanation and a code sample for how to gain more fine-grained control over this View Link Consistency feature...
http://radio.weblogs.com/0118231/2004/02/27.html#a242 -
Update table based on a select with a where clause
I am trying to update a table only for records where i have a status of changed.
Using the following code the update changes all the records putting in blank data if it is outwith the where clause.
ideas?
-- Update changed records
UPDATE IP_SURVEY_ACTIVITY_REG_NO old
SET (
old.SLPN,
old.SURVEY_DATE,
old.SEQUENTIAL_REF_NUMBER,
old.TOTAL_NUM_OF_SAMPLES,
old.TOTAL_NUM_OF_ASSOC_SAMPLES,
old.AIR_TESTS,
old.REMARKS,
old.SURVEY_DETAILS,
old.FURTHER_SURVEY_DETAILS,
old.GENERAL_COMMENTS) =
(SELECT
new.SLPN,
new.SURVEY_DATE,
new.SEQUENTIAL_REF_NUMBER,
new.TOTAL_NUM_OF_SAMPLES,
new.TOTAL_NUM_OF_ASSOC_SAMPLES,
new.AIR_TESTS,
new.REMARKS,
new.SURVEY_DETAILS,
new.FURTHER_SURVEY_DETAILS,
new.GENERAL_COMMENTS
FROM IP_SURVEY_ACTIVITY_REG_NO_INT new
WHERE new.load_id = v_load_id
AND new.status = 'CHANGED'
AND new.sarn = old.sarn);
cheers bjornThe EXISTS claue just needs to be added to your original query as a predicate on the ip_survey_activity_reg_no table. somethign like:
UPDATE ip_survey_activity_reg_no old
SET (old.slpn, old.survey_date, old.sequential_ref_number,
old.total_num_of_samples, old.total_num_of_assoc_samples,
old.air_tests, old.remarks, old.survey_details,
old.further_survey_details, old.general_comments) =
(SELECT new.slpn, new.survey_date,
new.sequential_ref_number,
new.total_num_of_samples,
new.total_num_of_assoc_samples, new.air_tests,
new.remarks, new.survey_details,
new.further_survey_details,new.general_comments
FROM ip_survey_activity_reg_no_int new
WHERE new.load_id = v_load_id and
new.status = 'CHANGED' and
new.sarn = old.sarn)
WHERE EXISTS (SELECT 1 FROM ip_survey_activity_reg_no_int new
WHERE new.load_id = v_load_id and
new.status = 'CHANGED' and
new.sarn = old.sarn)An updateable join view is similar, except you just join the two tables. Assuming that sarn is the primary key of ip_survey_activity_reg_no_int, or is at least declared as unique in that table, then the update of the join would look something like:
UPDATE (SELECT old.slpn oslpn, old.survey_date osurvey_date,
old.sequential_ref_number osequential_ref_number,
old.total_num_of_samples ototal_num_of_samples,
old.total_num_of_assoc_samples ototal_num_of_assoc_samples,
old.air_tests oair_tests, old.remarks oremarks,
old.survey_details osurvey_details,
old.further_survey_details ofurther_survey_details,
old.general_comments ogeneral_comments,
new.slpn nslpn, new.survey_date nsurvey_date,
new.sequential_ref_number nsequential_ref_number,
new.total_num_of_samples ntotal_num_of_samples,
new.total_num_of_assoc_samples ntotal_num_of_assoc_samples,
new.air_tests nair_tests, new.remarks nremarks,
new.survey_details nsurvey_details,
new.further_survey_details nfurther_survey_details,
new.general_comments ngeneral_comments
FROM ip_survey_activity_reg_no old, ip_survey_activity_reg_no_int new
WHERE new.sarn = old.sarn and
new.status = 'CHANGED' and
new.load_id = v_load_id)
SET oslpn = nslpn,
osurvey_date = nsurvey_date,
osequential_ref_number = nsequential_ref_number,
ototal_num_of_samples = ntotal_num_of_samples,
ototal_num_of_assoc_samples = ntotal_num_of_assoc_samples,
oair_tests = nair_tests,
oremarks = nremarks,
osurvey_details = nsurvey_details,
ofurther_survey_details = nfurther_survey_details,
ogeneral_comments = ngeneral_commentsHTH
John
Message was edited by:
John Spencer
Honest, Eric wasn't there when I posted :-) -
Deadlock when updating different rows on a single table with one clustered index
Deadlock when updating different rows on a single table with one clustered index. Can anyone explain why?
<event name="xml_deadlock_report" package="sqlserver" timestamp="2014-07-30T06:12:17.839Z">
<data name="xml_report">
<value>
<deadlock>
<victim-list>
<victimProcess id="process1209f498" />
</victim-list>
<process-list>
<process id="process1209f498" taskpriority="0" logused="1260" waitresource="KEY: 8:72057654588604416 (8ceb12026762)" waittime="1396" ownerId="1145783115" transactionname="implicit_transaction"
lasttranstarted="2014-07-30T02:12:16.430" XDES="0x3a2daa538" lockMode="X" schedulerid="46" kpid="7868" status="suspended" spid="262" sbid="0" ecid="0" priority="0"
trancount="2" lastbatchstarted="2014-07-30T02:12:16.440" lastbatchcompleted="2014-07-30T02:12:16.437" lastattention="1900-01-01T00:00:00.437" clientapp="Internet Information Services" hostname="CHTWEB-CH2-11P"
hostpid="12776" loginname="chatuser" isolationlevel="read uncommitted (1)" xactid="1145783115" currentdb="8" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<inputbuf>
UPDATE analyst_monitor SET cam_status = N'4', cam_event_data = N'sales1', cam_event_time = current_timestamp , cam_modified_time = current_timestamp , cam_room = '' WHERE cam_analyst_name=N'ABCD' AND cam_window= 2 </inputbuf>
</process>
<process id="process9cba188" taskpriority="0" logused="2084" waitresource="KEY: 8:72057654588604416 (2280b457674a)" waittime="1397" ownerId="1145783104" transactionname="implicit_transaction"
lasttranstarted="2014-07-30T02:12:16.427" XDES="0x909616d28" lockMode="X" schedulerid="23" kpid="8704" status="suspended" spid="155" sbid="0" ecid="0" priority="0"
trancount="2" lastbatchstarted="2014-07-30T02:12:16.440" lastbatchcompleted="2014-07-30T02:12:16.437" lastattention="1900-01-01T00:00:00.437" clientapp="Internet Information Services" hostname="CHTWEB-CH2-11P"
hostpid="12776" loginname="chatuser" isolationlevel="read uncommitted (1)" xactid="1145783104" currentdb="8" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<inputbuf>
UPDATE analyst_monitor SET cam_status = N'4', cam_event_data = N'sales2', cam_event_time = current_timestamp , cam_modified_time = current_timestamp , cam_room = '' WHERE cam_analyst_name=N'12345' AND cam_window= 1 </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="72057654588604416" dbid="8" objectname="CHAT.dbo.analyst_monitor" indexname="IX_Clust_scam_an_name_window" id="lock4befe1100" mode="X" associatedObjectId="72057654588604416">
<owner-list>
<owner id="process9cba188" mode="X" />
</owner-list>
<waiter-list>
<waiter id="process1209f498" mode="X" requestType="wait" />
</waiter-list>
</keylock>
<keylock hobtid="72057654588604416" dbid="8" objectname="CHAT.dbo.analyst_monitor" indexname="IX_Clust_scam_an_name_window" id="lock18ee1ab00" mode="X" associatedObjectId="72057654588604416">
<owner-list>
<owner id="process1209f498" mode="X" />
</owner-list>
<waiter-list>
<waiter id="process9cba188" mode="X" requestType="wait" />
</waiter-list>
</keylock>
</resource-list>
</deadlock>
</value>
</data>
</event>To be honest, I don't think the transaction is necessary, but the developers put it there anyway. The select statement will put the result cam_status
into a variable, and then depends on its value, it will decide whether to execute the second update statement or not. I still can't upload the screen-shot, because it says it needs to verify my account at first. No clue at all. But it is very simple, just
like:
Clustered Index Update
[analyst_monitor].[IX_Clust_scam_an_name_window]
cost: 100%
By the way, for some reason, I can't find the object based on the associatedObjectId listed in the XML
<keylock hobtid="72057654588604416" dbid="8" objectname="CHAT.dbo.analyst_monitor"
indexname="IX_Clust_scam_an_name_window" id="lock4befe1100" mode="X" associatedObjectId="72057654588604416">
For example:
SELECT * FROM sys.partition WHERE hobt_id = 72057654588604416
This return nothing. Not sure why. -
Use of Select stmts with Update stmts
Hi,
I want to execute the following update stmt...
UPDATE Test1_tab a
SET a.invpln_seq_no = (SELECT b.seq_no
FROM Test2_tab b
WHERE b.contract_id = a.contract_id
AND b.date_from = a.period_from_date)
WHERE a.invpln_seq_no != (SELECT b.seq_no
FROM Test2_tab b
WHERE b.contract_id = a.contract_id
AND b.date_from = a.period_from_date)
Here the problem is I have used 'SELECT b.seq_no FROM Test2_tab b WHERE b.contract_id = a.contract_id AND b.date_from = a.period_from_date' twice, one in the SET clause and the other one in WHERE clause...But it is the same SELECT stmt...So this same Select stmt runs twice when I run the whole update stmt I guess. Is there a way to do the above update, where it runs the SELECT stmt only once...
Any input is highly appreciated...
Thanks And Best Regards,
/Dinesh...Then you can use Merge statement instead.
try this
merge into test1_tab t1
using
(SELECT a.rowid,b.seq_no SEQ_DEST
FROM test1_tab a,test2_tab b
WHERE b.contract_id = a.contract_id
AND b.date_from = a.period_from_date
AND a.invpln_seq_no != b.seq_no) t2
ON (t1.rowid=t2.rowid)
WHEN MATCHED THEN
UPDATE SET t1.invpln_seq_no=t2.seq_destor if you are sure that sno is a unique key with out any duplicates and if you are going to perform one time manual update then you can use an undocumented hint /*+ bypass_ujvc */ to do this.
*DO NOT include this code if you are about to add it in a production procedure or a function
UPDATE /*+ bypass_ujvc */ (SELECT a.invpln_seq_no SEQ_SRC,b.seq_no SEQ_DEST FROM test1_tab a,test2_tab b
WHERE b.contract_id = a.contract_id
AND b.date_from = a.period_from_date
AND a.invpln_seq_no != b.seq_no)
SET SEQ_SRC = SEQ_DESTRegards,
Prazy -
Held back by the partion selection when installing Windows 8.1 with Update
Hello, all,
I just bought a brand new model MBP and also downloaded the newest Windows 8.1 Update which was released yesterday.
Everything goes well until I enter the screen where to select the partition to install Windows.
-- If booted from EFI (the default reboot after bootcamp job), the screen shows "Can't use the current partition, because system volume has not reahced the available requirements." (may not be the exact words as I used a language other than English)
I see the EFI parition is marked System Volume and the Bootcamp partion is makred Main Parition. Is this the cause of the issue? But how can I change the Bootcamp partition to a System Parition?
and If booted from the USB disk created by bootcamp, the error would be "Windows can't be installed to this disk because the disk is in GPT partition format."
I've tried a few times and had no luck. Does anyone know what was going on? Or anyone also has this issue? Thanks a lot for any help!Welcome to Apple Support Communities
Have you partitioned the drive with Boot Camp Assistant? If not, start up in OS X, open Boot Camp Assistant and create a partition for Windows (the process is automatic). Then, Boot Camp will set your Mac to start up from the USB drive automatically, so you will only have to follow these steps > http://manuals.info.apple.com/MANUALS/1000/MA1636/en_US/boot_camp_install-setup_ 10.8.pdf -
Deadlocks with simple UPDATE statement
I have in a C# program a dictionary and in SQL Server a stored procedure with a simple UPDATE statement. I process the dictionary in parallel. For each entry in my dictionary I call this stored procedure and I am getting deadlocks.
This is the UPDATE statement:
ALTER PROCEDURE [dbo].[UpdateImages]
@ICRTCode nvarchar(max),
@ICRTImage nvarchar(max)
AS
BEGIN
UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE() WHERE IDICRT = @ICRTCode
END
Can someone give me a hint as to why this would cause deadlocks? There are no other processes writing to this table. This is a table in a staging database.http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx
Try change the statement a little bit
UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE()
FROM
Images
WITH (TABLOCK) WHERE IDICRT = @ICRTCode
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help with this, please.
jpg does not support Layers.
Just to make sure, what exactly do you mean by "stacking photos" and what do you want to achieve thereby? -
TDE Issue with UPDATE/SELECT statement
We just implemented TDE on a table and now our import script is getting errors. The import script has not changed and has been running fine for over a year. The script failed right after applying TDE on the table.
Oracle 10g Release 2 on Solaris.
Here are the encrypted colums:
COLUMN_NAME ENCRYPTION_ALG SALT
PERSON_ID AES 192 bits key NO
PERSON_KEY AES 192 bits key NO
USERNAME AES 192 bits key NO
FIRST_NAME AES 192 bits key NO
MIDDLE_NAME AES 192 bits key NO
LAST_NAME AES 192 bits key NO
NICKNAME AES 192 bits key NO
EMAIL_ADDRESS AES 192 bits key NO
AKO_EMAIL AES 192 bits key NO
CREATION_DATE AES 192 bits key NO
Here is the UPDATE/SELECT statement that is failing:
UPDATE cslmo_framework.users a
SET ( person_id
, username
, first_name
, middle_name
, last_name
, suffix
, user_status_seq
= (
SELECT person_id
, username
, first_name
, middle_name
, last_name
, suffix
, user_status_seq
FROM cslmo.vw_import_employee i
WHERE i.person_key = a.person_key
WHERE EXISTS
SELECT 1
FROM cslmo.vw_import_employee i
WHERE i.person_key = a.person_key
AND ( NVL(a.person_id,0) <> NVL(i.person_id,0)
OR NVL(a.username,' ') <> NVL(i.username,' ')
OR NVL(a.first_name,' ') <> NVL(i.first_name,' ')
OR NVL(a.middle_name,' ') <> NVL(i.middle_name,' ')
OR NVL(a.last_name,' ') <> NVL(i.last_name,' ')
OR NVL(a.suffix,' ') <> NVL(i.suffix,' ')
OR NVL(a.user_status_seq,99) <> NVL(i.user_status_seq,99)
cslmo@awpswebj-dev> exec cslmo.pkg_acpers_import.p_users
Error importing USERS table.START p_users UPDATE
Error Message: ORA-01483: invalid length for DATE or NUMBER bind variableI rewrote the procedure using BULK COLLECT and a FORALL statement and that seems to work fine. Here is the new code:
declare
bulk_errors EXCEPTION ;
PRAGMA EXCEPTION_INIT(bulk_errors,-24381) ;
l_idx NUMBER ;
l_err_msg VARCHAR2(2000) ;
l_err_code NUMBER ;
l_update NUMBER := 0 ;
l_count NUMBER := 0 ;
TYPE person_key_tt
IS
TABLE OF cslmo_framework.users.person_key%TYPE
INDEX BY BINARY_INTEGER ;
arr_person_key person_key_tt ;
TYPE person_id_tt
IS
TABLE OF cslmo_framework.users.person_id%TYPE
INDEX BY BINARY_INTEGER ;
arr_person_id person_id_tt ;
TYPE username_tt
IS
TABLE OF cslmo_framework.users.username%TYPE
INDEX BY BINARY_INTEGER ;
arr_username username_tt ;
TYPE first_name_tt
IS
TABLE OF cslmo_framework.users.first_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_first_name first_name_tt ;
TYPE middle_name_tt
IS
TABLE OF cslmo_framework.users.middle_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_middle_name middle_name_tt ;
TYPE last_name_tt
IS
TABLE OF cslmo_framework.users.last_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_last_name last_name_tt ;
TYPE suffix_tt
IS
TABLE OF cslmo_framework.users.suffix%TYPE
INDEX BY BINARY_INTEGER ;
arr_suffix suffix_tt ;
TYPE user_status_seq_tt
IS
TABLE OF cslmo_framework.users.user_status_seq%TYPE
INDEX BY BINARY_INTEGER ;
arr_user_status_seq user_status_seq_tt ;
CURSOR users_upd IS
SELECT i.person_key
,i.person_id
,i.username
,i.first_name
,i.middle_name
,i.last_name
,i.suffix
,i.user_status_seq
FROM cslmo.vw_import_employee i ,
cslmo_framework.users u
WHERE i.person_key = u.person_key ;
begin
OPEN users_upd ;
LOOP
FETCH users_upd
BULK
COLLECT
INTO arr_person_key
, arr_person_id
, arr_username
, arr_first_name
, arr_middle_name
, arr_last_name
, arr_suffix
, arr_user_status_seq
LIMIT 100 ;
FORALL idx IN 1 .. arr_person_key.COUNT
SAVE EXCEPTIONS
UPDATE cslmo_framework.users u
SET
person_id = arr_person_id(idx)
, username = arr_username(idx)
, first_name = arr_first_name(idx)
, middle_name = arr_middle_name(idx)
, last_name = arr_last_name(idx)
, suffix = arr_suffix(idx)
, user_status_seq = arr_user_status_seq(idx)
WHERE u.person_key = arr_person_key(idx)
AND
( NVL(u.person_id,0) != NVL(arr_person_id(idx),0)
OR
NVL(u.username,' ') != NVL(arr_username(idx),' ')
OR
NVL(u.first_name,' ') != NVL(arr_first_name(idx),' ')
OR
NVL(u.middle_name, ' ') != NVL(arr_middle_name(idx), ' ')
OR
NVL(u.last_name,' ') != NVL(arr_last_name(idx),' ')
OR
NVL(u.suffix,' ') != NVL(arr_suffix(idx),' ')
OR
NVL(u.user_status_seq,99) != NVL(arr_user_status_seq(idx),99)
l_count := arr_person_key.COUNT ;
l_update := l_update + l_count ;
EXIT WHEN users_upd%NOTFOUND ;
END LOOP ;
CLOSE users_upd ;
COMMIT ;
dbms_output.put_line('updated records: ' || l_update);
EXCEPTION
WHEN bulk_errors THEN
FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
l_err_code := sql%BULK_EXCEPTIONS(i).error_code ;
l_err_msg := sqlerrm(-l_err_code) ;
l_idx := sql%BULK_EXCEPTIONS(i).error_index;
dbms_output.put_line('error code: ' || l_err_code);
dbms_output.put_line('error msg: ' || l_err_msg);
dbms_output.put_line('at index: ' || l_idx);
END LOOP ;
ROLLBACK;
RAISE;
end ;
cslmo@awpswebj-dev> @cslmo_users_update
updated records: 1274There are about 20 or so other procedure in the import script. I don't want to rewrite them.
Does anyone know why the UPDATE/SELECT is failing? I checked Metalink and could not find anything about this problem.This is now an Oracle bug, #9182070 on Metalink.
TDE (transparent data encryption) does not work when an update/select statement references a remote database. -
Dynamic select query with dynamic where condition
Hi all,
I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
Please advice, if there is any other way to achieve this requirement.
Thanks,
Sanket Sethi
Code***************
PARAMETERS: p_tabnam TYPE tabname,
p_selfl1 TYPE edpline,
p_value TYPE edpline,
p_where1 TYPE edpline .
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
l_wa_name TYPE string,
ls_where TYPE edpline,
l_having TYPE string,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
* <ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
*CREATE DATA dref TYPE HANDLE struct_type.
*ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields
APPEND p_selfl1 TO lt_sel_list.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
** Creation of the "where" clause
*CONCATENATE p_selfl1 '= '' p_value ''.'
* INTO ls_where
* SEPARATED BY space.
*APPEND ls_where TO lt_where.
* Creation of the "where" clause
APPEND p_where1 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
* WHERE (lt_where).Hi Sanket,
The above given logic of mine works for you, put the code in the If condition and try-
just like below:
IF NOT P_EBELN IS INITIAL.
lt_where = '& = ''&'' '.
REPLACE '&' WITH p_ebeln INTO lt_where.
REPLACE '&' WITH field_value INTO lt_where.
SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
FROM (p_tabnam)
WHERE (lt_where).
ENDIF.
thanks\
Mahesh -
Select three tables data with Same where condition
Hi i want sum data in three tables with same where condition. how can i do this code very simple.
SELECT SUM(SIGNA) FROM dbo.tblPLAG
WHERE VERSION='ACTUAL' AND STATS='ST_Z010'
AND FACILITY='FA_2003'
AND TD IN ( SELECT TIMEID FROM Time WHERE ID BETWEEN
@YEAR+'.'+(SELECT RIGHT ('000'+ CAST (@PERIOD-6 AS varchar), 3))
AND
@YEAR +'.'+(SELECT RIGHT ('000'+ CAST (@PERIOD AS varchar), 3)))
Try following
SELECT SUM(t1.SIGNA) + sum(t2.SIGNA) + sum(t3.SIGNA) and you query, it will add the SUMs of each table.. hopefully it will work -
With update of iOS 8 lost pictures and numbers...where did they go?
With update of iOS 8 lost pictures and numbers...where did they go?
If the pictures are still on your phone, they may be in a different location as the camera roll and photo stream albums were removed in iOS 8. This explains the new photos locations: Get help finding your Photos in iOS 8.
Don't know about your numbers. If you mean your contacts, if they were syncing with iCloud check iCloud.com to see if they are sill there. -
With clause in a stored procedure with update
create table TEMP_STAGE as
(select '111111' student_id, 'N' TMP_TEST FROM DUAL
UNION
select '111111' student_id, 'N' TMP_TEST FROM DUAL
UNION
select '222222' student_id, 'N' TMP_TEST FROM DUAL
CREATE OR REPLACE PROCEDURE TEMP_SEC_TEST
AS
BEGIN
UPDATE TEMP_STAGE S
SET S.TMP_TEST = 'Y'
WHERE STUDENT_ID IN
WITH MARK AS
SELECT '111111' STUDENT_ID FROM DUAL
select STUDENT_ID from MARK
END;
I have a huge sql statement with several 'with' tables in the statement...It works if I execute it as a script but it does not work when I put it in a stored procedure.
When I execute the above it gives me an error...
Error Syntax Check (8:9)
Found 'MARK' expecting .....
It gives me an error at the wth Mark as line....
I have to do it in the stored procedure as the statement is very complicated...
Please help.What tool are you using to create the procedure? Error Syntax Check (8:9) is not an Oracle error, nor as far as I know from any Oracle product.
It works just fine in sqlplus.
SQL> CREATE procedure my_p AS
2 BEGIN
3 UPDATE t
4 SET descr = 'Un'
5 WHERE id IN (WITH tmp AS (
6 SELECT 1 x FROM dual)
7 SELECT x FROM tmp);
8 END;
9 /
Procedure created.
SQL> SELECT * FROM t;
ID DESCR
1 One
SQL> exec my_p;
PL/SQL procedure successfully completed.
SQL> SELECT * FROM t;
ID DESCR
1 UnJohn -
hi all,
I am facing issue with below update statemetn. taking huge time to update. in xx__TEMP table I have index on Project id column. and all underlying table hase index.
Please look into plan and let me how I can reduce Cost for the blow update statement.
Thanks in advance.
UPDATE dg2.ODS_PROJ_INFO_LOOKUP_TEMP o
SET Months_In_Stage_Cnt =
(SELECT
NVL(ROUND(MONTHS_BETWEEN(SYSDATE,x.project_event_actual_date),2),0) Months_In_Stage_Cnt
FROM od.project_event x
WHERE x.project_id = o.project_id
AND event_category_code = 'G'
AND project_event_seq_nbr =
(SELECT MAX(project_event_seq_nbr)
FROM od.project_event y
WHERE y.project_id = x.project_id
AND y.event_category_code = 'G'
AND y.project_event_actual_date IS NOT NULL
AND stage_nbr <> 0
AND y.project_event_seq_nbr <
(SELECT project_event_seq_nbr
FROM od.project_event z
WHERE stage_nbr =
(SELECT current_stage_nbr
FROM od.project
WHERE project_id = x.project_Id )
AND z.project_id = x.project_Id
AND z.event_category_code = 'G'
AND skip_stage_ind = 'N'
AND project_event_actual_date IS NULL )
Plan
UPDATE STATEMENT CHOOSECost: *1,195,213* Bytes: 71,710,620 Cardinality: 41,213
14 UPDATE DG2.ODS_PROJ_INFO_LOOKUP_TEMP
1 TABLE ACCESS FULL TABLE DG2.ODS_PROJ_INFO_LOOKUP_TEMP Cost: 36 Bytes: 71,710,620 Cardinality: 41,213
13 FILTER
3 TABLE ACCESS BY INDEX ROWID TABLE OD.PROJECT_EVENT Cost: 9 Bytes: 104 Cardinality: 8
2 INDEX RANGE SCAN INDEX (UNIQUE) od.XPKPROJECT_EVENT Cost: 3 Cardinality: 8
12 SORT AGGREGATE Bytes: 16 Cardinality: 1
11 FILTER
5 TABLE ACCESS BY INDEX ROWID TABLE od.PROJECT_EVENT Cost: 9 Bytes: 16 Cardinality: 1
4 INDEX RANGE SCAN INDEX (UNIQUE) od.XPKPROJECT_EVENT Cost: 3 Cardinality: 8
10 FILTER
7 TABLE ACCESS BY INDEX ROWID TABLE od.PROJECT_EVENT Cost: 9 Bytes: 108 Cardinality: 6
6 INDEX RANGE SCAN INDEX (UNIQUE) od.XPKPROJECT_EVENT Cost: 3 Cardinality: 8
9 TABLE ACCESS BY INDEX ROWID TABLE od.PROJECT Cost: 2 Bytes: 9 Cardinality: 1
8 INDEX UNIQUE SCAN INDEX (UNIQUE) od.XPKPROJECT Cost: 1 Cardinality: 1
Thanks
Deb882134 wrote:
Can any body give me some light why upto Select statement cost is ok, but only Update statemet is take huge 11m costing.
thanks
DebOkay so completely ignore the content of the 2 forum posts.
Why is the cost an issue for you? Without your tables, data and environment, and without a readable execution plan it's difficult to help you.
Maybe you could read the link I gave you and post some of the information it talks about up here.
p.s. read the link. -
Issue with updating partitioned table
Hi,
Anyone seen this bug with updating partitioned tables.
Its very esoteric - its occurs when we update a partitioned table using a join to a temp table (not non-temp table) when the join has multiple joins and you're updating the partitoned column that isn't the first column in the primary key and the table contains a bit field. We've tried changing just one of these features and the bug disappears.
We've tested this on 15.5 and 15.7 SP122 and the error occurs in both of them.
Here's the test case - it does the same operation of a partitioned table and a non-partitioned table, but the partitioned table shows and error of "Attempt to insert duplicate key row in object 'partitioned' with unique index 'pk'".
I'd be interested if anyone has seen this and has a version of Sybase without the issue.
Unfortunately when it happens on a replicated table - it takes down rep server.
CREATE TABLE #table1
( PK char(8) null,
FileDate date,
changed bit
CREATE TABLE partitioned (
PK char(8) NOT NULL,
ValidFrom date DEFAULT current_date() NOT NULL,
ValidTo date DEFAULT '31-Dec-9999' NOT NULL
LOCK DATAROWS
PARTITION BY RANGE (ValidTo)
( p2014 VALUES <= ('20141231') ON [default],
p2015 VALUES <= ('20151231') ON [default],
pMAX VALUES <= (MAX) ON [default]
CREATE UNIQUE CLUSTERED INDEX pk
ON partitioned(PK, ValidFrom, ValidTo)
LOCAL INDEX
CREATE TABLE unpartitioned (
PK char(8) NOT NULL,
ValidFrom date DEFAULT current_date() NOT NULL,
ValidTo date DEFAULT '31-Dec-9999' NOT NULL,
LOCK DATAROWS
CREATE UNIQUE CLUSTERED INDEX pk
ON unpartitioned(PK, ValidFrom, ValidTo)
insert partitioned
select "ET00jPzh", "Jan 7 2015", "Dec 31 9999"
insert unpartitioned
select "ET00jPzh", "Jan 7 2015", "Dec 31 9999"
insert #table1
select "ET00jPzh", "Jan 15 2015", 1
union all
select "ET00jPzh", "Jan 15 2015", 1
go
update partitioned
set ValidTo = dateadd(dd,-1,FileDate)
from #table1 t
inner join partitioned p on (p.PK = t.PK)
where p.ValidTo = '99991231'
and t.changed = 1
go
update unpartitioned
set ValidTo = dateadd(dd,-1,FileDate)
from #table1 t
inner join unpartitioned u on (u.PK = t.PK)
where u.ValidTo = '99991231'
and t.changed = 1
go
drop table #table1
go
drop table partitioned
drop table unpartitioned
gowrt to replication - it is a bit unclear as not enough information has been stated to point out what happened. I also am not sure that your DBA's are accurately telling you what happened - and may have made the problem worse by not knowing themselves what to do - e.g. 'losing' the log points to fact that someone doesn't know what they should. You can *always* disable the replication secondary truncation point and resync a standby system, so claims about 'losing' the log are a bit strange to be making.
wrt to ASE versions, I suspect if there are any differences, it may have to do with endian-ness and not the version of ASE itself. There may be other factors.....but I would suggest the best thing would be to open a separate message/case on it.
Adaptive Server Enterprise/15.7/EBF 23010 SMP SP130 /P/X64/Windows Server/ase157sp13x/3819/64-bit/OPT/Fri Aug 22 22:28:21 2014:
-- testing with tinyint
1> use demo_db
1>
2> CREATE TABLE #table1
3> ( PK char(8) null,
4> FileDate date,
5> -- changed bit
6> changed tinyint
7> )
8>
9> CREATE TABLE partitioned (
10> PK char(8) NOT NULL,
11> ValidFrom date DEFAULT current_date() NOT NULL,
12> ValidTo date DEFAULT '31-Dec-9999' NOT NULL
13> )
14>
15> LOCK DATAROWS
16> PARTITION BY RANGE (ValidTo)
17> ( p2014 VALUES <= ('20141231') ON [default],
18> p2015 VALUES <= ('20151231') ON [default],
19> pMAX VALUES <= (MAX) ON [default]
20> )
21>
22> CREATE UNIQUE CLUSTERED INDEX pk
23> ON partitioned(PK, ValidFrom, ValidTo)
24> LOCAL INDEX
25>
26> CREATE TABLE unpartitioned (
27> PK char(8) NOT NULL,
28> ValidFrom date DEFAULT current_date() NOT NULL,
29> ValidTo date DEFAULT '31-Dec-9999' NOT NULL,
30> )
31> LOCK DATAROWS
32>
33> CREATE UNIQUE CLUSTERED INDEX pk
34> ON unpartitioned(PK, ValidFrom, ValidTo)
35>
36> insert partitioned
37> select "ET00jPzh", "Jan 7 2015", "Dec 31 9999"
38>
39> insert unpartitioned
40> select "ET00jPzh", "Jan 7 2015", "Dec 31 9999"
41>
42> insert #table1
43> select "ET00jPzh", "Jan 15 2015", 1
44> union all
45> select "ET00jPzh", "Jan 15 2015", 1
(1 row affected)
(1 row affected)
(2 rows affected)
1>
2> update partitioned
3> set ValidTo = dateadd(dd,-1,FileDate)
4> from #table1 t
5> inner join partitioned p on (p.PK = t.PK)
6> where p.ValidTo = '99991231'
7> and t.changed = 1
Msg 2601, Level 14, State 6:
Server 'PHILLY_ASE', Line 2:
Attempt to insert duplicate key row in object 'partitioned' with unique index 'pk'
Command has been aborted.
(0 rows affected)
1>
2> update unpartitioned
3> set ValidTo = dateadd(dd,-1,FileDate)
4> from #table1 t
5> inner join unpartitioned u on (u.PK = t.PK)
6> where u.ValidTo = '99991231'
7> and t.changed = 1
(1 row affected)
1>
2> drop table #table1
1>
2> drop table partitioned
3> drop table unpartitioned
-- duplicating with 'int'
1> use demo_db
1>
2> CREATE TABLE #table1
3> ( PK char(8) null,
4> FileDate date,
5> -- changed bit
6> changed int
7> )
8>
9> CREATE TABLE partitioned (
10> PK char(8) NOT NULL,
11> ValidFrom date DEFAULT current_date() NOT NULL,
12> ValidTo date DEFAULT '31-Dec-9999' NOT NULL
13> )
14>
15> LOCK DATAROWS
16> PARTITION BY RANGE (ValidTo)
17> ( p2014 VALUES <= ('20141231') ON [default],
18> p2015 VALUES <= ('20151231') ON [default],
19> pMAX VALUES <= (MAX) ON [default]
20> )
21>
22> CREATE UNIQUE CLUSTERED INDEX pk
23> ON partitioned(PK, ValidFrom, ValidTo)
24> LOCAL INDEX
25>
26> CREATE TABLE unpartitioned (
27> PK char(8) NOT NULL,
28> ValidFrom date DEFAULT current_date() NOT NULL,
29> ValidTo date DEFAULT '31-Dec-9999' NOT NULL,
30> )
31> LOCK DATAROWS
32>
33> CREATE UNIQUE CLUSTERED INDEX pk
34> ON unpartitioned(PK, ValidFrom, ValidTo)
35>
36> insert partitioned
37> select "ET00jPzh", "Jan 7 2015", "Dec 31 9999"
38>
39> insert unpartitioned
40> select "ET00jPzh", "Jan 7 2015", "Dec 31 9999"
41>
42> insert #table1
43> select "ET00jPzh", "Jan 15 2015", 1
44> union all
45> select "ET00jPzh", "Jan 15 2015", 1
(1 row affected)
(1 row affected)
(2 rows affected)
1>
2> update partitioned
3> set ValidTo = dateadd(dd,-1,FileDate)
4> from #table1 t
5> inner join partitioned p on (p.PK = t.PK)
6> where p.ValidTo = '99991231'
7> and t.changed = 1
Msg 2601, Level 14, State 6:
Server 'PHILLY_ASE', Line 2:
Attempt to insert duplicate key row in object 'partitioned' with unique index 'pk'
Command has been aborted.
(0 rows affected)
1>
2> update unpartitioned
3> set ValidTo = dateadd(dd,-1,FileDate)
4> from #table1 t
5> inner join unpartitioned u on (u.PK = t.PK)
6> where u.ValidTo = '99991231'
7> and t.changed = 1
(1 row affected)
1>
2> drop table #table1
1>
2> drop table partitioned
3> drop table unpartitioned
Maybe you are looking for
-
how do i search for a photo album when i use the search facility on my iPad or iPhone it will not find photo albums of a given name can anyone help
-
the n key on my keyboard suddenly stopped working! For no apparent reason! What can I do?
-
How can I improve network signal in my home?
I have locked myself into a 24 mth contract with Three and I can't get a network signal indoors. Can I do anything to improve the signal in my home?
-
T410, Intel HD Graphics and Windows Server 2008
Hi All When I run my video drivers with the standard VGA it works fine but I can't use my analog VGA port to a projector or external monitor without changing the BOS settings. If I install the Windows 7/Vista video drivers for the Intel HD Graphics,
-
New Produkt by amazon, but adobe doesn´t accept the serial-number. Please (if possible) answer in german - thanks