Statement UPDATE of SQL TIP about WHERE CLAUSE
(1) Oracle does support SQL UPDATE statement of SUSPICION for WHERE CLAUSE(2) if so, then please give example.
Thank you.
Hello
Yes, it is possible to use the "tips" in the Update statement
Sake example
Update
/ * + rowid * /.
tableX
Set char_date = '19' | char_date
where nvl (length (char_date), 0) = 6
and rowid between chartorowid ('000927.0000.0008')
and chartorowid('000A3F.) FFFF.0008');
http://Stanford.edu/dept/ITSS/docs/Oracle/10G/server.101/b10752/hintsref.htm#27647
-Pavan Kumar N
Tags: Database
Similar Questions
-
Update statement with joins of tables and where Clause
Hi, I have MS SQL background and I try to execute an update statement in Oracle with joins of tables. However, the syntax below does not work but I think it works for MS SQL.
Basically, the base table must be attached to a master table trend with monthly snapshots, an account will be only an entry for a given date monthly. Where clause must be limited to accounts within a certain range of interest rates.
The first approach returns command SQL ORA-00933 not correctly completed, and the second approach returns ORA-01427 row below query returns multiple rows. Can anyone help? Thanks in advance!
1:
Update PenaltyAll
Set a.indicator = month (b.)
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
where a.monthend='01/31/2009' and b.date='12/31/2008' and b.apr < 20
2:
Update PenaltyAll
adjustment indicator =
(select to_char (b., 'MM')
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
"where to_char (a.monthend,'mm/dd/yyyy ') = 31 January 2009"
(et to_char(b.date,'mm/dd/yyyy') = December 31, 2008 "
and b.apr < 20)
Published by: sqlrookie on August 21, 2009 07:04I edited my post, that was my mistake, ANC you try now?
-
Hello
I'm doing a conditional clause where clause displays the lines in a report.
The desired control is date of two fields (CIC and announcement) must all be virgins or someone not be an 'Admin' (taken from a global variable stored on connection) for her to no display.
Here's what I have:
WHERE (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN IS NOT NULL AND DATACOLLECT. CHANGE_IN_CONTROL IS NOT NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".
During the test of this query, it hides a field with ONE of the two dates being blank and which is not desirable.
I also tried to write it like this and got an error of analysis for an invalid relational operator:
WHERE (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN AND DATACOLLECT. CHANGE_IN_CONTROL IS NOT NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".
Any help would be greatly appreciated. Please let me know if I need to clarify.
I take what I said back. Your requirement of "double negative" is odd
DO NOT SHOW: where (X is null and Y is null)
translates
Show: where not (x is null and Y is null)
WHERE NOT (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN is null AND DATACOLLECT. CHANGE_IN_CONTROL IS NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".
MK
PS - this is a thing of database. PL/SQL and SQL would have been a better choice
-
I have the following table.
I need to create a query that returns:
(a) if the table contains 1 and 0 on pass that only values with 1
(b) otherwise, if the table contains only 1 on collar that only values 1
(c) otherwise, if the table contains only 0 on pass that only values to 0.
I tried with the following query, but if the table contains only 0 returns nothing
{code}
create table test
(col1 number);
Insert in the test
values (1);
Insert in the test
values (1);
Insert in the test
values (1);
Insert in the test
values (0);
Insert in the test
values (0);
Insert in the test
values (0);
commit;
Select *.
of the test
where
col1 case
When 1 then 1
0 otherwise
end = nvl2 (col1, 1, 0);
{code}
Thank you
Hello
If you want to find which is the highest value of col1 in the table and view only the lines where col1 has this value.
Here's a way to do it:
WITH got_max_col1 AS
(
SELECT col1
MAX (col1) ON (AS max_col1)
OF the test
WHERE col1 IN (0, 1) - if necessary
)
SELECT col1
OF got_max_col1
WHERE col1 = max_col1
;
With the sample data you posted, you do not have the condition: WHERE col1 IN (0, 1)
If you add lines where col1 can be anything other than 0 or 1, then this condition will ignore them.
-
Case statement in a WHERE clause
Gurus,
Im trying to avoid Union of several select statements using a CASE inside a WHERE clause. When the parameter is defined as "What's new" it is advisable to use a code and for "Update Items" another condition.
Having a problem with the following... I know that BOX in WHEREs instructions are allowed only can not make it work for this one.
Points for correct and helpful answers!and case when 'New Items' = 'xxx' --p_item_status then msi.creation_date = msi.last_update_date when 'Updated Items' = 'bbb' --p_item_status then msi.creation_date != msi.last_update_date else 1=1 end;
Published by: sreese on March 27, 2012 17:51Hello
The great thing about CASE expressions, is that they allow you to use a login IF-THEN-ELSE in the clause SELECT, the ORDER BY clause or anywhere else. The WHERE clause has its own way to IF-THEN-ELSE logic, so even if you can use a CASE expression in a clause WHERRE, it usually does not help anything. You can do somehting like this:
WHERE ( :p_item_status = 'New Items' AND msi.creation_date = msi.last_update_date ) OR ( :p_item_status = 'Updated Items' AND msi.creation_date != msi.last_update_date ) OR ( :p_item_status NOT IN ( 'New Items' , 'Updated Items' ) )
This guess: p_item_status is not NULL.
If: p_item_status can be NULL, and you want to include all the lines where it is, and then change the last condition toOR ( NVL (:p_item_status, 'OK') NOT IN ( 'New Items' , 'Updated Items' ) )
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions), some values of the parameter and the expected results of these data for each value of the parameter.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using. -
Hello
When I run this application it shows no record
But if I use a space in where clause, it shows the recordsSQL> select * from mas_unit where unit_name!=''; no rows selected SQL> select * from mas_unit where unit_name=''; no rows selected
Please can someone explain what oracle doing here?select * from mas_unit where unit_name!=' '; 13364 rows selected.
Thanx11 g DBA wrote:
Hello
When I run this application it shows no recordSQL> select * from mas_unit where unit_name!=''; no rows selected SQL> select * from mas_unit where unit_name=''; no rows selected
But if I use a space in where clause, it shows the records
select * from mas_unit where unit_name!=' '; 13364 rows selected.
Please can someone explain what oracle doing here?
Thanx
Oracle sees the empty string ('') as NULL.
Use IS NULL or IS NOT NULL instead of = or! =
documentation http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements005.htm#g194888Nulls in Conditions
A condition that evaluates to UNKNOWN behaves almost like FALSE. For example, a SELECT statement with a condition in the WHERE clause that evaluates to UNKNOWN returns no rows. -
NVL selection list does not not on the place where clause in query
Ok. APEX 4.2...
Im having problems with my selection lists and NULL values... I see that it has come time and time again...
I have a tabular presentation, with a query based on a selection list. The selection list has the ability to '- Show All -'... The value of the selection list is a number, and the display is words... (for reference the LOV query is: select status, batch from pmt_stat_lookup by 1)
Initially I had problems with null and invalid numbers like ' display Null = 'Yes' and the problem of null % ', so have used the code in this blog to remove the NULL values... Display Null = & amp; #34; Yes & amp; #34; and the problem of null % | Inside Oracle APEX by Patrick Wolf
Then in the application of my report, I have a where clause clause that checks the value of the selection list... WHERE batch = nvl(:P11_STATUS_SELECT,STATUS_ID)
everything works almost fine, and I can choose a status, or I choose - see the All-, but the query will not include the lines where the State is null.
(I also see that maybe I should be, use the case statement instead of the NVL on where clause, but not sure of the syntax. In addition, NVL was used somewhat in the different reports in the application...)
For reference, the code of the old blog that I as a process page is:
BEGIN
FOR rItem IN
(SELECT NOM_ELEMENT
OF APEX_APPLICATION_PAGE_ITEMS
WHERE APPLICATION_ID = TO_NUMBER(:APP_ID)
AND PAGE_ID IN (TO_NUMBER(:APP_PAGE_ID), 0)
AND LOV_DISPLAY_NULL = 'Yes'
AND LOV_DEFINITION IS NOT NULL
-change here
AND LOV_NULL_VALUE = '% null | '%'
)
LOOP
IF V (rItem.ITEM_NAME) = "% null | '%'
THEN
Apex_Util.set_session_state (rItem.ITEM_NAME, NULL);
END IF;
END LOOP;
END;
Thank you very much
Richard
Richard,
Perhaps this example can help you solve your problem.
https://Apex.Oracle.com/pls/Apex/f?p=63838:2
Jeff
-
Execution of statement of UPDATE for the whole table even when the WHERE Clause is presentation
Hi friends,
I have a problem in a stored procedure where I wrote an update with a where clause clause statement. At some point only one line should be updated according to the unique identifier in where clause.
But what is happening is that the Update statement is getting executed for all rows in the table to neglect the WHERE clause. I don't get any idea of why this is happening. Here is the stored procedure and the update statement is BOLD:-
CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
(
CntryMasterCode IN VARCHAR2,
CntryName IN VARCHAR2,
MDMUser IN VARCHAR2,
Exists IN ITS ENTIRETY,
status in VARCHAR2,
Inserted_By IN VARCHAR2 default NULL,
Modified_By IN VARCHAR2 default NULL,
Mdm_Code IN the DEFAULT NUMBER 0.
Action in VARCHAR2 DEFAULT 'Add ',.
XGenAttNames IN VARCHAR2 default NULL,
XGenAttValues IN VARCHAR2 default NULL,
MirusAttNames IN VARCHAR2 default NULL,
MirusAttValues IN VARCHAR2 default NULL,
GenisysAttNames IN VARCHAR2 default NULL,
GenisysAttValues IN VARCHAR2 default NULL,
XGenModify IN VARCHAR2 default NULL,
MirusModify IN VARCHAR2 default NULL,
GenisysModify IN VARCHAR2 default NULL
)
IS
strSQLXGen VARCHAR (1000);
strSQLMirus VARCHAR (1000);
strSQLGenisys VARCHAR (1000);
nMaxMDMCode INTEGER.
ifExist INTEGER;
/******************************************************************************
NAME: proc_MDM_InsertCntryDetails
PURPOSE:
REVISIONS:
Worm Date Description of the author
--------- ---------- --------------- ------------------------------------
1.0 03/07/2009 1. Created this procedure.
NOTES:
Keywords to replace automatically available Auto:
Object name: proc_MDM_InsertCntryDetails
SYSDATE: 03/07/2009
Date and time: 03/07/2009, 19:11:20 and 03/07/2009-19:11:20
User name: (put in TOAD Options, editor of the procedure)
Name of the table: (defined in the dialog box "New PL/SQL object")
******************************************************************************/
BEGIN
COUNT (*) of SELECT INTO ifExist OF MDM_COUNTRY_MASTER;
IfExist IF = 0 THEN
SELECT 1 INTO nMaxMDMCode FROM DUAL;
ON THE OTHER
SELECT MAX (MDM_CODE) + 1 IN MDM_COUNTRY_MASTER nMaxMDMCode;
END IF;
IF Action = "add" THEN
INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,exist,Status,action,sysdate,Inserted_By);
strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
"VALUES (' |)" nMaxMDMCode | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen;
strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
"VALUES (' |)" nMaxMDMCode | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus;
strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
"VALUES (' |)" nMaxMDMCode | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys;
ON THE OTHER
UPDATE MDM_COUNTRY_MASTER
SET MDM_DESCRIPTION = CntryName, DAT_MODIFIED_BY = Modified_By, DAT_MODIFY_DATE = SYSDATE.
MDM_USER = MDMUser, MDM_ACTION = Action, MDM_STATUS = status MDM_EXIST = exist WHERE MDM_CODE = Mdm_Code;
COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 1 AND MDM_CODE = Mdm_Code;
IfExist IF = 0 THEN
strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
' VALUES(' ||) Mdm_Code | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen;
ON THE OTHER
strSQLXGen: = "UPDATE MDM_COUNTRY_MAPPING SET | XGenModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 1';
EXECUTE IMMEDIATE strSQLXGen;
END IF;
COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 2 AND MDM_CODE = Mdm_Code;
IfExist IF = 0 THEN
strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
' VALUES(' ||) Mdm_Code | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus;
ON THE OTHER
strSQLMirus: = "UPDATE MDM_COUNTRY_MAPPING SET | MirusModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 2';
EXECUTE IMMEDIATE strSQLMirus;
END IF;
COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 3 AND MDM_CODE = Mdm_Code;
IfExist IF = 0 THEN
strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
' VALUES(' ||) Mdm_Code | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys;
ON THE OTHER
strSQLGenisys: = "UPDATE MDM_COUNTRY_MAPPING SET | GenisysModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 3';
EXECUTE IMMEDIATE strSQLGenisys;
END IF;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHILE OTHERS THEN
-Consider recording the error and then re-raise
LIFT;
END proc_MDM_InsertCntryDetails;
/
Thank you>
WHERE mdm_code = mdm_code
>This will always be value true - similar to WHERE 1 = 1.
You typed it wrong or is the same as the variable column name? If they are the same test rename one of them.
-
Exclude duplicates on SQL where clause statement
Hello!
Are a few posibilities to exclude duplicates do not using aggregate sql in a main select functions?
Priview SQL statement
SELECT * FROM ( select id,hin_id,name,code,valid_date_from,valid_date_to from diaries ) QRSLT WHERE (hin_id = (SELECT NVL(historic_id,id)FROM tutions where id=/*???*/ 59615)) AND NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy')) <= (SELECT NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy'))FROM tutions where id= /*???*/ 59615) AND trunc(valid_date_from) >=(SELECT trunc(valid_date_from)FROM tutions where id= /*???*/ 59615) ;
The result
ID HIN_ID NAME CODE VALID_DATE_TO VALID_DATE
50512 59564 RE YOU 01 07.06.2013 16:32:15 07.06.2013 16:33:28 50513 59564 TT2 02 07.06.2013 16:33:23 07.06.2013 16:33:28 50515 59564 TT2 02 07.06.2013 16:33:28 07.06.2013 16:34:42 50516 59564 STEM 03 07.06.2013 16:34:37 07.06.2013 16:34:42 VALID_DATE_TO & VALID_DATE_FROM information AND
07.06.2013 16:34:42 15.07.2013 10:33:23 In this case, I had doubles of the TT2 50513 entry in a statement identifier select main cant use agregate functions are still possible to exclude this result value by changing only the QLRST a WHERE clause (TRUNC must be here)
THANKS FOR ANY ADVICE!
FDA
Try this,
WITH QRSLT AS (SELECT id, hin_id, name, code, valid_date_from, valid_date_to FROM diaries) SELECT * FROM QRSLT A WHERE (A.hin_id = (SELECT NVL (historic_id, id) FROM tutions WHERE id = /*???*/ 59615)) AND NVL (A.valid_date_to, TO_DATE ('22.12.2999', 'dd.mm.yyyy')) <= (SELECT NVL (valid_date_to, TO_DATE ('22.12.2999', 'dd.mm.yyyy')) FROM tutions WHERE id =/*???*/ 59615) AND TRUNC (A.valid_date_from) >= (SELECT TRUNC (valid_date_from) FROM tutions WHERE id = /*???*/ 59615) AND A.valid_date_from = (SELECT MAX (B.valid_date_from) FROM QRSLT B WHERE A.Name = B.Name AND A.Code = B.Code AND A.hin_id = B.hin_id)
-
Session variable in the WHERE clause of the SQL statement
Hey all,.
I was wonering just if there is a way to set the WHERE clause of the query that the session variable? I have the following so far and have tried to go through a ton of tutorials, but it doesn't seem to work. Is it still possible? I don't know what follows is wrong, but can someone help me with changing the following code, or pointing me to a good tutorial? (I write it with PHP)
$query = "SELECT * from members where user_id = ' $_SESSION ['members']";
Thanks for your help.
$member = "-1";
If (isset($_SESSION['members'])) {}
$member = $_SESSION ['members'];}
$query = "SELECT * from members where user_id = $member; -
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?
Thanks in advance,
Hello
dariyoosh wrote:
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...
The reverse is actually closer to the truth, but we can't really make general statements like that.
SQL is not a language of the proceedings. Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it. In other words, SQL is a language that describes the results you get, not the way to get them.
The optimizer will do everything what he thinks is faster if it does not change the results. If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.
Here is a query looks very much like you posted:
SELECT d.deptno
e.ename, e.sal
OF scott.dept d
LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno
WHERE e.sal > = 3000
ORDER BY d.deptno
;
Output:
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000
20 FORD 3000
20 3000 SCOTT
The scott.dept table contains deptnos 30 and 40; Why are they not in the result set? The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied. All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.
-
Can I use truncated and where clause in the statement even?
Hello guys,.
Can I use truncated with where clause in the same statement.
For ex:
TRUNCATE TABLE my_table WHERE id < 500;
If not, that you recommend me to overtemperature to the level of high water line?
By the way
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Productionselect * from v$version;
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
>
Thank you very much.
Published by: 970992 on 11:14 13.Ara.2012>
Okay I need an increasing amount of space. However, at the same time I want to recover the spaces empty below HWM. So, I need to use less amount of space I am inserting. Therefore, shouldn't use retractable for this?
>
Why waste the effort. Oracle will reuse the space below the HWM when doing inserts. You already said that you insert more lines you delete so all these will be more accustomed to the top.The only time where that oracle may not use space is when the space is too small to be useful. It is documented in the doc, I told you
>
Understanding recoverable unused space
Over time, Update, and Delete on objects within a tablespace can create pockets of empty space that individually are not large enough to be reused for the new data.
>
Most uses of CONTRACTION I've seen are totally useless. If you follow the doc and run the Advisor of segment it will tell you if there is space that can be retrieved and how much. But, even once, for your use even if case will get you will Oracle while you need to reassign the new extensions, then the HWM will just go still higher.If pay you a heavy price in Oracle did a full table scan, update of many blocks from the table, update THE index, impact performance for other users to access the table during the SHRINK and reallocate extensions (maybe even some of the same areas) when you insert more data.
Do not SHRINK unless you know it's necessary.
-
Tuning - using the CASE statement in the WHERE clause of the query
Hi all
My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:
Query:
Description of the table:SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date, os.acctnum, os.avieworigin_refid, COUNT(1) cnt_articleview, SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm FROM TABLE1 os WHERE os.acctnum IS NOT NULL AND os.avieworigin_refid IS NOT NULL AND os.requestdatetime IS NOT NULL AND UPPER(os.success_ind) = 'S' AND CASE WHEN Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 END = 1 AND CASE WHEN Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' THEN 1 END = 1 GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
(Number of lines: approx. > amount 600 000 000)
Explain PlanName Null Type ------------------------------ -------- ------------ ARTICLEID NOT NULL NUMBER(20) USERKEY NUMBER(10) AVIEWORIGIN_REFID VARCHAR2(10) SUCCESS_IND VARCHAR2(2) ENTRY_CREATEDDATE DATE CREATED_BY VARCHAR2(10) FILENUMBER NUMBER(10) LINENUMBER NUMBER(10) ACCTNUM VARCHAR2(10) AUTOCOMPLETEDTERM NUMBER(2) REQUESTDATETIME VARCHAR2(19)
Published by: Chaitanya on June 9, 2011 02:44SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2224314832 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| |* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| ---------------------------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN 'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL' AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
Published by: Chaitanya on June 9, 2011 02:47When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.
BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
Are compare us like with like? -
How to set SQL that contains 'in' where clause in VO?
I don't want to set "in" would adopt a kind of programatical in VO as below. I want to use a method declariable to set in the clause using bindings varaible.
It can be implemented?
private String getInClauseWithParamNames(List termCodes) { //logic to form the in clause with multiple bind variables StringBuffer inClause = new StringBuffer(); if(termCodes !=null){ for (int i = 1; i < termCodes.size() + 1; i++) { inClause.append(":termC" + (i)); if (i < termCodes.size()) { inClause.append(","); } } } return inClause.toString(); } public Row[] getYardFixedSlots(List termCodes) { if(termCodes != null && !termCodes.isEmpty()){ String inClause = getInClauseWithParamNames(termCodes); //setting the where cluase to use the generated in clause this.setWhereClause("YardFixedSlot.TERMINAL_C in (" + inClause + ")"); ////clearing all existing where clause params if any this.setWhereClauseParams(null); if(getVariableManager() !=null){ this.getVariableManager().clearVariables(); } //setting values for all bind variables one by one in the in clause for (int i = 0; i < termCodes.size(); i++) { //defining the named bind variables programatically this.defineNamedWhereClauseParam("termC" + (i + 1), null, null); //setting the value for each named bind variable this.setNamedWhereClauseParam("termC" + (i + 1), termCodes.get(i)); } this.setRangeSize(-1); //executing the query this.executeQuery(); } //returning the rows from query result return this.getAllRowsInRange(); }
You can only use the link as a parameter to the in clause. You must divide the string inside the binding variable. Sample can be found at decompilation binary ADF: using bind variable for SQL statements with the paragraph
Timo
-
using case when statement or decode unfavorable in where clause
Hi the gems...
I have a problem in the following query...
I try to use when case statement in where clause of a select query.
Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when ' > ' = ' > ' then ' cr.salary > 5000')
When ' > ' = ' < ' then ' cr.salary < 5000'
When ' > ' = '=' and then 'cr.salary = 5000'
Another null
(end);
the expression in the when clause of the statement of the case, when comes from HQ and according to the choice I have to make the where clause.
That is why, for the execution of the query, I put ' > ' in this place.
If the original query will look like this (for reference):
Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when variable = ' > ' then ' cr.salary > 5000')
When the variable = ' < ' then ' cr.salary < 5000'
When the variable = '=' and then 'cr.salary = 5000'
Another null
(end);
so, in a real case, if the user selects ' > ' then the filter will be ' where cr.salary > 5000.
If the user selects ' < ' then the filter will be ' where cr.salary < 5000.
If the user selects '=', then the filter will be 'where cr.salary = 5000 '.
but I get the error "ORA 00920:invalid relational operator.
Help, please... Thanks in advance...Hello
select cr.customer_name || ' - ' ||cr.customer_number as cust_name, cr.salary as salary from customer_details cr where ( v_variable = 'bigger' and cr.salary > 5000 ) or ( v_variable = 'less' and cr.salary < 5000 ) or ( v_variable = 'eq' and cr.salary = 5000 )
Published by: user6806750 on 22.12.2011 14:56
For some reason that I can't write in sql "<', '="">", "=".',>
Maybe you are looking for
-
I get sent a lot of pdf on email for my ipad. They come to the top in the form of images on my email so I can only save pictures no ibooks. Is far from stop this? If so, how? also can you seal my pdf then one both of ibooks for and by e-mail. IM on t
-
Satellite M55 - PCI modem and Ethernet controller continue missing
Hi all I got this Satellite M55 quite a few years and until now it works really not too bad for me apart from a few minor errors here and there...Just recently, I sometimes have some hard to connect to wireless internet.It could always be connected o
-
His impression back in front. I see how to resolve this problem in Windows 7, but there seems to be no option in HP utility on the mac; Paper handling has only "Tray Lock" and "Tray by default". 5.23.4 HP utility
-
Recovery of Active directory on a domain controller
Nice day We operate a windows 2008 R2 server. At one point, the server has begun to restart and later was not log. One of the problems is that we have only created a domian controller and there is no backup. Now we've managed to log on to the compute
-
in OUTLOOK EXPRESS, I can move me is more Inbox files to remove the box. Why?
As indicated in the title. This started after I had moved it, maybe 1000 email, delete. I've since removed the deleted and the problem persists. Most forms of delete not only react. When I drag the file to delete, I have a popup saying basically,