Query tuning - update with join statement
Hi,
I have 2 tables (table1 and table 2) with following condition:
TABLE 1 - Need to selection a column say staus ! = 'C'
join emp_id and project_id of TABLE1 and TABLE2
From join I am selecting minimun and maximum of TABLE2.salary and updating TABLE3 respective column.
Now as per requirement I have to update required column on TABLE2.EMP_ID = TABLE3.EMP_ID
Following is the query I have written,
update TABLE3 T3
set (T3.MIN_salary, T3.MAX_salary) = (
select min(c.salary), max(c.salary)
from TABLE2 t2, TABLE1 t1
where t2.emp_id = t1.emp_id
and t2.project_id = t1.project_id
and t1.status != 'C'
and t2.emp_id = t3.emp_id)
The above query takes 7 min to update some 8 lakhs records. Can you please suggest some other optimized method to do so?
Thanks in advance
Sandeep
Hi SBH
Required info for "Please provide oracle version, indexes on the 3 tables and also stats info for the table from user_tables"
1) Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
2) Index is not there on TABLE3 (It is temporary table)
Composite index on TABLE 1 - column1, column2 - Index name say table1index1
Composite index on TABLE 2 - column1, column2 - Index name say table2index1
TABLE_NAME NUM_ROWS BLOCKS DEGREE INSTANCES SAMPLE_SIZE PARTITIONED
FXO_CFW 11767341 144930 1 1 11767341 NO
FXO_RSL_STBL 1 1 NO
FXO_TRN 4917778 230196 1 1 4917778 NO
execution plan is:
Execution Plan
Plan hash value: 3131833900
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 789K| 23M| 2397 (3)| 00:00:29 |
| 1 | UPDATE | TABLE3 | | | |
| 2 | TABLE ACCESS FULL | TABLE3 | 789K| 23M| 2397 (3)| 00:00:29 |
| 3 | SORT AGGREGATE | | 1 | 28 | | |
| 4 | TABLE ACCESS BY INDEX ROWID | TABLE2 | 1 | 17 | 3 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 1 | 28 | 12 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID| TABLE1 | 1 | 11 | 9 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN | IDX_TABLE1INDEX1 | 6 | | 3 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | IDX_TABLE2INDEX1 | 1 | | 2 (0)| 00:00:01 |
Thanks for quick response,
Sandeep
Similar Messages
-
Updateable scrollable result sets with join statement
I am writing a generic GUI fronend for any database that has a JDBC2.0 driver available.
I have been using scrollable updateable result sets. These work well for individual tables but as soon as two tables are linked either implicitly or explicitly with a join statement the result set meta data isDefinitelyWriteable is set to false thus preventing the result set from being updated.
Assuming I am using the JDBC-ODBC driver with java sdk1.4.0 and MS Access (although I have used other databases and JDBCs I assume that the one mentioned will be a common combination and needs to work) is there any way of getting linked tables to be updateable with scollable result sets.
I am using scrollable result sets since this prevents the necessity of putting the data in a secondary data store.
I am able to link tables programmatically by requerying the linked table with a new where clause each time the cursor moves in the linked table but this seems rather wasteful. This method is not vey satisfactory when attempting to display data from more than one table which have more than one linked level (i.e. cascaded links).
Is there a simple solution to this problem or do I have to do a rewrite using an update statement instead of having an updateable result set. I assume this method would also require the result set to be reloaded after the update.
Any suggestions much appreciated.I am trying to make the GUI as flexible as possible by constructing "views" which if necessary link tables on one field in each table. This is fine for two tables but when linking to several tables the information thats produced cannot be read easily because as it stands the information from each table is displayed on a separate tabbed page. This mechanism allows me to keep each record set for each table separate and updateable.
Since I could see that this was not very user friendly in the way that it displayed the data I decided to try and introduce a join on two or more tables and hence the introduction of the current problem.
I mentioned that the objective was to be flexible and therefore I also allow queries to be written by the user to facilitate for any shortfalls of the automatic query construction produced by using the "views" mechanism.
So the answer to your question is yes I do control the SQL selections with one mechanism but ultimately no I do not because I provide a fail safe which allows the user to enter arbitary SQL.
I only really want a solution for the controlled SQL construction mechanism where I create the link between two or more tables. As mentioned earlier these are linked on one field only but I wish to provide the option of displaying the result in a single table (tabbed page) rather than spread across multiple tabbed pages. -
Query based on "NATURAL JOIN" statement of Oracle9i
I have created following 4 tables
create table CUST_MASTER
(CUST_NO NUMBER(3),CUST_NAME VARCHAR2(20),CUST_CITY VARCHAR2(20));
create table ITEM_MASTER
(ITEM_NO NUMBER(2),ITEM_NAME VARCHAR2(20),
PRICE NUMBER(4));
create table ORDER_HEADER
( ORDER_NO NUMBER(4), CUST_NO NUMBER(3));
create table ORDER_ITEMS
( ORDER_NO NUMBER(4), ITEM_NO NUMBER(2), QTY NUMBER(3));
Based on the above 4 table I have executed the following query.
select c.cust_no, c.cust_name, c.cust_city, oh.order_no, i.item_no, i.item_name, i.price, oi.qty
from cust_master c, item_master i, order_header oh, order_items oi
where c.cust_no = oh.cust_no and oh.order_no = oi.order_no and oi.item_no = i.item_no;
How should I build similar query in Oracle9i making use of "NATURAL JOIN" statement?Hallo,
yes you are correct.
From SQL Reference
NATURAL JOIN The NATURAL keyword indicates that a natural join is being performed. A natural join is based on all columns in the two tables that have the same name. It selects rows from the two tables that have equal values in the relevant columns
Nothing about foreign keys.
Test:
select * from scott.emp natural join scott.dept
DEPTNO EMPNO ENAME JOB MGR HIREDATE SAL COMM DNAME LOC
20 7369 SMITH CLERK 7902 17.12.1980 800 RESEARCH DALLAS
30 7499 ALLEN SALESMAN 7698 20.02.1981 1600 300 SALES CHICAGO
30 7521 WARD SALESMAN 7698 22.02.1981 1250 500 SALES CHICAGO
20 7566 JONES MANAGER 7839 02.04.1981 2975 RESEARCH DALLAS
30 7654 MARTIN SALESMAN 7698 28.09.1981 1250 1400 SALES CHICAGO
30 7698 BLAKE MANAGER 7839 01.05.1981 2850 SALES CHICAGO
10 7782 CLARK MANAGER 7839 09.06.1981 2450 ACCOUNTING NEW YORK
20 7788 SCOTT ANALYST 7566 19.04.1987 3000 RESEARCH DALLAS
10 7839 KING PRESIDENT 17.11.1981 5000 ACCOUNTING NEW YORK
30 7844 TURNER SALESMAN 7698 08.09.1981 1500 0 SALES CHICAGO
20 7876 ADAMS CLERK 7788 23.05.1987 1100 RESEARCH DALLAS
30 7900 JAMES CLERK 7698 03.12.1981 950 SALES CHICAGO
20 7902 FORD ANALYST 7566 03.12.1981 3000 RESEARCH DALLAS
10 7934 MILLER CLERK 7782 23.01.1982 1300 ACCOUNTING NEW YORK
alter table scott.emp drop constraint fk_deptno
select * from scott.emp natural join scott.dept
DEPTNO EMPNO ENAME JOB MGR HIREDATE SAL COMM DNAME LOC
20 7369 SMITH CLERK 7902 17.12.1980 800 RESEARCH DALLAS
30 7499 ALLEN SALESMAN 7698 20.02.1981 1600 300 SALES CHICAGO
30 7521 WARD SALESMAN 7698 22.02.1981 1250 500 SALES CHICAGO
20 7566 JONES MANAGER 7839 02.04.1981 2975 RESEARCH DALLAS
30 7654 MARTIN SALESMAN 7698 28.09.1981 1250 1400 SALES CHICAGO
30 7698 BLAKE MANAGER 7839 01.05.1981 2850 SALES CHICAGO
10 7782 CLARK MANAGER 7839 09.06.1981 2450 ACCOUNTING NEW YORK
20 7788 SCOTT ANALYST 7566 19.04.1987 3000 RESEARCH DALLAS
10 7839 KING PRESIDENT 17.11.1981 5000 ACCOUNTING NEW YORK
30 7844 TURNER SALESMAN 7698 08.09.1981 1500 0 SALES CHICAGO
20 7876 ADAMS CLERK 7788 23.05.1987 1100 RESEARCH DALLAS
30 7900 JAMES CLERK 7698 03.12.1981 950 SALES CHICAGO
20 7902 FORD ANALYST 7566 03.12.1981 3000 RESEARCH DALLAS
10 7934 MILLER CLERK 7782 23.01.1982 1300 ACCOUNTING NEW YORK
ALTER TABLE scott.emp
ADD CONSTRAINT fk_deptno FOREIGN KEY (deptno)
REFERENCES SCOTT.dept (deptno)
ENABLE NOVALIDATE
/Regards
Dmytro Dekhtyaryuk -
Oracle Syntax for Update with Join
Can anyone help with the Oracle Syntax on and update that includes a join?
This is what I've got:
Update
(SELECT a.DOCUMENT_NO
From DOCUMENT_CONTROL a, DOCNOTEST b
where a.DOCUMENT_NO = b.DOCUMENT_NO)
set a.PATH = NULL
Everything I try leads to another error message. With the current code I'm getting the error message: ORA-00971 a.path invalid identifier.
I am much more familiar with SQL Server (if you can't tell :) This is the way I would write the above in SQL Server.
UPDATE DOCUMENT_CONTROL
Set [Path] = ''
FROM DOCUMENT_CONTROL
INNER JOIN DOCNOTEST
ON DOCUMENT_CONTROL.DOCUMENT_NO=DOCNOTEST.DOCUMENT_NO
where DOCUMENT_CONTROL.DOCUMENT_NO=DOCNOTEST.DOCUMENT_NO
Does anyone have any advice for me? Thanks in advanceAlternate syntax since it seems you're not able to update the join...
update DOCUMENT_CONTROL a
set
a.path = null
where a.path is not null
and exists
select null
from DOCNOTEST b
where a.DOCUMENT_NO = b.DOCUMENT_NO
); -
Hello All,
I'm trying to update several colums of a table from a inner join query.
First a retrieve the rows afected and the values that I need for the update (I call this subquery ED_Query).
It's important to note that this subquery has a group by and and having clause.
My first attemp (using the query that work in SQL Server query) fails:
SQL> update ED_Update
2 set ED_Update.dtHoraInicioReal = ED_Query.dtHoraInicioReal,
3 ED_Update.dtHoraFinReal = ED_Query.dtHoraFinReal,
4 ED_Update.fPorcentajeRealizado = ED_Query.fPorcentajeRealizado
5 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED_Update
6 inner join (
7 select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
8 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
9 MAX(HPP.iOrden) as iOrdenUltimaParada,
10 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
11 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
12 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado
13 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
14 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
15 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
16 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
17 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
18 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal
19 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
20 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal)
21 ) ED_Query
22 on ED_Update.iIdExpedicionDiaria = ED_Query.iIdExpedicionDiaria;
ERROR at line 5:
ORA-00933: SQL command not properly ended
The subquery (ED_Query) work fine in Oracle, so I suspect that the problems are when I mix it with the update clause.
SQL> select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
2 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
3 MAX(HPP.iOrden) as iOrdenUltimaParada,
4 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
5 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
6 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
7 ED.dtHoraInicioReal as ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
8 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
9 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
10 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
11 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
12 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
13 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal, ED.fPorcentajeRealizado
14 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
15 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal);
IIDEXPEDICION IIDEXPEDICIONDIARIA INUMPARADAS IORDENULTIMAPARADA DTHORAINI
DTHORAFIN FPORCENTAJEREALIZADO ED_DTHORA ED_DTHORA ED_FPORCENTAJEREALIZADO
-131076 5662 406 15-JAN-13
15-JAN-13 15-JAN-13 15-JAN-13 0
-131076 5663 406 15-JAN-13
15-JAN-13 15-JAN-13 15-JAN-13 0
-131076 5664 406 15-JAN-13
15-JAN-13 15-JAN-13 15-JAN-13 0
After reading this forum, I change the query and try the next one:
SQL> UPDATE
2 (
3 select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
4 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
5 MAX(HPP.iOrden) as iOrdenUltimaParada,
6 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
7 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
8 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
9 ED.dtHoraInicioReal as ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
10 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
11 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
12 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
13 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
14 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
15 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal,ED.dtHoraFinReal, ED.fPorcentajeRealizado
16 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
17 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal)
18 )
19 SET ED_dtHoraInicioReal = dtHoraInicioReal,
20 ED_dtHoraFinReal = dtHoraFinReal,
21 ED_fPorcentajeRealizado = fPorcentajeRealizado;
ERROR at line 2:
ORA-01732: data manipulation operation not legal on this view
Some help?
Thanl in advance.
Edited by: 984483 on 28-ene-2013 1:48Thanks for your answer. I tried to rewrite my question.
SQL> select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
PL/SQL Release 9.2.0.3.0 - Production
CORE 9.2.0.3.0 Production
TNS for 32-bit Windows: Version 9.2.0.3.0 - Production
NLSRTL Version 9.2.0.3.0 - Production
I have 2 tables. I like to update one of them (ED_Update) with the data from the another one (ED_Query).
This example is equivalent:
create table ED_Query (id number,
date01 date,
number01 number)
insert into ED_Query values (1, to_date('01/01/2013','DD/MM/YYYY'), 10);
insert into ED_Query values (2, to_date('01/01/2013','DD/MM/YYYY'), 20);
insert into ED_Query values (3, to_date('01/01/2013','DD/MM/YYYY'), 30);
insert into ED_Query values (4, to_date('02/01/2013','DD/MM/YYYY'), 40);
insert into ED_Query values (5, to_date('03/01/2013','DD/MM/YYYY'), 50);
create table ED_Update (date01 date,
numberMax number,
numberSum number)
insert into ED_Update values (to_date('01/01/2013','DD/MM/YYYY'), 0, 0);
insert into ED_Update values (to_date('02/01/2013','DD/MM/YYYY'), 0, 0);
insert into ED_Update values (to_date('03/01/2013','DD/MM/YYYY'), 0, 0);
The next update query fails with ORA-00933: SQL command not properly ended.
update ED_Update
set ED_Update.date01 = ED_Query.date01,
ED_Update.numberMax = ED_Query.numberMax,
ED_Update.numberSum = ED_Query.numberSum
inner join
select date01, max (number01) as numberMax, sum(number01) as numberSum
from ED_Query
where date01 = TO_DATE('01/01/2013', 'DD/MM/YYYY')
group by date01
) ED_Query
on ED_Update.date01 = ED_Query.date01
I think the problem is in the update clause because the next query work:
select * from
ED_Update
inner join
select date01, max (number01) as numberMax, sum(number01) as numberSum
from ED_Query
where date01 = TO_DATE('01/01/2013', 'DD/MM/YYYY')
group by date01
) ED_Query
on ED_Update.date01 = ED_Query.date01
Thank in advance. -
Hello Everybody
I have 3 tables in a maxdb 7.6 database
rbarbeitsplanpos key=rbarbeitsplanposid column gewichtung,...
rbaplposausf key=rbaplposausfid columns rbarbeitsplanposid,...
rbqspruefpos key=rbqspruefposid columns rbaplposausfid,gewichtung,...
Now i want to update gewichtung in rbqspruefpos with the value of gewichtung in the corresponding record in rbarbeitsplanpos.
The way to find the correct value is:
From rbqspruefpos with rbaplposausfid into rbaplposausf
From rbaplposausf with rbarbeitsplanposid to rbarbeitsplanpos
I found this hit:
A simple example of the power of including joins in an Update Statement:
Update Tbl1 set tbl1.field1=tbl2.field2*.10,
from Tbl1 join tbl2 on tbl1.PKfield=tbl2.tbl1FK
This will update all the joined rows in tbl1 to 10% of the values in tbl2.
I code:
update rbqspruefpos set gewichtung = rbarbeitsplanpos.gewichtung,
from rbqspruefpos
join rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
General error;-5016 POS(73) Missing delimiter: =
This one works without errors:
update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung from rbarbeitsplanpos
join rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
but all rbqspruefpos.gewichtung are filled with the same value?
The first value found in rbarbeitsplanpos.
Any help welcomed
Best regards
Albert> I code:
> update rbqspruefpos set gewichtung = rbarbeitsplanpos.gewichtung,
> from rbqspruefpos
> join rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
> join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
>
> General error;-5016 POS(73) Missing delimiter: =
>
>
> This one works without errors:
> update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung from rbarbeitsplanpos
> join rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
> join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
>
> but all rbqspruefpos.gewichtung are filled with the same value?
> The first value found in rbarbeitsplanpos.
Looks like you're doing it wrong.
Subselects need to be enclosed in brackets.
See [Subquery (subquery)|http://maxdb.sap.com/doc/7_6/60/515f3eca2a11d2a97100a0c9449261/content.htm]
Only scalar subselects (these are the ones that by their very structure can only produce zero or one rows in the result set) can omit the brackets.
The database cannot know that there is only one value in this column - you may try and put a aggregation function round it.
regards,
Lars -
Help with an update with join (works in access)
This is my working query in ms access...
UPDATE Caxnode AS A INNER JOIN Caxnode AS B ON A.node_alias = B.node_alias SET A.partition_Type = 'LDOM', A.node_mode = 'LOGICAL', A.host_id = b.host_id, A.num_of_proc = b.num_of_proc WHERE (((A.node_mode)='virtual' Or (A.node_mode)='regular') AND ((B.partition_Type)='LDOM'));
This doesn't work in oracle, I googled and read that update doesnt work with inner join in oracle..
can someone please help me translate this query to work on oracle?
Thanks!
-nikhil.thanks for your reply. however, im a little confused . i want to update the table caxnode for a particular node_alias if the same table has the SAME node_alias defined as partition_Type=ldom
for eg..
my table is as follows
id node_alias host_id node_mode partition_type num_procs
1 abc abc virtual null 2
2 abc xyz logical LDOM 4
3 def def virtual null 2
4 def ppp logical LDOM 8
5 abc abc regular null 3
So those that are ldoms are marked ldom in partition_type, those that are not recognised as ldoms are marked null in partition_type. LDOM's are logical in node_mode, others are either virtual or regular in node_mode.
Now since there are some old entries that are marked regular/virtual and NULL but are actually LDOMs, I need to go through the table and mark those as LDOM's which have same node_alias marked as LDOM later on.
In the table above, abc is marked as LDOM in row 2, so row 1 and 5 should reflect that. the host id should change to host_id in row 2 because the same alias is defined as ldom in row 2..
Same with def.. host_id for def should change to host_id thats in row 4 because def is also defined as ldom in row 4..
The table should look like this
id alias host_id node_type num_procs
1 abc xyz LDOM 4
2 abc xyz LDOM 4
3 def ppp LDOM 8
4 def ppp LDOM 8
5 abc xyz LDOM 4 -
hay guys
I have written a query in ABAP OO to join 2 tables and have output in different table.Here i want only selected fields in 3 table .I dont know why this query is giving erroe.Help needed.
TYPES : BEGIN OF ty_catsubcat,
CATEGORYID type ZNCYID,
DESCRIPTION_CAT TYPE ZNCYID,
SUBCATID type ZNSBCYID,
DESCRIPTION_SUBCAT type ZNSBDS,
END OF ty_catsubcat.
DATA : IT_CATSUBCAT TYPE TABLE OF ty_catsubcat.
Select ZNCYMS~CATEGORYID ZNCYMS~DESCRIPTION ZNSBCYMS~SUBCATID ZNSBCYMS~DESCRIPTION
INTO (IT_CATSUBCAT-CATEGORYID,
IT_CATSUBCAT-DESCRIPTION_CAT,
IT_CATSUBCAT-SUBCATID,
IT_CATSUBCAT-DESCRIPTION_SUBCAT)
FROM ZNCYMS INNER JOIN ZNSBCYMS
ON ZNCYMS~CATEGORYID = ZNSBCYMS~CATEGORYID
order by ZNCYMS~CATEGORYID.
endselect.A few issues..
Your table it_catsubcat does not have a header line, and you are trying to insert into the header area of the table which does not exist. Either declare a work area/header, or do a table fetch instead.
Select ZNCYMSCATEGORYID ZNCYMSDESCRIPTION ZNSBCYMSSUBCATID ZNSBCYMSDESCRIPTION
<b> INTO CORRESPONDING FIELDS OF TABLE IT_CATSUBCAT</b>
FROM ZNCYMS INNER JOIN ZNSBCYMS
ON ZNCYMSCATEGORYID = ZNSBCYMSCATEGORYID
order by ZNCYMS~CATEGORYID.
If you use a work area to insert into, then you need to append the work area to your internal table.
data: IT_CATSUBCAT TYPE TABLE OF ty_catsubcat with header line.
Select ZNCYMSCATEGORYID ZNCYMSDESCRIPTION ZNSBCYMSSUBCATID ZNSBCYMSDESCRIPTION
INTO (IT_CATSUBCAT-CATEGORYID,
IT_CATSUBCAT-DESCRIPTION_CAT,
IT_CATSUBCAT-SUBCATID,
IT_CATSUBCAT-DESCRIPTION_SUBCAT)
FROM ZNCYMS INNER JOIN ZNSBCYMS
ON ZNCYMSCATEGORYID = ZNSBCYMSCATEGORYID
order by ZNCYMS~CATEGORYID.
append it_catsubcat.
endselect. -
Count of Rows Updated with prepared statement batch
I am using a batch of prepared statements for update operation. (pstmt.executeBatch())
Configuration I am using
WLS 6.1sp2 Connection pool - Oracle Thin driver - TX Datasource
DB - Oracle 8.1.7
The batch update works well i.e data gets updated and committed. BUT I am not
getting back the count of number of rows updated.
Is there any thing more required on WLS side ?
Thanks in AdvanceThe Oracle drivers do not return the updated row counts from batched updates.
Try running the attached program with the thin driver
java Batch oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@host:port:database user password
You will see that returns -2, which indicates that the number of rows updated is unknown.
This does meet the JDBC spec.
"Harshad Nanal" <[email protected]> wrote in message news:3f8a455f$[email protected]..
>
I am using a batch of prepared statements for update operation. (pstmt.executeBatch())
Configuration I am using
WLS 6.1sp2 Connection pool - Oracle Thin driver - TX Datasource
DB - Oracle 8.1.7
The batch update works well i.e data gets updated and committed. BUT I am not
getting back the count of number of rows updated.
Is there any thing more required on WLS side ?
Thanks in Advance[Batch.java] -
SQL QUERY TUNING(PARTITONS AND JOIN)
Hello
My below query is taking very long time to execute ..here is the query and explain plan
EXPLAIN PLAN FOR select w.ref_no,a.*
from table1 a left outer join table2 w
on(a.emp_id=w.emp_id)
where a.joining_date=20090205 ;
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Pstart| Pstop |
| 0 | SELECT STATEMENT | | 2415K| 504M| | 226K (2)| | |
|* 1 | HASH JOIN OUTER | | 2415K| 504M| 488M| 226K (2)| | |
|* 2 | TABLE ACCESS BY INDEX ROWID| table1 | 2415K| 460M| | 77975 (1)| | |
|* 3 | INDEX RANGE SCAN | table1_joining_ DATE | 2441K| | | 6463 (2)| | |
| 4 | PARTITION RANGE ALL | | 39M | 718M| | 64745 (2)| 1 | 4 |
| 5 | TABLE ACCESS FULL | table2 | 39M | 718M| | 64745 (2)| 1 | 4 |
table 2 has 40 million rows
Table2 structure
emp_id
ref_no
Project_id
Partitoned on Project_id, Project_id is nowhere used on the above query
Table1 Structure
emp_id
joining_date
other columns
Is indexed on joining_date, not partitioned
Please adviseThe CBO has estimated that you have 2415K table1 rows where joining_date = 20090205. (By the way: is this really a number?!)
Is this estimate accurate?
Please add some more information:
- Which version do you use
- How long is "very long time"?
- How many does your query return
- information as described in this thread: When your query takes too long ...
Regards,
Rob. -
Update with case statement problem.
Hi,
I have this statement
update tab_tr set col_rate =
case
when col_ern_type in ('031','035','036') then (1.5 * col_rate)
when col_ern_type in ('041','045','046') then (2 * col_rate)
end;this statement updated some 2 million rows in the table tab_tr. But the total count of rows for col_ern_type in ('031','035','036', '041','045','046') yeild only around 222642 rows.
select count(*) from tab_tr where col_ern_type in ('031','035','036', '041','045','046'); --> 222642 rowswhat is the problem with the above update statement.
Thank you,Hi,
DBA_1976 wrote:
... I thought the case statement conditions are counted as the where condition. But ......A CASE expression just takes the place of some other expression, such as a literal, a function, or a column.
For example, which rows do you think this should update?
UPDATE tab_tr
SET col_rate = 100;It would update all rows, of course.
How about this statement?
UPDATE tab_tr
SET col_rate = column_x;Will it only change the rows where column_x are a certain value, or not NULL, or in any way depend on column_x? No, of course not. It will update all rows.
How about this statement?
UPDATE tab_tr
SET col_rate = function_y (col_ern_type);Will it only change the rows where the fucntion returns a certain value? Will it depend on the value in col_ern_type? No, of course not. It calls the function for each row, and whatever the function returns (even if the function returns NULL), that's what goes into col_rate on each row.
A CASE expression is just something that you can substitute in place of any other expression, such as the literal 100, or the column column_x, or the function function_y in the statements above. Naturally, the value that gets put into col_rate will depend on what the CASE expression returns, but the behavior of the UPDATE statement as a whole will not. -
HI Everyone,
I'm facing a issue with SQ02, where I need to link 2 table COVP and AFRU . Now that I have 2 feilds in COVP REFBN and AWORG which is or Char(10) feilds and I need to link this with tabl;e AFRU feilds RUECK and RMZHL which is of Num(10) and Num(4).
I cant use a join link between these 2 feilds as it says illegal join. Now I need to pull data by the input from COVP that of refbn and aworg.
Please let me know how to go about and implement this? Is there a way where I can use the code section and write code for this. I need to further add another table CATSDB from the output from AFRU.
Thanks & Best regards,
RajHi Raj,
I had the same problem with other join, since the two fields are different it is not possible to use a join on them.
The only solution that occurred to me was to create an auxiliary table to map both fields with all possible values, like this:
| fild1 | field2 |
| 001 | 00001 |
| 002 | 00002 |
And a view with one of the tables together with this auxiliary one. Then the join would use this view...
I admit it isn't pretty, but it would work. However in the end I've decided to write a program instead of using a query to obtain our client's desired map.
best regards,
Edgar -
Hello,
I want to use case in update statement.
For example I have a table whose name is Item. There are 20 fields in this table. StockHoldType, Quantity and Amount are three of them.
I want to update quantity or amount fields according to stockholdtype fields value. If stockholdtype is 1 , I will update quantity field,
if stockholdtype field is 2 I will update amount field.
How can I do this?upadte table_name
set Quantity = decode(stockholdtype,1,+new_value+,quantity),
amount = decode(stockholdtype,2,+new_value+,amount)
where stockholdtype in (1,2) -
I have 2 tables
tblA(aID, aSeq, aname, aLname)
tblB(bSeq, bname, bLname)
I need to update table tblA to set aSeq where the name and Lname match with tblB. Something like
update zA A
set A.aSeq =
select B.bSeq
from zB B
where UPPER(B.bname) = UPPER(A.aname)
and UPPER(B.blname) = UPPER(A.alname)
What am I doing wrong? Why do I get the error - ORA-01427: single-row subquery returns more than one rowbased on above scenario (tblA => proposal tblB => personnel)
select rp.prop_id || '| ' || UPPER(rp.prodir_fn) || '| ' || UPPER(rp.prodir_ln)
from proposal rp
where exists(
select p.piid ---------------------------------------------------get matching names from personnel
from personnel p
where UPPER(rp.prodir_fn) = UPPER(p.fname)
and UPPER(rp.prodir_ln) = UPPER(p.lname)
and EXISTS
( select UPPER(q.fname), UPPER(q.lname) ------------ get matching names of single person that is drop
from personnel q--------------------------------------------- peron names who have same first and last name different id
where UPPER(q.fname) = UPPER(p.fname)
and UPPER(q.lname) = UPPER(p.lname)
group by UPPER(q.fname), UPPER(q.lname)
having count(*) = 1
gives me 3535 matching records
but
my update still fails, Please guide
UPDATE proposal rp
set rp.pi = (
select p.piid
from personnel p
where UPPER(rp.prodir_fn) = UPPER(p.fname)
and UPPER(rp.prodir_ln) = UPPER(p.lname)
and EXISTS
( select UPPER(q.fname), UPPER(q.lname)
from personnel q
where UPPER(q.fname) = UPPER(p.fname)
and UPPER(q.lname) = UPPER(p.lname)
group by UPPER(q.fname), UPPER(q.lname)
having count(*) = 1
; -
SQL Server updating with join issue
Could someone explain to me why this update script isn't behaving the way I think it should. I'm currently running the following script:SQLUPDATE [PO_RECVR_HIST]SET [PO_RECVR_HIST].[REF] = ( CASE -- Place MUD or HOCKEY in receiver header reference fields WHEN coalesce([IM_ITEM].[ATTR_COD_1], '') = 'MUD' THEN 'MUD' WHEN coalesce([IM_ITEM].[ATTR_COD_1], '') = 'HOCKEY' THEN 'HOCKEY' ELSE coalesce([PO_RECVR_HIST].[REF], [PO_RECVR_HIST].[REF]) END )FROM [PO_RECVR_HIST] LEFT JOIN[PO_RECVR_HIST_LIN]ON -- Acquire all the line information for each receiver header[PO_RECVR_HIST].[RECVR_NO] = [PO_RECVR_HIST_LIN].[RECVR_NO]LEFT JOIN[IM_ITEM] ON -- Acquire all the item information (specifically attribute code 1) for each line item on the receiver[PO_RECVR_HIST_LIN].[ITEM_NO] = [IM_ITEM].[ITEM_NO]I'm trying to run this script on the PO_RECVR_HIST...
This topic first appeared in the Spiceworks Community1) First Reboot your server and try again for the installation.
2) If first fail again than Take a backup of Registry first for safe side and then delete the entries of SQL server 2012 if found take a reboot again and try to install again.
One more thing if installation created any file then move/Delete that also before installation.
Maybe you are looking for
-
I want to download specific music to my IPad so I can access it off line. I have iOS 8 on my Mac mini and my pad. The artists, albums and playlists I have selected to sync on my Mac mini do not show up on my iPad. I am involved in international vo
-
Tried to update to the newest version of Flash Player. The file in question is on the computer in two locations, including WOW64 which someone online said that's where Flash looks for the file. The really bothersome problem is that the error message
-
HI EXPERTS I searched on sdn on how to remove tab from va01 and created a transaction variant through shd0 i made the tab appearing at item level data invisible but when i test it it still shows that tab please help. being specific i need to remove t
-
Adobe LiveCycle Connection to MS SQL Server
Hello All, I'm new to Adobe Livecycle. I want to create a form in Adobe LiveCycle that will connect to SQL server database and pull data from it. The user will be running the form on MAC. Can this be achieved? Any inputs on this will be greatly appre
-
How do i stop the envelope indicator from flashing? I don't have "new" messages -- but it's flashing 24/7 -- and has been since i got the device! N96-3 thank you! Solved! Go to Solution.