Tuning sql (where order clauses)
Hello
This request is really slow, because it calls the function f to each line (table1 and table2 may have more than 10000 lines)
SELECT * FROM table1 t1 inner join tabl2 t2.............. WHERE where_clause_1 AND where_clause_2 AND f(t1.a, t2.a) = 'Y'
Returns 20 lines
Howerver, this query is much faster
SELECT * FROM table1 t1 inner join tabl2 t2.............. WHERE where_clause_1 AND where_clause_2 -- AND f(t1.a, t2.a) = 'Y'
Returns 24 ranks
I try that, but it is too slow:
SELECT * FROM ( SELECT ... FROM table1 t1 inner join tabl2 t2.............. WHERE where_clause_1 AND where_clause_2 ) WHERE f(t1_a, t2_a) = 'Y'
I would like to SELECT by where_clause_1 filter then where_clause_2 and finally the function call.
How can I do?
Thank you!
- SELECT * FROM)
- SELECT / * + NO_MERGE * /... THE T1 from table1 inner join t2 tabl2...
- WHERE where_clause_1
- AND where_clause_2
- )
- WHERE f (t1_a, t2_a) = 'Y '.
Indicates tips NO_MERGE optimizer outer query not combine and query the view of inline in a unique.
Tags: Database
Similar Questions
-
need to sql where condition evaluates to null
Hello
I have a branch_master and I am from the following sql querry
Select * from branch_master where branch_code =: p3_branch_code
Here, if I give a null value for: p3_branch_code, querry must return all the branch_code and the details. Incase if I give a particular value as "acts".
It must then return only the rows where the branch_code has value "acts".
Otherwise, if the value of the condition is null then querry should ignore the condition itself. Any help is appreciated
your
Dr.s.RaghuThe easiest sollution is
select * from branch_master where branch_code = nvl(:p3_branch_code,branch_code)
but based on your index, you may need to do a SQL function returning a query and dynamically add the where the clause.
Kofi -
Hello
The goal for the following statement is so that it can be created as a point of view, but it takes 45 minutes minimum to complete. He returned about 200 000 lines and will gradually increase approximately 1,000 lines a day. Please bear with me, I couldn't get the output autotrace and dbms_xplan.display_cursor, because it takes ages to run. I've included output from v$ sql sql instead, hope this helps.
Database version: 10.2.0.1
Here are the coded sql statement:
Here is the output of the explain plan:select tbl_4.col1, tbl_1.col2, tbl_1.col3, tbl_1.col4, tbl_5.col5, tbl_1.col6, tbl_1.col7, tbl_2.col8, tbl_2.col9, tbl_2.col10, tbl_2.col11, tbl_2.col12, tbl_3.col13, substr(tbl_6.col14, 1, 2), substr(tbl_6.col14, 4, 10), a.number_of_sales, decode (tbl_1.year, 99, 1999, 00, 2000, 98,1998), NVL2(tbl_7.col16, 'Yes', 'None'), NVL2(tbl_8.col17, tbl_8.col1, 'N/A'), NVL2(tbl_8.col18, tbl_8.col1, 'N'), NVL2(tbl_8.col19, tbl_8.col1, 'N'), NVL2(tbl_8.col20, tbl_8.col1, 'N'), tbl_6.col21 from tbl_1 join tbl_2 on (tbl_2.guid = tbl_1.guid) join tbl_3 on (tbl_3.guid = tbl_1.guid) join tbl_5 on (tbl_5.guid = tbl_1.guid) join tbl_6 on (tbl_6.guid = tbl_1.guid) join (select prod, number_of_sales from tbl_1 where prod IN (select guid from tbl_6) MODEL PARTITION BY (country) DIMENSION BY (prod, year) MEASURES (prod as number_of_sales) IGNORE NAV UNIQUE DIMENSION RULES UPDATE SEQUENTIAL ORDER ( number_of_sales[ANY, ANY] = CASE WHEN count(number_of_sales)[ANY, '1999'] > 0 THEN count(number_of_sales)[ANY, '1999'] ELSE (CASE WHEN count(number_of_sales)[ANY, '2000'] > 0 THEN count(number_of_sales)[ANY, '2000'] ELSE (CASE WHEN count(number_of_sales)[ANY, '1998'] > 0 THEN count(number_of_sales)[ANY, '1998'] ELSE 0 END) END) END ));a on (a.prod = tbl_1.prod) left outer join tbl_7 on (tbl_7.guid = tbl_1.guid) left outer join tbl_8 on (tbl_8.guid = tbl_1.guid) left outer join tbl_4 on (tbl_4.col22 = tbl_1.col23);
Here is the optimizer settings:PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- Plan hash value: 2231252653 --------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | --------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 60357 | 29M| | 25428 (2)| 00:05:06 | |* 1 | HASH JOIN RIGHT OUTER | | 60357 | 29M| | 25428 (2)| 00:05:06 | | 2 | TABLE ACCESS FULL | TBL_8 | 727 | 53798 | | 6 (0)| 00:00:01 | |* 3 | HASH JOIN RIGHT OUTER | | 60357 | 25M| | 25420 (2)| 00:05:06 | | 4 | TABLE ACCESS FULL | TBL_4 | 102 | 7854 | | 3 (0)| 00:00:01 | |* 5 | HASH JOIN | | 60357 | 20M| 17M| 25415 (2)| 00:05:05 | PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- |* 6 | HASH JOIN | | 60742 | 16M| 15M| 21282 (2)| 00:04:16 | |* 7 | HASH JOIN | | 63196 | 15M| 14M| 19152 (2)| 00:03:50 | |* 8 | HASH JOIN | | 66797 | 13M| 5696K| 16578 (2)| 00:03:19 | | 9 | VIEW | | 176K| 3619K| | 6779 (2)| 00:01:22 | | 10 | BUFFER SORT | | 176K| 15M| | | | | 11 | SQL MODEL ORDERED | | 176K| 15M| | | | |* 12 | HASH JOIN | | 176K| 15M| 6152K| 6779 (2)| 00:01:22 | | 13 | INDEX FAST FULL SCAN| TBL_6_PK | 128K| 4643K| | 214 (2)| 00:00:03 | | 14 | TABLE ACCESS FULL | TBL_1 | 466K| 25M| | 4701 (2)| 00:00:57 | |* 15 | HASH JOIN RIGHT OUTER | | 176K| 32M| | 7814 (2)| 00:01:34 | | 16 | TABLE ACCESS FULL | TBL_7 | 467 | 19614 | | 3 (0)| 00:00:01 | PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- |* 17 | HASH JOIN | | 176K| 25M| 7536K| 7808 (2)| 00:01:34 | | 18 | TABLE ACCESS FULL | TBL_6 | 128K| 6023K| | 225 (3)| 00:00:03 | | 19 | TABLE ACCESS FULL | TBL_1 | 466K| 44M| | 4701 (2)| 00:00:57 | | 20 | TABLE ACCESS FULL | TBL_3 | 321K| 12M| | 1059 (3)| 00:00:13 | | 21 | TABLE ACCESS FULL | TBL_5 | 326K| 12M| | 523 (3)| 00:00:07 | | 22 | TABLE ACCESS FULL | TBL_2 | 337K| 22M| | 1919 (3)| 00:00:24 | --------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- 1 - access("TBL_8"."GUID"(+)="TBL_1"."GUID") 3 - access("TBL_4"."COL22"(+)="TBL_1"."COL23") 5 - access("TBL_2"."GUID"="TBL_1"."GUID") 6 - access("TBL_5"."GUID"="TBL_1"."GUID") 7 - access("TBL_3"."GUID"="TBL_1"."GUID") 8 - access("A"."PROD"="TBL_1"."PROD") 12 - access("GUID"="GUID") 15 - access("TBL_7"."GUID"(+)="TBL_1"."GUID") 17 - access("TBL_6"."GUID"="TBL_1"."GUID")
Here is the TKProf output:NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_dynamic_sampling integer 2 optimizer_features_enable string 10.2.0.1 optimizer_index_caching integer 0 optimizer_index_cost_adj integer 100 optimizer_mode string ALL_ROWS optimizer_secure_view_merging boolean TRUE db_file_multiblock_read_count integer 16 db_block_size integer 8192 cursor_sharing string EXACT SNAME PNAME PVAL1 PVAL2 -------------------- -------------------- ---------- -------------------- SYSSTATS_INFO STATUS COMPLETED SYSSTATS_INFO DSTART 08-30-2005 15:04 SYSSTATS_INFO DSTOP 08-30-2005 15:04 SYSSTATS_INFO FLAGS 1 SYSSTATS_MAIN CPUSPEEDNW 484.974958 SYSSTATS_MAIN IOSEEKTIM 10 SYSSTATS_MAIN IOTFRSPEED 4096 SYSSTATS_MAIN SREADTIM SYSSTATS_MAIN MREADTIM SYSSTATS_MAIN CPUSPEED SYSSTATS_MAIN MBRC SNAME PNAME PVAL1 PVAL2 -------------------- -------------------- ---------- -------------------- SYSSTATS_MAIN MAXTHR SYSSTATS_MAIN SLAVETHR
Here is the output from v$ sqlcall count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.48 0.52 10 48 192 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 4112 87.79 1099.84 3890789 61207 2 205504 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4114 88.28 1100.36 3890799 61255 194 205504 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 72 Rows Row Source Operation ------- --------------------------------------------------- 205504 HASH JOIN RIGHT OUTER (cr=61207 pr=3890789 pw=3336846 time=1099316224 us) 731 TABLE ACCESS FULL TBL_8 (cr=23 pr=11 pw=0 time=11508 us) 205504 HASH JOIN RIGHT OUTER (cr=61184 pr=3890778 pw=3336846 time=1098446711 us) 102 TABLE ACCESS FULL TBL_4 (cr=7 pr=6 pw=0 time=10685 us) 205504 HASH JOIN (cr=61177 pr=3890772 pw=3336846 time=1097406100 us) 205504 HASH JOIN (cr=52309 pr=3876731 pw=3331582 time=1092251311 us) 205504 HASH JOIN (cr=49818 pr=3872092 pw=3327095 time=1088296724 us) 205504 HASH JOIN (cr=44805 pr=3862788 pw=3322741 time=1083430636 us) 205504 VIEW (cr=22340 pr=3824447 pw=3312710 time=1064542304 us) 205504 BUFFER SORT (cr=22340 pr=3824447 pw=3312710 time=1064131291 us) 205504 SQL MODEL ORDERED (cr=22340 pr=3823920 pw=3312183 time=79100422 us) 205504 HASH JOIN (cr=22340 pr=24845 pw=3829 time=22189967 us) 135074 INDEX FAST FULL SCAN TBL_6_PK (cr=1011 pr=869 pw=0 time=955438 us)(object id 103575) 469544 TABLE ACCESS FULL TBL_1 (cr=21329 pr=17067 pw=0 time=12229819 us) 205504 HASH JOIN RIGHT OUTER (cr=22465 pr=34519 pw=6209 time=18445327 us) 497 TABLE ACCESS FULL TBL_7 (cr=7 pr=3 pw=0 time=15547 us) 205504 HASH JOIN (cr=22458 pr=34516 pw=6209 time=17560031 us) 135074 TABLE ACCESS FULL TBL_6 (cr=1082 pr=1059 pw=0 time=157502 us) 469544 TABLE ACCESS FULL TBL_1 (cr=21376 pr=16734 pw=0 time=11749176 us) 341927 TABLE ACCESS FULL TBL_3 (cr=5013 pr=4950 pw=0 time=2080124 us) 341935 TABLE ACCESS FULL TBL_5 (cr=2491 pr=152 pw=0 time=5129098 us) 341932 TABLE ACCESS FULL TBL_2 (cr=8868 pr=8777 pw=0 time=3436425 us)
SQL_TEXT select tbl_4… SQL_FULLTEXT SQL_ID bh7z3jzt6vw06 SHARABLE_MEM 66824 PERSISTENT_MEM 25756 RUNTIME_MEM 23808 SORTS 1 LOADED_VERSIONS 1 OPEN_VERSIONS 1 USERS_OPENING 1 FETCHES 1 EXECUTIONS 1 PX_SERVERS_EXECUTIONS 0 END_OF_FETCH_COUNT 0 USERS_EXECUTING 1 LOADS 1 FIRST_LOAD_TIME 2009-08-14/15:59:08 INVALIDATIONS 0 PARSE_CALLS 1 DISK_READS 3905090 DIRECT_WRITES 3340053 BUFFER_GETS 62290 APPLICATION_WAIT_TIME 0 CONCURRENCY_WAIT_TIME 0 CLUSTER_WAIT_TIME 0 USER_IO_WAIT_TIME 1042926858 PLSQL_EXEC_TIME 0 JAVA_EXEC_TIME 0 ROWS_PROCESSED 50 COMMAND_TYPE 3 OPTIMIZER_MODE ALL_ROWS OPTIMIZER_COST 25428 OPTIMIZER_ENV E289FB....... OPTIMIZER_ENV_HASH_VALUE 1151412318 PARSING_USER_ID 72 PARSING_SCHEMA_ID 72 PARSING_SCHEMA_NAME DATA KEPT_VERSIONS 0 ADDRESS 569F083C TYPE_CHK_HEAP 00 HASH_VALUE 4067291142 OLD_HASH_VALUE 1777942244 PLAN_HASH_VALUE 2231252653 CHILD_NUMBER 0 SERVICE SYS$USERS SERVICE_HASH 0 MODULE SQL Developer MODULE_HASH 0 ACTION ACTION_HASH 0 SERIALIZABLE_ABORTS 0 OUTLINE_CATEGORY CPU_TIME 81093819 ELAPSED_TIME 1122285962 OUTLINE_SID CHILD_ADDRESS 52541620 SQLTYPE 6 REMOTE N OBJECT_STATUS VALID LITERAL_HASH_VALUE 0 LAST_LOAD_TIME 2009-08-14/15:59:08 IS_OBSOLETE N CHILD_LATCH 3 SQL_PROFILE PROGRAM_ID 101200 PROGRAM_LINE# 2 EXACT_MATCHING_SIGNATURE 4.3484E+18 FORCE_MATCHING_SIGNATURE 1.5863E+19 LAST_ACTIVE_TIME 14-AUG-09 BIND_DATA
There is a large gap between the time cpu and elapsed time. So a lot of time - more than 1000 seconds of 1100 seconds in total - were spent waiting. Please repeat track/tkprof step you took, but this time include the record of the expectations. You can do, for example, by launching:
alter session set events '10046 trace name context forever, level 8'
I think for now, is that your PGA is undersized for this query, because the time is especially dedicated to step "BUFFER FATE." If the report of tkprof including wait, reveals a lot of 'direct path read temp' and 'direct path write temp', then we know for sure.
Kind regards
Rob. -
When installing UCCE I use the ICMDBA to create the base of data but get this error:
"The sorting order of SQL Server on this computer is not binary. You can't go any further.
Anyone know how you can change the SQL sort order?
Hello
To change the SQL Server "Binary order", you will need to reinstall SQL Server and select 'Custom' config Binary order (Latin1_General) for installation.
Follow the instructions in this link:
See Chapter 10. This installation of SQL procedure is valid for all IPCC Enterprise versions in SQL Server 2000.
Hope this helps,
Juan Luis
-
Tuning sql of a product to the seller without changing the sql statement
Hello
We have a product of the provider that generates the SQL statement. For a query, we get the answer in 15 seconds. But users are asking if we can bring it back to 5 seconds. Limitation is the query can not be changed. He used about 10 to 12 tables and bit complex query.
What kind of options could be evaluated if we are to improve the performance of a query (not sure if she could never be reduced to 5 seconds)
without making any change to the query.
Database Version: Oracle 10.2.0.4
Thank you
DelphineHello
http://www.Oracle-base.com/articles/10G/AutomaticSQLTuning10g.php
your software is enterprise or standard?
Tuning Pack & pack diagnosis are extra cost option with the standard edition.
& the useful note * automatic SQL Tuning - SQL [271196.1 ID] profiles *.
http://www.Oracle.com/us/corporate/pricing/technology-price-list-070617.PDF
Thank you
Published by: CKPT November 5, 2010 11:12
-
Does anyone know how or where to enter in the ORDER BY clause when you use a SQL data source in a load rule? I prefer to do the classification in the State of charge rather than create a view on the side of the DB for this if possible.
According to the documentation "box of the SQL statement in Open SQL Data Sources dialog box provides Select, From, and where areas of text that helps you write SQL queries." You can specify multiple data sources, filter the display of folders and specify how the records displayed in the data editor Prep are classified and grouped. "but I have not found anywhere where you can order or group data. I don't need to be able to group data I want to just be able to control my data to make the most effective possible charging process.
I sort the data by inserting into the table of load, but Oracle is not necessarily insert the records in the table according to their order when you go.
We're currently on 11.1.1.3 Essbase and Oracle 11 g.
Any help is greatly apprecied.Just nail it on your WHERE clause in the area WHERE the. I think that you can even stick the entire statement (under the keyword "SELECT") within the area of SELECTION.
-
Setting of outsourcing work is not for a SQL Where clause
Im trying to outsource the WHERE SQL clause of a snapshot data (connecting to Siebel DB) and specify where clause in the run profile that does not work.
Snapshot of research: Select the name of siebel.s_org_ext
Parameter of outsourcing: where_clause_sql
Run the content of the profile:
phase. Phase1.snapshot.clt.where_clause_sql = name = "ABC0009".
#phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
The above parameter retrieves all the records in the table. Below the profile execution retrieves just this record that seems to work fine.
Run the content of the profile:
phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
I want to outsource only where clause as there are many SQL and they are huge to maintain in the run profile.
I have attached a doco with screenshots that will help to understand more.
Hello
You must BE
-Choose "Select table or view" in the table of the snapshot Wizard selection page
&
-Use outsourced where clause
OR
-Choose "SQL" in the snapshot table selection wizard page.
&
-Outsourced use SQL snapshot
You can't mix and match options.
Kind regards
Nick
-
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)
-
dynamic logic in SQL WHERE clause based on the value of the ELEMENT
Hello
I have a report based on the following SQL query.
Thank youselect dept_no, dept_name, dept_loc from dept where dept_loc = :P1_DEPT_LOC // If P1_DEPT_LOC is not null, I want the WHERE clause and IF P1_DEPT_LOC is null, then I don't need the WHERE clause. // how can I build this logic in same SQL
Deepak
Published by: Deepak_J on March 11, 2010 16:37where: P1_DEPT_LOC IS NULL or dept_loc =: P1_DEPT_LOC
If dept_loc is not null better would be
where dept_loc = coalesce(:P1_DEPT_LOC,dept_loc)
-
case in PL/SQL where clause statement
- Hello
- I have a research procedure where the user can search on the city, street, zip code.
- I need meet the 6 different combinations as I don't know what value the user will pass.
- It should be checked if the user passes the value or not, and then look on values passed.
- But the procedure below is out.it the slightest mistake can be transformed with if-then-else, but case statement seems much cleaner in the code.
- procedure searchaddress (pc_town IN SEARCHADDRESS. CITY % TYPE,
pc_street IN SEARCHADDRESS. TYPICAL STREET %,
pc_postcode IN SEARCHADDRESS. POSTCODE % TYPE,
pResultSet to ref_cursor) as
Start
Open the pResultset for
Select searchaddress_pk from searchaddress
where
case
When pc_town is null then ((street = pc_street) and (ZipCode = pc_postcode))
When pc_street is null then ((town = pc_town) and (ZipCode = pc_postcode))
When pc_postcode is null then ((town = pc_town) and (street = pc_street))
When pc_town is null and pc_street is null then (postal code = pc_postcode)
When pc_street is null and pc_postcode is null then (city = pc_town)
When pc_town is null and pc_postcode is null then (street = pc_street)
end
end searchaddress;
Thank you
CenterB
A basic concept that is important to understand - sliders aren't 'sets of results' (sets of data in memory). A cursor is a series of executable steps (see plans run to cursor). It's like a program. An extraction run the program and output data. In general, which is repeated until the cursor (aka program) is no longer found the corresponding lines.
A ref cursor is a pointer or a handle for a such slider, passed to a caller, allowing the appellant to interface directly with this slider/program.
The slider more effective to create a search would be one without superfluous code and predicates and filters. Consider the following approach - a beefier PL/SQL procedure, do not try and play little tricks with SQL predicates in an attempt to create one (and probably not optimal) SQL.
(not tested/compiled code)
create or replace procedure SearchAddress( town IN SEARCHADDRESS.TOWN%TYPE, street IN SEARCHADDRESS.STREET%TYPE, postcode IN SEARCHADDRESS.POSTCODE%TYPE, refCur out ref_cursor ) is curHandle integer; res integer; searchSQL varchar2(1000); begin -- create base query searchSQL := 'select searchaddress_pk from searchaddress where 1 = 1 '; -- add dynamic predicates as needed if town is not null then searchSQL := searchSQL || 'and town = :town'; end if; if street is not null then searchSQL := searchSQL || ' and street = :street'; end if; if postcode is not null then searchSQL := searchSQL || ' and postcode = :postcode'; end if; -- create a DBMS_SQL cursor curHandle := DBMS_SQL.open_cursor; DBMS_SQL.parse( curHandle, searchSQL, DBMS_SQL.NATIVE ); -- bind the dynamic bind variables added as predicate values if town is not null then DBMS_SQL.Bind_Variable( curHandle, 'town', town ); end if; if street is not null then DBMS_SQL.Bind_Variable( curHandle, 'street', street ); end if; if postcode is not null then DBMS_SQL.Bind_Variable( curHandle, 'postcode', postcode ); end if; -- execute cursor (to create the cursor program) and pass it back as a ref cursor res := DBMS_SQL.Execute( curHandle ); refCur := DBMS_SQL.To_RefCursor( curHandle ); end;
-
Simple conditional SQL WHERE Clause with two Subselects
Hi SQL Experts,
I need some quick help with a query.
It is a ' select ' for a data source object repository phyiscal table OBI.
So, I can't put in PL/SQL or in stored procedures. I just need
have two conditions / selects different according to the user's role (this information comes
of the session).
The above does not work:-ORA00905. 00000 - 'lack the key word'
SELECT OFFICENO FROM orgunit
WHERE
BOX WHEN "SESSION_VARIABLE' LIKE '% globalmanager %' THEN
ASSIGNEDOFFICES =
(
SELECT DISTINCT ASSIGNEDOFFICES
FROM USERSTABLE INNER JOIN orgunit WE
OrgUnit. KEY = USERSTABLE. OFFICE
WHERE USERSTABLE. USERNAME ='VALUEOF (NQ_SESSION. THE USER)"
)
ON THE OTHER
OFFICENO =
(
SELECT DISTINCT USERSTABLE OFFICENO
INNER JOIN orgunit WE
OrgUnit. KEY = USERSTABLE. OFFICE
WHERE USERSTABLE. USERNAME ='VALUEOF (NQ_SESSION. THE USER)"
)
END;Can anyone help?
Hello
I can't tell what you want to do by looking at the code that do not do. Maybe:
SELECT officeno
For orgunit
WHERE (session_variable LIKE '% globalmanager %'
AND IN assignedofficies
(
SELECT assignedoffices
UserTable U1
JOIN orgunit o1 ON o1.officekey = u1.officekey
WHERE u1.username = ' VALUEOF (NQ_SESSION. THE USER)"
)
)
OR (NVL (session_variable
, '?'
) NOT LIKE '% globalmanager % '.
AND IN officeno
(
SELECT officeno
Of u2 usertable
JOIN orgunit o2 ON o2.officekey = u2.officekey
WHERE u2.username = ' VALUEOF (NQ_SESSION. THE USER)"
)
)
;
There might be a simpler and more efficient way in function your tables and your limit.
The condition u2.username = ' VALUEOF (NQ_SESSION. The USER) "almost certainly not what you really want.
.
Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
[SQL] Where the problem of the clause with subqueries
Hello
I am writing a query for an apex application where I have a field (P47_UNNR) for filtering. In my where clause I try to do this:
... AND IN qo.pk_id
CASE
WHEN: P47_UNNR IS NULL
THEN
(SELECT pk_id FROM quote_orders)
ON THE OTHER
(SELECT QOR. FK_QUOTE_ORDER_ID
OF QUOTE_ORDER_RIDS QOR
JOIN THE
RID RID
WE RID. PK_ID = QOR. FK_RID_ID
WHERE RID.NAME LIKE: P47_UNNR)
END
...
But it gives an error "ORA-01427: einreihig subquery returns more than one line.
I tried several ways to work around this problem, but don't seem to be able to do. Does anyone have a suggestion on how to fix this?Try something like...
AND qo.pk_id IN (SELECT pk_id FROM quote_orders WHERE :47_UNNR IS NULL UNION ALL SELECT QOR.FK_QUOTE_ORDER_ID FROM QUOTE_ORDER_RIDS QOR JOIN RIDS RID ON RID.PK_ID = QOR.FK_RID_ID WHERE RID.NAME LIKE :P47_UNNR )
-
Problem with the creation of date range with PL/SQL WHERE clause
Hello, everyone:
I'm unable to develop and the SQL statement to filter records today and seven days back. My condition is as follows:
I think I'm to mess with the (to_char (ALM_OG_ACTIVITY_DATE, ' mm/dd/yyyy ' ")) statement.from wsualumni.wsu_online_giving_table --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7 where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7 and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1';
The actual code is below to:
Resultsset serveroutput ON SIZE 1000000 set heading off set feedback off set trimspool off set echo off set pagesize 0 DECLARE v_data_line_hdr varchar2(1000); v_data_file varchar2(80); v_sch_code varchar2(10); v_instance_name varchar2(10); ws_path payroll.pybutfl.pybutfl_utl_file_path%TYPE; v_data_line VARCHAR2 (4000) := NULL; fhandle_o UTL_FILE.file_type; v_line_count NUMBER := 0; v_selected_count NUMBER := 0; v_error_count NUMBER := 0; v_written_count NUMBER := 0; v_error_text VARCHAR2 (50) := ' Unable to write the line. '; v_errm VARCHAR2 (255); v_sqlerrm VARCHAR2 (255); CURSOR C1 IS select RTRIM ( ALM_OG_ID ||'|'|| NULL ||'|'|| (to_char(ALM_OG_AMOUNT, '999,999.99')) ||'|'|| 'Cash' ||'|'|| 'Credit Card' ||'|'|| (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy')) ||'|'|| ALM_OG_ACCI_CODE ||'|'|| 'On-Line Giving' ||'|'|| 'On-Line giving' ||'|'|| ALM_OG_HONOR_MEM_NAME ||'|'|| NULL ||'|'|| 'Do not post' ||'|'|| 'StandardThankYou' ||'|'|| 'Not Acknowledged' ||'|'|| 'Do not receipt' ||'|'|| NULL ||'|'|| 'Banner Gift Number' ||'|'|| ALM_OG_BANNER_GIFT_NO ||'.'|| ALM_OG_ACCI_CODE ||'|'|| (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy')) ||'|'|| NULL ||'|'|| 'Web ID' ||'|'|| ALM_OG_WEBID ||'|'|| NULL ||'|'|| 'Source' ||'|'|| ALM_OG_CAMPAIGN_CODE ||'|'|| 'On-Line Giving' ) data_line from wsualumni.wsu_online_giving_table --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7 where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7 and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1'; CURSOR C2 IS select RTRIM( 'ConsID' ||'|'|| 'GFImpID' ||'|'|| 'GFTAmt' ||'|'|| 'GFType' ||'|'|| 'GFPayMeth' ||'|'|| 'GFDate' ||'|'|| 'FundID' ||'|'|| 'CAMPID' ||'|'|| 'GFAppeal' ||'|'|| 'GfRef' ||'|'|| 'GfPostDate' ||'|'|| 'GfPostStatus' ||'|'|| 'GfltrCode' ||'|'|| 'GfAck' ||'|'|| 'GfRcpt' ||'|'|| 'GfAttrlmpID00' ||'|'|| 'GfAttrCat00' ||'|'|| 'GfAttrdesc00' ||'|'|| 'GfAttrDate00' ||'|'|| 'GfAttrlmpD01' ||'|'|| 'GfAttrCat01' ||'|'|| 'GfAttrdesc01' ||'|'|| 'GfAttrlmpID02' ||'|'|| 'GfAttrCat02' ||'|'|| 'GfAttrdesc02' ||'|'|| 'GfSubType' ) line_header from DUAL; /**********************************************************************/ /* Main Program Processing */ /**********************************************************************/ BEGIN DBMS_OUTPUT.put_line ('Program Started in wsualumni.wsu_online_giving_online'); IF UTL_FILE.is_open (fhandle_o) THEN UTL_FILE.fclose (fhandle_o); END IF; /* Name The File Here */ v_data_file := ('MED_SCH_' || TO_CHAR(sysdate, 'dd-MON-yyyy') || '_OG_DATA.txt'); SELECT RTRIM (pybutfl_utl_file_path) INTO ws_path FROM payroll.pybutfl; fhandle_o := UTL_FILE.fopen (ws_path, v_data_file, 'w'); DBMS_OUTPUT.put_line ('UTLFILE file for this run is: ' || ws_path||'/'||v_data_file); v_written_count := 0; FOR c2_rec IN C2 LOOP BEGIN v_selected_count := v_selected_count + 1; v_data_line_hdr := rtrim(c2_rec.line_header); UTL_FILE.put_line (fhandle_o, v_data_line_hdr); v_written_count := v_written_count + 1; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (v_error_text); v_error_count := v_error_count + 1; END; END LOOP; FOR c1_rec IN C1 LOOP BEGIN v_selected_count := v_selected_count + 1; v_data_line := rtrim(c1_rec.data_line); UTL_FILE.put_line (fhandle_o, v_data_line); v_written_count := v_written_count + 1; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (v_error_text); v_error_count := v_error_count + 1; END; END LOOP; DBMS_OUTPUT.put_line ('Number of Records Selected: ' || v_selected_count); DBMS_OUTPUT.put_line ('Number of Records Written: ' || v_written_count); IF UTL_FILE.is_open (fhandle_o) THEN UTL_FILE.fclose (fhandle_o); END IF; END; /
ConsID|GFImpID|GFTAmt|GFType|GFPayMeth|GFDate|FundID|CAMPID|GFAppeal|GfRef|GfPostDate|GfPostStatus|GfltrCode|GfAck|GfRcpt|GfAttrlmpID00|GfAttrCat00|GfAttrdesc00|GfAttrDate00|GfAttrlmpD01|GfAttrCat01|GfAttrdesc01|GfAttrlmpID02|GfAttrCat02|GfAttrdesc02|GfSubType 000013505|| 20.00|Cash|Credit Card|06/22/2009|221686|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.221686|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving 000013505|| 20.00|Cash|Credit Card|06/22/2009|770830|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.770830|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving
Hello
The problem is due to the "OR" condition (I did not pay attention to it earlier).
Because of this condition, your query is given beyond 7 days recovery. You need to rewrite the code as:
ALM_OG_CAMPAIGN_CODE in ('MED', 'MED1')
Instead of
and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1';
This will do the magic for you.
Concerning
Asif Momen
http://momendba.blogspot.com -
For UNION in VOImpl SQL WHERE clause
Hey gurus,
I need the ability to add a condition to VOImpl to user_id for two queries in a UNION statement. However, setWhereClause only adds condition at the end of the query. Any suggestions? I tried to make a selection online and could not because of the 'double '.
Thank you
-Scott
Select "Sys" x double where exists)
Select responsibility_name in the fur of fnd_user_responsibility,
fnd_responsibility_tl frt
When user_id = 16448
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = "system administrator")
Union
Select "NoSys" x double where does not exist)
Select responsibility_name in the fur of fnd_user_responsibility,
fnd_responsibility_tl frt
When user_id = 16448
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = "system administrator")You can have the condition at the request of origin itself and in the VOImpl, just switch the setting.
select 'Sys' x from dual where exists ( select responsibility_name from fnd_user_responsibility fur, fnd_responsibility_tl frt where user_id = :1 and frt.responsibility_id = fur.responsibility_id and frt.responsibility_name = 'System Administrator') union select 'NoSys' x from dual where not exists ( select responsibility_name from fnd_user_responsibility fur, fnd_responsibility_tl frt where user_id = :2 and frt.responsibility_id = fur.responsibility_id and frt.responsibility_name = 'System Administrator')
See you soon
Ganesh -
Hi friends,
Reference post https://community.oracle.com/thread/3520158
If the order of processing of a SQL statement is
OF-> WHERE-> GROUP-> GET-> SELECT-> ORDER BY
So why do I get errors in a different order:
See for more information.
(A). all fields are false. FROM a known first.
SQL > SELECT EAEED
2 FROM DEEP FISHING
3. WHERE MODOU > 3
GROUP 4 BY EDDEW
5 HAVE EDEW = 5
6 ORDER BY ERA;
DEEP FISHING
*
ERROR on line 2:
ORA-00942: table or view does not exist
(B) correction OF the identifier clause. [ORDER BY has been checked before WHERE]
SQL > SELECT EAEED
2 FROM EMP
3. WHERE MODOU > 3
GROUP 4 BY EDDEW
5 HAVE EDEW = 5
6 ORDER BY ERA;
ORDER BY ERA
*
ERROR on line 6:
ORA-00904: "ERA": invalid identifier
(C) correction ORDERBY clause. [HAVING been checked before GROUP BY]
SQL > SELECT EAEED
2 FROM EMP
3. WHERE MODOU > 3
GROUP 4 BY EDDEW
5 HAVE EDEW = 5
6 ORDER BY ENAME;
AFTER YOU HAVE EDEW = 5
*
ERROR on line 5:
ORA-00904: "EDEW": invalid identifier
(D). WITH withdrawal clause.
SELECT EAEED
FROM EMP
WHERE MODOU > 3
EDDEW GROUP
-HAVE EDEW = 5
ORDER BY ENAME;
(E) correction Group by
SQL > SELECT EAEED
2 FROM EMP
3. WHERE MODOU > 3
GROUP 4 BY EMPNO
5 WITH EDEW = 5
6 ORDER BY ENAME;
WHERE MODOU > 3
*
ERROR at line 3:
ORA-00904: "MODOU": invalid identifier
(F) fixed WHERE
SQL > SELECT EAEED
2 FROM EMP
3. WHERE deptno <>10
GROUP 4 BY EMPNO
5 WITH EDEW = 5
6 ORDER BY ENAME;
SELECT EAEED
*
ERROR on line 1:
ORA-00904: "EAEED": invalid identifier
(G). SELECT correction
SELECT EMPNO
FROM EMP
WHERE deptno <>10
GROUP BY EMPNO
VIEW count (*) > 1
ORDER BY Empno;
EMPNO
----------
7369
7499
7521
7566
7654
7698
7788
7844
7876
7900
7902
11 selected lines.
This means SQL executed in different order, or there is some reason to get error in that order?
Hello
Kimmy says:
HI Frank and Baris,
Is that means there is a defined order for execution of SQL to oracle but compiling the SQL statement has no order defined by the (FROM, WHERE, GROUP BY) clauses and compilation may give error in any order, and which will compile all first does matter?
Kind regards
The system can choose to compile an SQL statement in any order. I have never seen a case where this order is significant to anyone. (I don't know what is important to you.)
If your code has compile errors, you will get only 1 error message, and the message can be caused by any line of your code. If your SQL statement has 10 lines, and you get an error message referring to line 5, there may be other errors as well. If there is another error, could be on lines 1-4, or it could be on lines 6-10, it could be elsewhere on line 5.
There is a relationship between the clauses in your code and the order in which the code is run. For example, the compiled code corresponding to a condition of a FROM clause join will probably run before the compiled code corresponding to the ORDER byclause of this request. The rules specifying the 'order' can be useful, but should not be taken too literally.
Maybe you are looking for
-
modem restarts when I send an email
When I send an email updated the and try to send it, my internet modem restarts.This does not happen if I use outlook express by using the same email.This happens on my windows 8.1 and computers windows XP.It starts happening a few days ago and I tho
-
SONY TV MODEL KV-XF25M80 WEGA CRT
I have Sony crt tv kv-xf25m80 in good condition. Sometimes her picture disappeared and buzz starts audio and audio channels. Sometimes, he is off on his own with led red flashes 2 times. This problem is intermittent and time varies. When this takes p
-
HelloI just bought the laptop L30 and I tried to install a game and first of all I had to install alcohol, when I installed the portable alcohol off immediately and whenever I turn it on, it turns after on 6seconds and I think it's for security reaso
-
What webcams G25 users use?
HelloI have the same problem (his chipmunk) of audio compression as one of the other users, when I use the 'QuickCam® for Notebooks Pro". I tried to use another device and it worked fine, but it would not clip the thick screen of my G25. Can anyone o
-
How can I get my T6i videos on my mac?
How the hell I get my videos from my T6i on my computer? I have the new software installed, I rebooted my computer. The software seems to work when I open it fine, but when I plug in my camera to my laptop mac nothing happens. It is not the USB (port