SQL query using lot of Temp space
I have sql query which is using lot of temp space , please suggest some ways to reduce this
SELECT A.POSITION_NBR, TO_CHAR(B.EFFDT,'YYYY-MM-DD'), rtrim( A.SEQNO), A.EMPLID, B.REG_REGION, A.MANAGER_ID, A.REPORTS_TO, case when A.POSITION_NBR = A.REPORTS_TO THEN 'POS reports to same position' else 'Positions with multiple Emp' End Case
FROM PS_Z_RPTTO_TBL A, PS_POSITION_DATA B, PS_POSTN_SRCH_QRY B1
WHERE B.POSITION_NBR = B1.POSITION_NBR AND B1.OPRID = 'MP9621Q' AND ( A.POSITION_NBR = B.POSITION_NBR AND ( A.REPORTS_TO = A.POSITION_NBR AND B.EFFDT =
(SELECT MAX(B_ED.EFFDT)
FROM PS_POSITION_DATA B_ED
WHERE B.POSITION_NBR = B_ED.POSITION_NBR) AND A.POSITION_NBR <> '00203392') OR ( B.EFFDT =
(SELECT MAX(B_ED.EFFDT)
FROM PS_POSITION_DATA B_ED
WHERE B.POSITION_NBR = B_ED.POSITION_NBR AND B_ED.EFFDT <= SYSDATE) AND B.MAX_HEAD_COUNT <>
(SELECT Count( C.EMPLID)
FROM PS_Z_RPTTO_TBL C)) ) UNION
SELECT F.POSITION_NBR, TO_CHAR(F.EFFDT,'YYYY-MM-DD'), '', '', F.REG_REGION, '', F.REPORTS_TO, ''
FROM PS_POSITION_DATA F, PS_POSTN_SRCH_QRY F1
WHERE F.POSITION_NBR = F1.POSITION_NBR AND F1.OPRID = 'MP9621Q' AND ( F.EFFDT =
(SELECT MAX(F_ED.EFFDT)
FROM PS_POSITION_DATA F_ED
WHERE F.POSITION_NBR = F_ED.POSITION_NBR AND F_ED.EFFDT <= SYSDATE) AND F.EFF_STATUS = 'A' AND F.DEPTID IN
(SELECT G.DEPTID
FROM PS_DEPT_TBL G
WHERE G.EFFDT =
(SELECT MAX(G_ED.EFFDT)
FROM PS_DEPT_TBL G_ED
WHERE G.SETID = G_ED.SETID AND G.DEPTID = G_ED.DEPTID AND G_ED.EFFDT <= SYSDATE) AND F.REG_REGION = G.SETID AND G.EFF_STATUS = 'I') )
Thanks in Advance
Rajan
use {noformat}<your code here>{noformat} tags to format your code.
I have sql query which is using lot of temp space , please suggest some ways to reduce thisIf your sort_area_size is not set sufficient oracle used temp space for sorting operation. As your code is not readable i cant say much more than this. Check with your DBA if you have to increase the temp space.
Similar Messages
-
Procedure using lot of temp space
Hi all,
DB version is 10.2.0.4. A procedure named xxxx while executing using 10gb of temp tablespace...What are the basic checklist of tuning that procedure...
thanks,
baskar.lhttp://download.oracle.com/docs/cd/B19306_01/server.102/b14211/toc.htm
-
How to obtain the transformed SQL query using SEM_MATCH
Dear all,
Is it possible to get the transformed relational SQL query when using the SEM_MATCH prefix, by querying directly on the database. We are able to obtain the relational SQL query using Joseki/Jena, however this is not the way to go for us. We would like (if possible) to get it straight from the oracle database by logging or something.
Kind regards.
MaxHi Max,
Just to clarify. What SEM_MATCH prefix are you talking about?
A SEM_MATCH based query is indeed a SQL query as SEM_MATCH is a SQL table function. So if you don't want to go through Java APIs or web service endpoint, then running SEM_MATCH directly should give you what you need. Or maybe you just want to see the underlying generated (from SEM_MATCH) SQL query. If that is true, can you please tell us why?
Thanks,
Zhe Wu -
How to determine what's using data store temp space?
How can one determine what's using data store temp space? We are interested to know what structures are occupying space in temp space and if possible what pid/process connected to TimesTen created them.
Also, is there a procedure that will work if temp space is full?
Recently one of our data stores ran of space. We we're unable to run commands like "monitor", "select * from monitor", "select count(*) from my_application_table", etc. These commands failed because they required temp space to run and temp space was full. We killed the application processes, this in turned freed up temp space, then we were able to run these queries.
Ideally, we'd like to have a procedure to figure out what's using temp space when temp space is full.
The other thing we could do is periodically monitor temp space prior to it filling to determine what's using temp space.That was my original thought, but once you click the slider track or thumb, and then enter a value in the text control, the clickTarget on the change event envoked by the change to the bound data (after entering a value in the text control) will be whatever slider element had last been clicked. If you've never clicked the slider, clickTarget=null. But once you've clicked the slider the clickTarget always has a value of "thumb" or "track", regardless of what triggered the change event.
-
Set TIMEOUT on OCCI sql query using ?
Is there a way to set a timeout on a sql query using OCCI ?
OCCI does not provide an API to set timeouts on SQL Queries.
You can use the CREATE PROFILE command and assign resources at
a user level. The restrictions may be applied to memory/resources which
in turn would control the SQL execution time. Please check the
CREATE PROFILE command.
Rgds
Amogh -
Report consuming a lot of temp Space (BIP)
Hi Experts,
I am facing an issue.
Some BIP reports consuming a lot of temp space (5-30 gb temp directory), which is causing service down (BIP, RMS, ReIM and RPM). BIP, RMS, ReIM and RPM are installed on same server.
Please help to troubleshoot this issue.
Thanks in Advanceplz see
Troubleshooting Oracle BI Publisher Enterprise 11g [ID 1387643.1]
Troubleshooting Oracle BI Publisher Enterprise 10g [ID 412232.1] -
GWTDOMAIN using lots of swaps space in WLE 4.2!!!
We are having problem in one our of non- production environments where the GWTDOMAIN is using lots of swap space and not releasing them. It got so bad that the swap space used was 100% and we had to "kill -9" this GWTDOMAIN and bounce it again to to release this space. Is this a known bug and if not what can I do to resolve this problem
or do we need to open a trouble ticket with BEA to fix.
Thank for your help.
Bayo Alege
Senior Analyst, Systems
CIMG
513-723-2954Excessive archivelog generation on an EM12c repository database may mean you are hitting bug 14726136. Please see MOS note 1502370.1. I would suggest filing an SR with support to confirm whether or not you are experiencing this bug; they can help you with some additional analysis.
-
How to find sql query using sqlid
Hi
I am not aware of that sqlid .DBA is saying a particular sqlid is making problem .how to find the particular sql query using sql_id ?Are you aware of modplsql when i executed the query the result is like
DECLARE
rc__ NUMBER;
simple_list__ OWA_UTIL.vc_arr;
complex_list__ OWA_UTIL.vc_arr;
BEGIN
OWA.init_cgi_env (:n__, :nm__, :v__);
HTP.htbuf_len := 84;
NULL;
NULL;
simple_list__ (1) := 'sys.%';
simple_list__ (2) := 'dbms\_%';
simple_list__ (3) := 'utl\_%';
simple_list__ (4) := 'owa\_%';
simple_list__ (5) := 'owa.%';
simple_list__ (6) := 'htp.%';
simple_list__ (7) := 'htf.%';
simple_list__ (8) := 'wpg_docload.%';
IF ((owa_match.match_pattern ('Oly_browse.oly_pattern ',
simple_list__,
complex_list__,
TRUE
THEN
rc__ := 2;
ELSE
NULL;
NULL;
oly_browse.oly_pattern (search_phrase => :search_phrase, --Oly_browse.oly_pattern is package name
btn => :btn,
p_qual => :p_qual,
p_bcat => :p_bcat,
p_stdy => :p_stdy,
p_bloc => :p_bloc,
z => :z
IF (WPG_DOCLOAD.is_file_download)
THEN
rc__ := 1;
WPG_DOCLOAD.get_download_file (:doc_info);
NULL;
NULL;
NULL;
COMMIT;
ELSE
rc__ := 0;
NULL;
NULL;
NULL;
COMMIT;
OWA.get_page (:data__, :ndata__);
END IF;
END IF;
:rc__ := rc__;
END; Edited by: vishnu prakash on Sep 8, 2010 10:16 PM -
SQL query using Group by and Aggregate function
Hi All,
I need your help in writing an SQL query to achieve the following.
Scenario:
I have table with 3 Columns. There are 3 possible values for col3 - Success, Failure & Error.
Now I need a query which can give me the summary counts for distinct values of col3 for each GROUP BY of col1 and col2 values. When there are no values for col3 then it should return ZERO count.
Example Data:
Col1 Col2 Col3
abc 01 success
abc 02 success
abc 01 success
abc 01 Failure
abc 01 Error
abc 02 Failure
abc 03 Error
xyz 07 Failure
Required Output:
c1 c2 s_cnt F_cnt E_cnt (Heading)
abc 01 2 1 1
abc 02 1 1 0
abc 03 0 0 1
xyz 07 0 1 0
s_cnt = Success count; F_cnt = Failure count; E_cnt = Error count
Please note that the output should have 5 columns with col1, col2, group by (col1,col2)count(success), group by (col1,col2)count(failure), group by (col1,col2)count(error)
and where ever there are NO ROWS then it should return ZERO.
Thanks in advance.
Regards,
ShivaHi,
user13015050 wrote:
Thanks TTT. Unfortunately I cannot use this solution because I have huge data for this.T's solution is basically the same as mine. The first 23 lines just simulates your table. Since you actually have a table, you would start with T's line 24:
SELECT col1 c1, col2 c2, SUM(decode(col3, 'success', 1, 0)) s_cnt, ...
user13015050 wrote:Thanks a lot Frank. It helped me out. I just did some changes to this as below and have no issues.
SELECT col1
, col2
, COUNT ( CASE
WHEN col3 = 'SUCCESS'
THEN 1
END
) AS s_cnt
, COUNT ( CASE
WHEN col3 = 'FAILED'
THEN 1
END
) AS f_cnt
, COUNT ( CASE
WHEN col3 = 'ERROR'
THEN 1
END
) AS e_cnt
FROM t1
WHERE c2 in ('PURCHASE','REFUND')
and c4 between to_date('20091031000000','YYYYMMDDHH24MISS') AND to_date('20100131235959','YYYYMMDDHH24MISS')
GROUP BY c1, c2
ORDER BY c1, c2;
Please let me know if you see any issues in this query.It's very hard to read.
This site normally compresses spaces. Whenever you post formatted text (such as queries or results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
Also, post exactly what you're using. The code above is SELECTing col1 and col2, but there's no mention of either in the GROUP BY clause, so I don't believe it's really what you're using.
Other than that, I don't see anything wrong or suspicious in the query. -
Need SQL query using View - Please help
Hi,
I have similar requirement like below.
I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
CREATE OR REPLACE VIEW dept_emp_vw AS
SELECT deptno, empid, 0 AS selected
FROM dept d, emp e
WHERE d.deptno = e.deptnno (+);
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 0
30 103 0
40 104 0
50 <null> 0
Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 1
30 103 1
40 104 0
50 <null> 0
Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
Thanks a lot for the help.Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
E.g.
SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
2 begin
3 DBMS_SESSION.set_context( 'MyVariables', name, value );
4 end;
5 /
Procedure created.
SQL>
SQL>
SQL> create or replace context MyVariables using SetVariable;
Context created.
SQL>
SQL> create or replace view my_funky_weird_view as
2 select
3 e.empno,
4 e.ename,
5 e.job,
6 case e.empno
7 when to_number(sys_context( 'MyVariables', 'empid' )) then
8 0
9 else
10 1
11 end as "SELECTED"
12 from emp e
13 /
View created.
SQL>
SQL> exec SetVariable( 'empid', 7499 )
PL/SQL procedure successfully completed.
SQL>
SQL> select * from session_context where namespace = 'MYVARIABLES';
NAMESPACE ATTRIBUTE VALUE
MYVARIABLES EMPID 7499
SQL>
SQL> select * from my_funky_weird_view order by selected;
EMPNO ENAME JOB SELECTED
7499 ALLEN SALESMAN 0
7521 WARD SALESMAN 1
7566 JONES MANAGER 1
7654 MARTIN SALESMAN 1
7698 BLAKE MANAGER 1
7934 MILLER CLERK 1
7788 SCOTT ANALYST 1
7839 KING PRESIDENT 1
7844 TURNER SALESMAN 1
7876 ADAMS CLERK 1
7900 JAMES CLERK 1
7902 FORD ANALYST 1
7369 SMITH CLERK 1
7782 CLARK MANAGER 1
14 rows selected.
SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined. -
Parameter passing to custom SQL query using PL/SQL FUNCTION
Hi
In order to pass a parameter to the query in custom folder of a business area I created a function and mapped it to the Custome query using Discoverer Desktop. There is no error in mapping as the system does not throw any error. When I am inputting the Parameter for the input values everytime the query doesnot return any rows.
Can anybody help in this regardHi,
I need to take the request Id as input from the user and then fetch only the data pertaining to that requet Id. As a lot of complex joins are involved I need to pass request id as parameter to the custome folder.
The package i greated:
CREATE OR REPLACE PACKAGE SETPARAM
AS
param1 varchar2(25);
param2 varchar2(25);
FUNCTION SET_PARAM1(p1 IN varchar2) RETURN NUMBER ;
FUNCTION GET_PARAM1 RETURN varchar2;
END SETPARAM;
CREATE OR REPLACE PACKAGE BODY SETPARAM AS
FUNCTION SET_PARAM1(p1 IN varchar2) RETURN NUMBER IS
BEGIN
fnd_client_info.set_org_context('138');
param1 := p1;
dbms_output.put_line(param1);
RETURN 1;
END;
FUNCTION GET_PARAM1 RETURN varchar2 AS
BEGIN
RETURN param1;
END;
END SETPARAM;
I registered the set_param1 function as a pl/sql function in discoverer admin.
This function is called on the condition associated with the parameter in Discoverer Desktop when i run the report.
In the custom folder query i have this piece in the where clause
WHERE tnfo.request_id = NVL(APPS.SETPARAM.GET_PARAM1,7383588)
And everytime i get the data pertaining to request id =7383588,
Please suggest where i went wrong
thanks
Ashwini -
Can Portal Report from SQL Query use where column IN (:bind_variable)
I would like to create a portal report from sql query with IN (:bind_variable) in the where clause. The idea is that the user would enter comma-separated or comma-quote-separated values for the bind_variable. I have tried this several ways but nothing seems to work. Can this be done?
TrentonHi,
Which version of portal are you using. This is a bug. It has been fixed in 30984.
Thanks,
Sharmila -
Sql query using LIKE is very slow
Hi,
I am running SQL query with LIKE on two table with more than two million records on oracle 10g and sun solaris OS. Does anybody have any idea or alternative to improve this query?
it will never use index because i m using LIKE '%xyz%'. I Have posted query below
PROCEDURE order_search
v_search_type_in IN VARCHAR2
,v_search_value1_in IN VARCHAR2 DEFAULT 'NONE'
,v_search_value2_in IN VARCHAR2 DEFAULT 'NONE'
,v_group_id_in IN bcf_groups.group_id%TYPE DEFAULT 0
,v_open_in IN NUMBER DEFAULT 0
,v_requested_in IN NUMBER DEFAULT 0
,v_cancelled_in IN NUMBER DEFAULT 0
,v_closed_in IN NUMBER DEFAULT 0
,v_employee_id_in IN sxweb00.customer.customer_id%TYPE DEFAULT 0
,outcursor IN OUT FulfillmentCurType
IS
v_status_code NUMBER;
v_upper_search_value1 VARCHAR2(500);
v_lower_search_value1 VARCHAR2(500);
v_open_status VARCHAR2(10);
v_closed_status VARCHAR2(10);
v_cancelled_status VARCHAR2(10);
v_requested_status VARCHAR2(10);
v_group_for_search bcf_groups.group_id%TYPE;
v_sql_select VARCHAR2(4000);
v_sql_from VARCHAR2(4000);
v_sql_where VARCHAR2(4000);
v_sql_order_by VARCHAR2(4000);
v_group_where VARCHAR2(100);
v_status_where VARCHAR2(500);
BEGIN
IF v_open_in = 1 THEN
v_open_status := 'OPEN';
END IF;
IF v_closed_in = 1 THEN
v_closed_status := 'CLOSED';
END IF;
IF v_cancelled_in = 1 THEN
v_cancelled_status := 'CANCELLED';
END IF;
IF v_requested_in = 1 THEN
v_requested_status := 'REQUESTED';
END IF;
IF UPPER(v_search_type_in) = 'GROUP'
THEN
v_group_for_search := v_search_value1_in;
ELSE
v_group_for_search := v_group_id_in;
END IF;
-- This is the select statement used for all search types
v_sql_select := ' '
|| 'po.order_id order_id '
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null) first_location '
|| ',TO_CHAR(po.order_date, ''mm/dd/yyyy'') order_date '
|| ',' || v_group_for_search || ' group_id '
|| ',TRIM(TO_CHAR(bcf_fulfillment.get_shipping_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_tax_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_subtotal(po.order_id,' || v_group_for_search || ') ,''$999,999,999,999,999,990.99'')) total '
|| ',bcf_fulfillment.get_billing_name (po.customer_id) billing_name '
|| ',bcf_fulfillment.get_open_and_assigned_count(po.order_id,' || v_group_for_search || ') open_and_assigned_count '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') divisions '
|| ',bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ' ) division_count '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ') picker_name '
|| ',bcf_fulfillment.get_picker_count (po.order_id,' || v_group_for_search || ') picker_count '
|| ',bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search || ') order_status '
|| ',po.customer_id customer_id '
-- IF there is only one unique picker then that means there are no unassigned or NULL pickers
-- therefore by default the checkbox should not be selected else the count picker_count is
-- 0 or > 1 meaning that at least one line item has an unassigned employee_id and by default
-- the checkbox should be selected
|| ',DECODE(bcf_fulfillment.get_picker_count(po.order_id,' || v_group_for_search || '),1 ,0,1) print_cb '
|| ',bcf_fulfillment.get_fulfillment_codes(po.order_id,' || v_group_for_search || ') fulfillment_types '
|| ',bcf_fulfillment.has_group_been_reassigned(po.order_id,' || v_group_for_search || ') group_reassigned_flag '
|| ',bcf_fulfillment.get_chain_codes(po.order_id,' || v_group_for_search || ') chain_codes '
|| ',po.status_id order_status_id '
|| ',bcf_fulfillment.get_viewed_by_picker_flag(po.order_id,' || v_group_for_search || ') viewed_by_picker_flag '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ', ''N'') pickers_without_unassigned '
|| ',bcf_fulfillment.get_group_list (po.order_id) group_list '
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ') line_item_count '
|| ',bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') shipping_priority'
-- Anna wants all users to know and always wants to know no matter what the status of the auth or order
|| ',(SELECT decode(count(*),0,''N'',''Y'') FROM bcf_payment WHERE ics_rflag = ''DAVSNO'' AND order_id = po.order_id AND status_code IN (''ATH2'',''FUL2'',''CPT0'',''CPT2'')) avs_failed'
|| ',trunc(po.order_date) date_for_sort'
-- When we need to look at all orders then the v_group_for_search will be zero i.e. customer service rep
IF v_group_for_search = 0 THEN
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
-- || ',bcf_lookup lu'
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
-- No orders will be looked at for fulfillment purposes that occurred before the minimum
-- shipping cost functionality was added
-- || 'AND po.order_date >= lu.implement_date '
|| 'AND po.order_date >= (SELECT min(implement_date) FROM bcf_lookup) '
|| 'AND po.submitted_flag = 1 '
|| 'AND po.channel_code = ''BCF'' '
-- When we are looking at all orders then we are not going to restrict it by group
v_group_where := ' ';
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search|| ') '
|| 'IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
ELSE
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
|| ',bcf_product_order_groups pog '
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
|| 'AND po.order_id = pog.order_id '
|| 'AND po.channel_code = ''BCF'' '
-- This is used only where the search type requires searching by a group.
v_group_where := ' '
|| 'AND pog.group_id = ' || v_group_for_search
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND pog.dn_status IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
END IF;
-- If an employee_id is provided then we need to add in a where clause so that only orders that belong to that
-- employee are pulled
IF v_employee_id_in > 0
THEN
v_sql_where := v_sql_where
|| 'AND pog.dn_employee_id = ' || TO_CHAR(v_employee_id_in) || ' '
END IF;
IF v_group_id_in = get_group_fulfillment_center1
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ') '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') '
|| ',po.order_id '
ELSIF v_group_id_in = c_GROUP_FULFILLMENT_CENTER_212
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',TRUNC(po.order_date)'
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ')'
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null)'
|| ',po.order_id'
ELSE
v_sql_order_by := 'ORDER BY '
|| ' bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',chain_codes DESC'
|| ',po.order_id '
END IF;
IF UPPER(v_search_type_in) = 'ORDERNUMBER'
THEN
v_sql_where := v_sql_where || v_group_where
|| 'AND po.order_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'STATUSONLY'
THEN
v_sql_where := v_sql_where || v_group_where || v_status_where
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSIF UPPER(v_search_type_in) = 'BILLINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_billing_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'GROUP'
THEN
IF v_search_value1_in = '0' -- Unassigned
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND po.order_id = pod.order_id '
|| 'AND pod.group_id IS NULL '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND pog.group_id = :v_group_for_search '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_group_for_search;
END IF;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_shipping_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'USERNAME'
THEN
v_lower_search_value1 := LOWER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,sxweb01.customer c ';
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.customer_id = c.customer_id '
|| 'AND c.username LIKE ''%'' || :v_lower_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_lower_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,shipping_info si '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_to_address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.home_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,shipping_info si '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'CREDITCARDNUMBER'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.credit_card_number = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'PONUMBER'
THEN
v_sql_from := ' '
|| 'FROM ' || ' product_order_detail_actv_v pod ,' || SUBSTR(v_sql_from, 6);
v_sql_where := v_sql_where || v_group_where
|| 'AND pod.po_no = :v_search_value1_in '
|| 'AND po.order_id = pod.order_id '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT /*+ ORDERED */ DISTINCT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'USERASSIGNED'
THEN
IF v_search_value1_in = '0' -- 'Unassigned'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.unassigned_flag = ''Y'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.dn_employee_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
END IF;
ELSIF UPPER(v_search_type_in) = 'ORDERDATE'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND po.order_date BETWEEN TO_DATE( :v_search_value1_in, ''MON DD YYYY HH24:MI:SS'') AND TO_DATE( :v_search_value2_in ,''MON DD YYYY HH24:MI:SS'') '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'PRINTJOB'
THEN
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select
|| ' '
|| 'FROM product_order po '
|| ' ,bcf_print_jobs pj '
|| 'WHERE 1 = 1 '
|| 'AND pj.order_id = po.order_id '
|| 'AND pj.username = :v_search_value1_in '
|| 'AND pj.create_date = TO_DATE( :v_search_value2_in,''MON DD YYYY HH24:MI:SS'') '
|| v_sql_order_by
USING v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'FULFILLMENTTYPE'
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pod.order_id = po.order_id '
-- Because we have to drill down the the POD level
-- we now need to ensure the pod records match on group
|| 'AND pod.group_id = ' || v_group_for_search
-- We curr. have 3 fufillment types FC165, FC212, FCBABY
-- so substr on 1st char works for Garry
|| 'AND UPPER(SUBSTR(pod.fulfillment_type,1,1)) = UPPER(:v_search_value1_in) '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'INSUFFICIENTAUTHORIZATION'
THEN
v_sql_where := v_sql_where
|| 'AND bcf_get_authorization_amount(po.order_id) > 0'
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by;
END IF;
END order_search;
Thanks
V
Edited by: vishal patel on Oct 23, 2008 3:59 PMPROCEDURE order_search
v_search_type_in IN VARCHAR2
,v_search_value1_in IN VARCHAR2 DEFAULT 'NONE'
,v_search_value2_in IN VARCHAR2 DEFAULT 'NONE'
,v_group_id_in IN bcf_groups.group_id%TYPE DEFAULT 0
,v_open_in IN NUMBER DEFAULT 0
,v_requested_in IN NUMBER DEFAULT 0
,v_cancelled_in IN NUMBER DEFAULT 0
,v_closed_in IN NUMBER DEFAULT 0
,v_employee_id_in IN sxweb00.customer.customer_id%TYPE DEFAULT 0
,outcursor IN OUT FulfillmentCurType
IS
v_status_code NUMBER;
v_upper_search_value1 VARCHAR2(500);
v_lower_search_value1 VARCHAR2(500);
v_open_status VARCHAR2(10);
v_closed_status VARCHAR2(10);
v_cancelled_status VARCHAR2(10);
v_requested_status VARCHAR2(10);
v_group_for_search bcf_groups.group_id%TYPE;
v_sql_select VARCHAR2(4000);
v_sql_from VARCHAR2(4000);
v_sql_where VARCHAR2(4000);
v_sql_order_by VARCHAR2(4000);
v_group_where VARCHAR2(100);
v_status_where VARCHAR2(500);
BEGIN
IF v_open_in = 1 THEN
v_open_status := 'OPEN';
END IF;
IF v_closed_in = 1 THEN
v_closed_status := 'CLOSED';
END IF;
IF v_cancelled_in = 1 THEN
v_cancelled_status := 'CANCELLED';
END IF;
IF v_requested_in = 1 THEN
v_requested_status := 'REQUESTED';
END IF;
IF UPPER(v_search_type_in) = 'GROUP'
THEN
v_group_for_search := v_search_value1_in;
ELSE
v_group_for_search := v_group_id_in;
END IF;
-- This is the select statement used for all search types
v_sql_select := ' '
|| 'po.order_id order_id '
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null) first_location '
|| ',TO_CHAR(po.order_date, ''mm/dd/yyyy'') order_date '
|| ',' || v_group_for_search || ' group_id '
|| ',TRIM(TO_CHAR(bcf_fulfillment.get_shipping_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_tax_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_subtotal(po.order_id,' || v_group_for_search || ') ,''$999,999,999,999,999,990.99'')) total '
|| ',bcf_fulfillment.get_billing_name (po.customer_id) billing_name '
|| ',bcf_fulfillment.get_open_and_assigned_count(po.order_id,' || v_group_for_search || ') open_and_assigned_count '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') divisions '
|| ',bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ' ) division_count '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ') picker_name '
|| ',bcf_fulfillment.get_picker_count (po.order_id,' || v_group_for_search || ') picker_count '
|| ',bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search || ') order_status '
|| ',po.customer_id customer_id '
-- IF there is only one unique picker then that means there are no unassigned or NULL pickers
-- therefore by default the checkbox should not be selected else the count picker_count is
-- 0 or > 1 meaning that at least one line item has an unassigned employee_id and by default
-- the checkbox should be selected
|| ',DECODE(bcf_fulfillment.get_picker_count(po.order_id,' || v_group_for_search || '),1 ,0,1) print_cb '
|| ',bcf_fulfillment.get_fulfillment_codes(po.order_id,' || v_group_for_search || ') fulfillment_types '
|| ',bcf_fulfillment.has_group_been_reassigned(po.order_id,' || v_group_for_search || ') group_reassigned_flag '
|| ',bcf_fulfillment.get_chain_codes(po.order_id,' || v_group_for_search || ') chain_codes '
|| ',po.status_id order_status_id '
|| ',bcf_fulfillment.get_viewed_by_picker_flag(po.order_id,' || v_group_for_search || ') viewed_by_picker_flag '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ', ''N'') pickers_without_unassigned '
|| ',bcf_fulfillment.get_group_list (po.order_id) group_list '
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ') line_item_count '
|| ',bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') shipping_priority'
-- Anna wants all users to know and always wants to know no matter what the status of the auth or order
|| ',(SELECT decode(count(*),0,''N'',''Y'') FROM bcf_payment WHERE ics_rflag = ''DAVSNO'' AND order_id = po.order_id AND status_code IN (''ATH2'',''FUL2'',''CPT0'',''CPT2'')) avs_failed'
|| ',trunc(po.order_date) date_for_sort'
-- When we need to look at all orders then the v_group_for_search will be zero i.e. customer service rep
IF v_group_for_search = 0 THEN
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
-- || ',bcf_lookup lu'
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
-- No orders will be looked at for fulfillment purposes that occurred before the minimum
-- shipping cost functionality was added
-- || 'AND po.order_date >= lu.implement_date '
|| 'AND po.order_date >= (SELECT min(implement_date) FROM bcf_lookup) '
|| 'AND po.submitted_flag = 1 '
|| 'AND po.channel_code = ''BCF'' '
-- When we are looking at all orders then we are not going to restrict it by group
v_group_where := ' ';
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search|| ') '
|| 'IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
ELSE
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
|| ',bcf_product_order_groups pog '
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
|| 'AND po.order_id = pog.order_id '
|| 'AND po.channel_code = ''BCF'' '
-- This is used only where the search type requires searching by a group.
v_group_where := ' '
|| 'AND pog.group_id = ' || v_group_for_search
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND pog.dn_status IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
END IF;
-- If an employee_id is provided then we need to add in a where clause so that only orders that belong to that
-- employee are pulled
IF v_employee_id_in > 0
THEN
v_sql_where := v_sql_where
|| 'AND pog.dn_employee_id = ' || TO_CHAR(v_employee_id_in) || ' '
END IF;
IF v_group_id_in = get_group_fulfillment_center1
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ') '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') '
|| ',po.order_id '
ELSIF v_group_id_in = c_GROUP_FULFILLMENT_CENTER_212
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',TRUNC(po.order_date)'
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ')'
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null)'
|| ',po.order_id'
ELSE
v_sql_order_by := 'ORDER BY '
|| ' bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',chain_codes DESC'
|| ',po.order_id '
END IF;
IF UPPER(v_search_type_in) = 'ORDERNUMBER'
THEN
v_sql_where := v_sql_where || v_group_where
|| 'AND po.order_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'STATUSONLY'
THEN
v_sql_where := v_sql_where || v_group_where || v_status_where
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSIF UPPER(v_search_type_in) = 'BILLINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_billing_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'GROUP'
THEN
IF v_search_value1_in = '0' -- Unassigned
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND po.order_id = pod.order_id '
|| 'AND pod.group_id IS NULL '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND pog.group_id = :v_group_for_search '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_group_for_search;
END IF;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_shipping_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'USERNAME'
THEN
v_lower_search_value1 := LOWER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,sxweb01.customer c ';
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.customer_id = c.customer_id '
|| 'AND c.username LIKE ''%'' || :v_lower_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_lower_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,shipping_info si '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_to_address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.home_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,shipping_info si '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'CREDITCARDNUMBER'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.credit_card_number = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'PONUMBER'
THEN
v_sql_from := ' '
|| 'FROM ' || ' product_order_detail_actv_v pod ,' || SUBSTR(v_sql_from, 6);
v_sql_where := v_sql_where || v_group_where
|| 'AND pod.po_no = :v_search_value1_in '
|| 'AND po.order_id = pod.order_id '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT /*+ ORDERED */ DISTINCT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'USERASSIGNED'
THEN
IF v_search_value1_in = '0' -- 'Unassigned'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.unassigned_flag = ''Y'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.dn_employee_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
END IF;
ELSIF UPPER(v_search_type_in) = 'ORDERDATE'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND po.order_date BETWEEN TO_DATE( :v_search_value1_in, ''MON DD YYYY HH24:MI:SS'') AND TO_DATE( :v_search_value2_in ,''MON DD YYYY HH24:MI:SS'') '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'PRINTJOB'
THEN
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select
|| ' '
|| 'FROM product_order po '
|| ' ,bcf_print_jobs pj '
|| 'WHERE 1 = 1 '
|| 'AND pj.order_id = po.order_id '
|| 'AND pj.username = :v_search_value1_in '
|| 'AND pj.create_date = TO_DATE( :v_search_value2_in,''MON DD YYYY HH24:MI:SS'') '
|| v_sql_order_by
USING v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'FULFILLMENTTYPE'
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pod.order_id = po.order_id '
-- Because we have to drill down the the POD level
-- we now need to ensure the pod records match on group
|| 'AND pod.group_id = ' || v_group_for_search
-- We curr. have 3 fufillment types FC165, FC212, FCBABY
-- so substr on 1st char works for Garry
|| 'AND UPPER(SUBSTR(pod.fulfillment_type,1,1)) = UPPER(:v_search_value1_in) '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'INSUFFICIENTAUTHORIZATION'
THEN
v_sql_where := v_sql_where
|| 'AND bcf_get_authorization_amount(po.order_id) > 0'
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by;
END IF;
END order_search;
-- -
Optimizing an SQL Query using Oracle SQL Developer
Hi ,
Currently i am using Oracle SQL Developer as my Database IDE .
Is it possible to use Orqcles SQLDeveloper for the purpose of Optimizing an SQL Query ??
For example assume i am having a query as :
Select from Tranac_Master where CUST_STATAUS='Y' and JCC_REPORT='N'*
Could anybody please tell me how can i use Oracle SQL Developer to optimize this query or any other SQL queries ??
Please share your ideas , thanks in advance .1. Your query looks very simplistic as it is, so I fail to see how you can better optimise it (unless 'Tranac_Master' is a view, in which case I'd need to see the view details).
2. No tool can automagically optimise your SQL to any degree of practical use. Very minor adjustments may be possible automatically, but really it is a question of you knowing your data & database design accurately, and then you applying your expert knowledge to tune it. -
Creating sql query using 3 tables
There is database (supposed to be relational but it is not) and
I cannot change the tables and it is very difficult to create SQL query.
Please, help!
First table T1
a1 char 20
time timestamp
a2 char 7 (the same as t2.a2 when is trimmed)
a3 number 5,0
a4 number 8,4
a5 number 7,3
Second table T2
a2 char 15
b1 number 1,0
b2 char 1,0
b3 char 4
a3 number 5,0
Third table T3
b3 char 4
c1 char 4
c2 number 7,3
c3 number 8,4
So, I need to create query (is it possible at all!?) from those 3 tables (a1, a2, b1,b2,b3, a4, a5, c2,c3
where time is within interval (from, to), a3 in interval (1,2,3,4), t2.b3=t3.b3, t1.a2=t2.a2
group by or sorted by a1, then, a2.
Any suggestion is welcome!
Thanks!
By the way, I will use this query in Crystal Reports.As I already mentioned, I received another conditions for the query, and when I create a new one, I
First table T1
a1 number 5,0
a2 char 7 (the same as t2.a2 when is trimmed)
a3 number 8,4
a4 number 7,3
a_time timestamp
Second table T2
a2 char 15
b1 number 1,0
b2 char 1,0
b3 char 4
b4 char 4
Third table T3
c1 char 4
c2 number 7,3
c3 number 8,4
b3 char 4
where if c1='MIN' c2, c3 return min values,
and if c1='MAX' c2,c3 return max values
SQL query:
select t1.a1, t1.a2, t2.b1, t2.b2, t2.b3, t1.a3, t1.a4, t3.c1,
t3.c2, t3.c3, t2.b4
from t1, t2, t3
where (TRIM(t1.a2)=TRIM(t2.a2)
and t1.a1=19
and ((to_char(t1.a_time, 'YYYY-MM-DD') >= '2006-03-15')
and (to_char(t1.a_time, 'YYYY-MM-DD') <= '2006-03-16')))
and t3.b3=t2.b3)
order by t1.a_time
Result set:
a1, a2, b1, b2, b3, a3, a4, c1('MAX'), c2', c3', b4
a1, a2, b1, b2, b3, a3, a4, c1('MIN'), c2", c3", b4
So when I executed SQL query it returns 2 rows for the same a2.
I want to get 1 row for each a2 together with c3 (c4) min and c3 (c4) max values.
How to name columns for c2 min and c2 max (the same for c3) in order to retreive 1 row per a2 value, something like this:
a1, a2, b1, b2, b3, a3, a4, c2min, c2max, c3min, c3max, b4
Thanks
Maybe you are looking for
-
How do I use a tag within a tag?
I have a tag that takes a variable input that is produced from another tag. But I can't figure out how to use the output of one, as the input for another. I'm using the value produced as a value for a form. ex <input type="text" value="<x:tag var="<x
-
How can I see the last location of a now dead ipod touch 4G that had find my iphone turned on?
How can I see the last location of a now dead ipod touch 4G that had find my iphone turned on? I can see my macbook but I cant see the last location of my ipod touch. I lost it a few weeks ago and figured it would show up. But it has not and I need i
-
I can;'t upload my apps, what do I do?
help me!!!!!!!!!!!!!!
-
Terrible signal problem in iPhone 3GS
Hi; I have old iPhone 3G. Which i lost over the last long weekend so i brought the new iPhone 3GS. we all know that iPhone has shaky 3G reception but 3GS is worse than 3G. In the same places where i was getting full signal now i am getting hardly any
-
Problem creating inbound deliveries
Hello to all, i have a problem to create inbound deliveries related to PO for a specific vendor. When i try using VL31N the system result is "An item with no delivery quantity is not permitted. Item will be deleted". It should be a problem related to