Issues with IN clause...
dear all,
I have following piece of code as shown below, as i have written
CREATE OR REPLACE Procedure p_test As
v_pamlg_plots_oprn1 Number := 1001;
v_pamlg_plots_oprn2 Number := 1011;
v_pamlg_plots_oprn3 Number := 1100;
v_pamlg_plots_oprn4 Number := 1110;
v_pamlg_plots_oprn5 Number := 1111;
v_pamlg_plots_oprn Varchar2(30);
v_qty Number;
Begin
Select v_pamlg_plots_oprn1||','||v_pamlg_plots_oprn2||','||v_pamlg_plots_oprn3||','||v_pamlg_plots_oprn4||','||v_pamlg_plots_oprn5
Into v_pamlg_plots_oprn
From dual;
dbms_output.put_line(' v_pamlg_plots_oprn -->>'||v_pamlg_plots_oprn);
Select Sum(d.Qty)
Into v_Qty
From Daily_Stock_Detail_Mal_Lpcs d
Where d.Product = 65019216
And d.Operation In (v_Pamlg_Plots_Oprn);
dbms_output.put_line ('v_qty -->>'||v_qty);
Exception
When Others Then
dbms_output.put_line(Substr(Sqlerrm, 1, 200));
End;
now the procedure is getting sucessfully compiled, and executed with no errors,
however i want to see the qty (v_qty and its always shown null) even though the record exists in the base table...
I am sorry as i cant post the data, but is this correct way of using in clause??
plz let me know,
Nicloei W wrote:
CREATE OR REPLACE Procedure p_test As
v_pamlg_plots_oprn1 Number := 1001;
v_pamlg_plots_oprn2 Number := 1011;
v_pamlg_plots_oprn3 Number := 1100;
v_pamlg_plots_oprn4 Number := 1110;
v_pamlg_plots_oprn5 Number := 1111;Not structured programming. What happens if there needs to be a 6th number? Or 7th? Add more variables and hack the code some more?
It is far easier and a lot more flexible, to deal with this as structured data, using intelligent and flexible data structures. In this case, you need an array of numbers. This is defined in SQL as an Advance Data Type:
create or replace type TNumbers as table of number;In your code, you can now define a single variable with all 5 number values:
create or replace procedure ....
numList TNumbers := new TNumbers( 1001, 1011, 1100, 1110, 1111 );
..To use this collection/array in a SQL statement, you simply code something along the following lines (and note that no literal values are coded in the SQL in order to optimise cursor re-usability):
select
sum(d.qty) into productQty
from daily_stock_detail d
where d.product = productID
and d.operation in (select * from TABLE(numList));Easy.. with structured programming and structured data. To add more numbers is now simply an update to the array's initialisation. Remainder of the code remains unchanged. No new variables to define. No hacking.
As for this smelly brown gunk you're written:
Exception
When Others Then
dbms_output.put_line(Substr(Sqlerrm, 1, 200));
End;DON'T!!! This is NOT how exception handlers work. EVER!!
Similar Messages
-
Greetings All,
I'm having an odd issue with a WHERE clause that I've been working on in a Record Set, $upperdate displays as 2011-02-28, $lowerdate as 2011-02-01, but,
WHERE visitdate >= $lowerdate AND visitdate <= $upperdate
returns no values, and
WHERE visitdate >= $lowerdate AND visitdate <= '2011-02-28'
returns the appropriate values,
Here is the code for $upperdate and $lowerdate:
$datemonth = date ('m');
$dateday = '01';
$dateday1 = date ('t');
$dateyear = date ('Y');
$lowerdate = date("Y-m-d",mktime(0,0,0,$datemonth, $dateday, $dateyear));
$upperdate = date("Y-m-d",mktime(0,0,0,$datemonth, $dateday1, $dateyear));
I've also tried the following things to check functionality with no success:
$upperdate = '2011-02-28';
$dateday1 = '28';
BETWEEN...AND... behaves the same as... >= AND <=
Thanks for the help in advance!Finally worked it out,
I ended up putting single parentheses around '$lowerdate' and '$upperdate' and it works now.
It still seems strange, because it worked when I used no parentheses with the variable in:
WHERE visitdate >= $lowerdate AND visitdate <= '2011-02-28'
Also, I had tried the parentheses a few other times without success, so maybe there was something else awry that I fixed inadvertantly while messing around.
Tim -
Hi All,
I am trying to combine a subquery in where clause but could not get it to work. Does anyone have better idea how can i achieve this?
>
select l.olic_id, l.olic_key, o.trading_name , p.name, l.olic_term, l.expire_date, l.status
from table1 l, table2 o, table3 p, table4 a
where l.cop_id=o.cop_id
and o.par_id=p.par_id
and l.olic_id=a.olic_id and ( select scripts from tb_scripts where dst_id=66)
>
Sub query in the where clause return -
AB is not null or BC is not null or AC is not null or CA is not null or DE is not nullThe region I want to use subquery because it contains more than 60 columns for each dst_id.
Please give me some suggestion. I hope this make sense.
Regards,
TajuddinHere is my table structure -
CREATE TABLE TB_SCRIPTS
DST_ID NUMBER,
SCRIPTS VARCHAR2(500 BYTE)
)Sample data for TB_SCRIPTS table -
dst_id scripts
66 AB is not null or BC is not null or AC is not null or CA is not null or DE is not null
65 AB is not null or CA is not null or DE is not null
67 CA is not null or DE is not nulltable structure for TABLE4 -
CREATE TABLE TABLE4
PK_ID NUMBER,
OLIC_ID NUMBER,
AB VARCHAR2(200),
BC VARCHAR2(200),
AC VARCHAR2(200),
CA VARCHAR2(200),
DE VARCHAR2(200),
EF VARCHAR2(200)
)OLIC_ID is the foreign key in this table referencing table1.
sample data for TABLE4 -
pk_id olic_id AB BC AC CA DE EF
1 123 6 2 8
2 23 9 2 0 1
3 123 0 2 1 7
4 44 7
5 12 8 1 8Table1 structure -
CREATE TABLE TABLE1
OLIC_ID NUMBER,
OLIC_KEY VARCHAR2(20),
OLIC_TERM VARCHAR2(20),
EXPIRE_DATE DATE,
STATUS VARCHAR2(60)
)Some sample data -
OLIC_ID OLIC_KEY OLIC_TERM EXPIRE_DATE STATUS
123 TR42332 1 Year 12/06/2010 Current
154 TR43232 2 Years 24/08/2011 Current
122 TR32422 2 Months 23/01/2009 ExpiredOther tables are not necessary to include here. Basically TABLE1 and TABLE4 joining to retrieve data here. Hope this make sense.
Regards,
M Tajuddin -
Using: oracle 10g
I'm trying to get unique records in my result set, but I can't seem to get my query to work correctly.
Using the following code:
select distinct PLAYER_ID, LAST_NAME , MONIKER, LEAGUE_NAME, TEAM_name, POSITION_1_DESC,
BIRTH_DATE, BIRTH_CITY, BIRTH_COUNTRY_short, METRIC_HEIGHT
from customeR_data.cd_soccer_players
where league_id in (49,64,140,39,80,22,54,51,58,135)
group by PLAYER_ID, LAST_NAME , MONIKER, LEAGUE_NAME, TEAM_name, POSITION_1_DESC,
BIRTH_DATE, BIRTH_CITY, BIRTH_COUNTRY_short, METRIC_HEIGHT
order by player_id, last_nameNot really sure what i'm doing wrong here but I seem to be getting records with the same player_idHi,
As others have explained, DISTINCT just means that each row of output will be different, in some way, from every other row.
If two rows have a different league_name, that means the rows are different, regardless of what is in the other columns.
GROUP BY also guarantees that no two rows will be identical, so DISTINCT is not doing anything in your query.
If you want just one row of output per player_id, then GROUP BY player_id only.
You can use MIN or MAX to get the items that are dependent on player_id (such as last_name).
When there are are two (or more) different values for some field (like league_name) what do you want to display?
If you want a delimited list of items (like the sting 'Chmp_1,TBS'), then search for "String Aggregation". asktom has a good page on this topic. -
Oracle text - issue with contains query
Hello,
Need urgent help.
Following code in my procedure is giving me error.
TYPE c_1 is ref cursor;
result_cursor c1;
i_text2 := 'NEW%';
open result_cursor for
'select /*+ INDEX_SS_DESC(e cad_addr_idx2 )*/
from cad_address
where
contains(text, {:i_text2}, 1) > 0
and rec_type in (1,2,3,4)
order by occur_count desc'
using
i_text2;
ORA-00936: missing expression
ORA-06512: at "AV_OWNER.MY_PROC", line 43
ORA-06512: at line 6
Oracle version is 11.2.0.3.0.
Thanks,check your table is 'text indexed' on this 'Text' column.To knoow more about 'text index' go to
http://docs.oracle.com/cd/B19306_01/text.102/b14217/ind.htm
Also refer to the below thread where someone had faced issues with CONTAINS clause.
ORA-20000: Oracle Text error: DRG-10599: column is not indexed -
No tree displayed with WHERE clause (data issue?)
I tried this on the apex.oracle.com workspace after it didnt run in our setup, and I ran into the same issue.
I cant get the tree to display when I add a WHERE clause to the query.
I know this isnt a problem with the WHERE clause, and has something to do with the data.
If I just delete the data I dont want from the table (data_type <> 'S'), it WORKS, even with the WHERE clause.
I have checked running the SQL, and the root element is returned.
When I look at the HTML source of the page, I can see the js object created, though it seems to be constructed incorrectly.
select case when connect_by_isleaf = 1 then 0
when level = 1 then 1
else -1
end as status,
level,
"DATA_TEXT" as title,
null as icon,
"ID" as value,
null as tooltip,
null as link
from "#OWNER#"."T_ROOT_CAUSE_TEMPLATE"
where (data_type='S' or id=346)
start with id=346
connect by prior "ID" = "PARENT"
order siblings by "DATA_SEQUENCE"Just in case if you didn't know it, you can use WITH factoring clause when creating a tree. It makes it possible to create as many "tables" as you need, while the final hierarchical query (that is responsible for the way the tree looks like) is a simple one. This (+WITH+) approach is convenient as you can avoid repeating inline views and/or subqueries.
For example, your query might have looked like this:
with s_type as
(select * from t_template
where data_type = 'S'
or id = 346
select
case when connect_by_isleaf = 1 then 0
when level = 1 then 1
else -1
end as status,
level,
data_text as title,
null as icon,
id as value,
null as tooltip,
null as link
from
s_type
start with id=346
connect by prior id = parent
order siblings by data_sequence -
Perf tuning issue with a query involving between clause
Hi all,
I am getting issues with performance when I try to execute this query. Given below the query and it is going for a full table scan. I think the problem is with the between clause. But I dont know how to resolve this issue
SELECT psm.member_id
FROM pre_stg_member psm
WHERE psm.map_tran_agn BETWEEN :start_transaction_agn and :end_transaction_agn
and psm.partition_key = :p_partition_key;
Having composite index on map_tran_agn and partition_key.
Please help me in this regard.
Thanks,
SwamiPlease consider the following when you post a question.
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude. -
Performance issues with dynamic action (PL/SQL)
Hi!
I'm having perfomance issues with a dynamic action that is triggered on a button click.
I have 5 drop down lists to select columns which the users want to filter, 5 drop down lists to select an operation and 5 boxes to input values.
After that, there is a filter button that just submits the page based on the selected filters.
This part works fine, the data is filtered almost instantaneously.
After this, I have 3 column selectors and 3 boxes where users put values they wish to update the filtered rows to,
There is an update button that calls the dynamic action (procedure that is written below).
It should be straight out, the only performance issue could be the decode section, because I need to cover cases when user wants to set a value to null (@) and when he doesn't want update 3 columns, but less (he leaves '').
Hence P99_X_UC1 || ' = decode(' || P99_X_UV1 ||','''','|| P99_X_UC1 ||',''@'',null,'|| P99_X_UV1 ||')
However when I finally click the update button, my browser freezes and nothing happens on the table.
Can anyone help me solve this and improve the speed of the update?
Regards,
Ivan
P.S. The code for the procedure is below:
create or replace
PROCEDURE DWP.PROC_UPD
(P99_X_UC1 in VARCHAR2,
P99_X_UV1 in VARCHAR2,
P99_X_UC2 in VARCHAR2,
P99_X_UV2 in VARCHAR2,
P99_X_UC3 in VARCHAR2,
P99_X_UV3 in VARCHAR2,
P99_X_COL in VARCHAR2,
P99_X_O in VARCHAR2,
P99_X_V in VARCHAR2,
P99_X_COL2 in VARCHAR2,
P99_X_O2 in VARCHAR2,
P99_X_V2 in VARCHAR2,
P99_X_COL3 in VARCHAR2,
P99_X_O3 in VARCHAR2,
P99_X_V3 in VARCHAR2,
P99_X_COL4 in VARCHAR2,
P99_X_O4 in VARCHAR2,
P99_X_V4 in VARCHAR2,
P99_X_COL5 in VARCHAR2,
P99_X_O5 in VARCHAR2,
P99_X_V5 in VARCHAR2,
P99_X_CD in VARCHAR2,
P99_X_VD in VARCHAR2
) IS
l_sql_stmt varchar2(32600);
p_table_name varchar2(30) := 'DWP.IZV_SLOG_DET';
BEGIN
l_sql_stmt := 'update ' || p_table_name || ' set '
|| P99_X_UC1 || ' = decode(' || P99_X_UV1 ||','''','|| P99_X_UC1 ||',''@'',null,'|| P99_X_UV1 ||'),'
|| P99_X_UC2 || ' = decode(' || P99_X_UV2 ||','''','|| P99_X_UC2 ||',''@'',null,'|| P99_X_UV2 ||'),'
|| P99_X_UC3 || ' = decode(' || P99_X_UV3 ||','''','|| P99_X_UC3 ||',''@'',null,'|| P99_X_UV3 ||') where '||
P99_X_COL ||' '|| P99_X_O ||' ' || P99_X_V || ' and ' ||
P99_X_COL2 ||' '|| P99_X_O2 ||' ' || P99_X_V2 || ' and ' ||
P99_X_COL3 ||' '|| P99_X_O3 ||' ' || P99_X_V3 || ' and ' ||
P99_X_COL4 ||' '|| P99_X_O4 ||' ' || P99_X_V4 || ' and ' ||
P99_X_COL5 ||' '|| P99_X_O5 ||' ' || P99_X_V5 || ' and ' ||
P99_X_CD || ' = ' || P99_X_VD ;
--dbms_output.put_line(l_sql_stmt);
EXECUTE IMMEDIATE l_sql_stmt;
END;Hi Ivan,
I do not think that the decode is performance relevant. Maybe the update hangs because some other transaction has uncommitted changes to one of the affected rows or the where clause is not selective enough and needs to update a huge amount of records.
Besides that - and I might be wrong, because I only know some part of your app - the code here looks like you have a huge sql injection vulnerability here. Maybe you should consider re-writing your logic in static sql. If that is not possible, you should make sure that the user input only contains allowed values, e.g. by white-listing P99_X_On (i.e. make sure they only contain known values like '=', '<', ...), and by using dbms_assert.enquote_name/enquote_literal on the other P99_X_nnn parameters.
Regards,
Christian -
OBIEE 11g Issue with "group by"
Hello,
I have issues with the physical queries generated by OBIEE engine.
All the facts are at detailed granular level. when I query the table, group by clause is excluded from the query. following is the sample query generated by OBIEE 11g engine.
select 0 as c1,
D1.c2 as c2,
D1.c1 as c3,
D2.c3 as c4,
D2.c2 as c5,
D2.c1 as c6
from
(select distinct T48494.SMBL as c1,
T48494.EXP_DT as c2
from
VW_CONTRACT_DETAILS T48494
where ( T48494.EXP_DT in (TO_DATE('2012-09-03 00:00:00' , 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('2012-09-19 00:00:00' , 'YYYY-MM-DD HH24:MI:SS')) )
) D1,
(select sum(T48494.TRADED_VOL) as c1,
sum(T48494.TRADED_VAL) as c2,
sum(T48494.TOTAL_TRADES) as c3
from
VW_CONTRACT_DETAILS T48494
where ( T48494.EXP_DT in (TO_DATE('2012-09-03 00:00:00' , 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('2012-09-19 00:00:00' , 'YYYY-MM-DD HH24:MI:SS')) )
) D2
order by c3, c2
I'm getting similar kind of issues(exclusion of group by from query) even when i query other fact tables as well. Is there any global change to be made?
Regards,
KishoreDoes it mean you are expecting a group by on
D1.c1, D1.c2?
So query should like
select 0 as c1,
D1.c2 as c2,
D1.c1 as c3,
D2.c3 as c4,
D2.c2 as c5,
D2.c1 as c6
from
(select distinct T48494.SMBL as c1,
T48494.EXP_DT as c2
from
VW_CONTRACT_DETAILS T48494
where ( T48494.EXP_DT in (TO_DATE('2012-09-03 00:00:00' , 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('2012-09-19 00:00:00' , 'YYYY-MM-DD HH24:MI:SS')) )
) D1,
(select sum(T48494.TRADED_VOL) as c1,
sum(T48494.TRADED_VAL) as c2,
sum(T48494.TOTAL_TRADES) as c3
from
VW_CONTRACT_DETAILS T48494
where ( T48494.EXP_DT in (TO_DATE('2012-09-03 00:00:00' , 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('2012-09-19 00:00:00' , 'YYYY-MM-DD HH24:MI:SS')) )
) D2
group by c3, c2 ---> added line
order by c3, c2 -
Issue with SQL Query with Presentation Variable as Data Source in BI Publisher
Hello All
I have an issue with creating BIP report based on OBIEE reports which is done using direct SQL. There is this one report in OBIEE dashboard, which is written using direct SQL. To create the pixel perfect version of this report, I am creating BIP data model using SQL Query as data source. The physical query that is used to create OBIEE report has several presentation variables in its where clause.
select TILE4,max(APPTS), 'Top Count' from
SELECT c5 as division,nvl(DECODE (C2,0,0,(c1/c2)*100),0) AS APPTS,NTILE (4) OVER ( ORDER BY nvl(DECODE (C2,0,0,(c1/c2)*100),0)) AS TILE4,
c4 as dept,c6 as month FROM
select sum(case when T6736.TYPE = 'ATM' then T7608.COUNT end ) as c1,
sum(case when T6736.TYPE in ('Call Center', 'LSM') then T7608.CONFIRMED_COUNT end ) as c2,
T802.NAME_LEVEL_6 as c3,
T802.NAME_LEVEL_1 as c4,
T6172.CALENDARMONTHNAMEANDYEAR as c5,
T6172.CALENDARMONTHNUMBERINYEAR as c6,
T802.DEPT_CODE as c7
from
DW_date_DIM T6736 /* z_dim_date */ ,
DW_MONTH_DIM T6172 /* z_dim_month */ ,
DW_GEOS_DIM T802 /* z_dim_dept_geo_hierarchy */ ,
DW_Count_MONTH_AGG T7608 /* z_fact_Count_month_agg */
where ( T802.DEpt_CODE = T7608.DEPT_CODE and T802.NAME_LEVEL_1 = '@{PV_D}{RSD}'
and T802.CALENDARMONTHNAMEANDYEAR = 'July 2013'
and T6172.MONTH_KEY = T7608.MONTH_KEY and T6736.DATE_KEY = T7608.DATE_KEY
and (T6172.CALENDARMONTHNUMBERINYEAR between substr('@{Month_Start}',0,6) and substr('@{Month_END}',8,13))
and (T6736.TYPE in ('Call Center', 'LSM')) )
group by T802.DEPT_CODE, T802.NAME_LEVEL_6, T802.NAME_LEVEL_1, T6172.CALENDARMONTHNAMEANDYEAR, T6172.CALENDARMONTHNUMBERINYEAR
order by c4, c3, c6, c7, c5
))where tile4=3 group by tile4
When I try to view data after creating the data set, I get the following error:
Failed to load XML
XML Parsing Error: mismatched tag. Expected: . Location: http://172.20.17.142:9704/xmlpserver/servlet/xdo Line Number 2, Column 580:
Now when I remove those Presention variables (@{PV1}, @{PV2}) in the query with some hard coded values, it is working fine.
So I know it is the PV that's causing this error.
How can I work around it?
There is no way to create equivalent report without using the direct sql..
Thanks in advanceI have found a solution to this problem after some more investigation. PowerQuery does not support to use SQL statement as source for Teradata (possibly same for other sources as well). This is "by design" according to Microsoft. Hence the problem
is not because different PowerQuery versions as mentioned above. When designing the query in PowerQuery in Excel make sure to use the interface/navigation to create the query/select tables and NOT a SQL statement. The SQL statement as source works fine on
a client machine but not when scheduling it in Power BI in the cloud. I would like to see that the functionality within PowerQuery and Excel should be the same as in Power BI in the cloud. And at least when there is a difference it would be nice with documentation
or more descriptive errors.
//Jonas -
Hello, everyone.
I am having issues with running a DELETE statement on an Oracle 10g database.
DELETE
FROM tableA
WHERE ID in (1,2,3)
If there is only one ID for the IN clause, it works. But if more than one ID is supplied, I get an "SQL command not properly ended" error message. Here is the query as CF:
DELETE
FROM TRAINING
WHERE userID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#trim(form.userID)#">
AND TRAINING_ID in <cfqueryparam value="#form.trainingIDs#" cfsqltype="CF_SQL_INTEGER" list="yes">
Anyone work with Oracle that can help me with this? I'm an experienced MS-SQL developer; Oracle is new to me.
Thanks,
^_^Nevermind.. a co-worker just told me that I still have to use parenthesis around the values for the IN clause.
-
Issue with @variable('DOCNAME')
I added a where clause using the BO designer that uses @variable ('DOCNAME') and it work perfect when running webi reports. But I also have some crystal reports that are using the universe and they suddenly stopped working. Does the variable 'DOCNAME' have an issue with cyrstal reports??
Even if I just create an object that simply displays the @variable ('DOCNAME'), I still run into the same problem.
I have another query that uses @variable ('BOUSER') and that one works fine on both webi and crystal reports.Nevermind, I may have found an answer. Based on what the article below states, it looks like the only variable that is supported in Crystal Reports is 'BOUSER'.
[https://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/20984c2b-17f1-2b10-1091-d18977f7cd8f|https://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/20984c2b-17f1-2b10-1091-d18977f7cd8f] -
Outer Join with Where Clause in LTS
HI all,
I have a requirement like this in ANSI SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1 left outer join product_group p2 on p1.product_id = p2.product_id
and p2.product_group = 'NEW'
In Regular SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1, product_group p2
WHERE p1.product_id *= p2.product_id and p2.product_group = 'NEW'
In OBIEE, I am using a left outer join between these two in Logical table Source, and also, Gave
p2.product_group = 'NEW' in WHERE clause of LTS.
This doesn't seem to solve purpose.
Do you have any idea how to convert WHERE clause in physical query that OBIEE is generating to something like
product p1 left outer join product_group p2 on p1.product_id = p2.product_id AND p2.product_group = 'NEW'
I am using Version 10.1.3.4.1
Creating an Opaque view would be my last option though.Hello
I have read your post and the responses as well. and I understand that you have issues with the Outer Join with where Clause in LTS.
Try this solution which worked for me (using your example ) -
1. In the Physical Layer created a Complex join between PRODUCT and PRODUCT_GROUP tables and use this join relationship :
PRODUCT.PROD_ID = PRODUCT_GROUP.PROD_ID AND PRODUCT_GROUP.GROUP_NAME = 'MECHANICAL'
2. In the General Tab of PRODUCT table LTS add PRODUCT_GROUP table and select Join Type as Left Outer Join.
3. Check Consistency and make sure there are no errors .
when you run a request you should see the following query generated -
select distinct T26908.PROD_ID as c1,
T26908.PROD_NAME as c2,
T26912.GROUP_NAME as c3
from
PRODUCT T26908 left outer join PRODUCT_GROUP T26912 On T26908.PROD_ID = T26912.PROD_ID and T26912.GROUP_NAME = 'MECHANICAL'
order by c1, c2, c3
Hope this works for you. If it does please mark this response as 'Correct' .
Good Luck. -
Select query with UNION clause in database adapter
Friends,
I have got a SQL query with two UNION clause withing it. like
select a,b,c
from a
union
select a,b,c
from b
The schema generated is like below in sequence
<element>a</element>
<element>b</element>
<element>c</element>
<element>a</element>
<element>b</element>
<element>c</element>
So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
Is there any way around to solve this issue ? or will need to with DB function/procedure.I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
<elementA>DateA</elementA>
<elementB>DataB</elementB>
<elementC>DataC</elementC>
...What is the result of the query when you run it in SQLPlus? Is it what you expect?
cheers
James -
Issue with "read by other session" and a parallel MERGE query
Hi everyone,
we have run into an issue with a batch process updating a large table (12 million rows / a few GB, so it's not that large). The process is quite simple - load the 'increment' from a file into a working table (INCREMENT_TABLE) and apply it to the main table using a MERGE. The increment is rather small (usually less than 10k rows), but the MERGE runs for hours (literally) although the execution plan seems quite reasonable (can post it tomorrow, if needed).
The first thing we've checked is AWR report, and we've noticed this:
Top 5 Timed Foreground Events
Event Waits Time(s) Avg wait (ms) % DB time Wait Class
DB CPU 10,086 43.82
read by other session 3,968,673 9,179 2 39.88 User I/O
db file scattered read 1,058,889 2,307 2 10.02 User I/O
db file sequential read 408,499 600 1 2.61 User I/O
direct path read 132,430 459 3 1.99 User I/OSo obviously most of the time was consumed by "read by other session" wait event. There were no other queries running at the server, so in this case "other session" actually means "parallel processes" used to execute the same query. The main table (the one that's updated by the batch process) has "PARALLEL DEGREE 4" so Oracle spawns 4 processes.
I'm not sure how to fix this. I've read a lot of details about "read by other session" but I'm not sure it's the root cause - in the end, when two processes read the same block, it's quite natural that only one does the physical I/O while the other waits. What really seems suspicious is the number of waits - 4 million waits means 4 million blocks, 8kB each. That's about 32GB - the table has about 4GB, and there are less than 10k rows updated. So 32 GB is a bit overkill (OK, there are indexes etc. but still, that's 8x the size of the table).
So I'm thinking that the buffer cache is too small - one process reads the data into cache, then it's removed and read again. And again ...
One of the recommendations I've read was to increase the PCTFREE, to eliminate 'hot blocks' - but wouldn't that make the problem even worse (more blocks to read and keep in the cache)? Or am I completely wrong?
The database is 11gR2, the buffer cache is about 4GB. The storage is a SAN (but I don't think this is the bottleneck - according to the iostat results it performs much better in case of other batch jobs).OK, so a bit more details - we've managed to significantly decrease the estimated cost and runtime. All we had to do was a small change in the SQL - instead of
MERGE /*+ parallel(D DEFAULT)*/ INTO T_NOTUNIFIED_CLIENT D /*+ append */
USING (SELECT
FROM TMP_SODW_BB) S
ON (D.NCLIENT_KEY = S.NCLIENT_KEY AND D.CURRENT_RECORD = 'Y' AND S.DIFF_FLAG IN ('U', 'D'))
...(which is the query listed above) we have done this
MERGE /*+ parallel(D DEFAULT)*/ INTO T_NOTUNIFIED_CLIENT D /*+ append */
USING (SELECT
FROM TMP_SODW_BB AND DIFF_FLAG IN ('U', 'D')) S
ON (D.NCLIENT_KEY = S.NCLIENT_KEY AND D.CURRENT_RECORD = 'Y')
...i.e. we have moved the condition from the MERGE ON clause to the SELECT. And suddenly, the execution plan is this
OPERATION OBJECT_NAME OPTIONS COST
MERGE STATEMENT 239
MERGE T_NOTUNIFIED_CLIENT
PX COORDINATOR
PX SEND :TQ10000 QC (RANDOM) 239
VIEW
NESTED LOOPS OUTER 239
PX BLOCK ITERATOR
TABLE ACCESS TMP_SODW_BB FULL 2
Filter Predicates
OR
DIFF_FLAG='D'
DIFF_FLAG='U'
TABLE ACCESS T_NOTUNIFIED_CLIENT BY INDEX ROWID 3
INDEX AK_UQ_NOTUNIF_T_NOTUNI RANGE SCAN 2
Access Predicates
AND
D.NCLIENT_KEY(+)=NCLIENT_KEY
D.CURRENT_RECORD(+)='Y'
Filter Predicates
D.CURRENT_RECORD(+)='Y' Yes, I know the queries are not exactly the same - but we can fix that. The point is that the TMP_SODW_BB table contains 1639 rows in total, and 284 of them match the moved 'IN' condition. Even if we remove the condition altogether (i.e. 1639 rows have to be merged), the execution plan does not change (the cost increases to about 1300, which is proportional to the number of rows).
But with the original IN condition (that turns into an OR combination of predicates) in the MERGE ON clausule, the cost suddenly skyrockets to 990.000 and it's damn slow. It seems like a problem with cost estimation, because once we remove one of the values (so there's only one value in the IN clausule), it works fine again. So I guess it's a planner/estimator issue ...
Maybe you are looking for
-
Itunes wont load error message appcrash?
Thank you in advance. windows 7 home premium. Itunes decided to not load a few days ago. I used the windows dialog box to look for a solution online and then close program. It came back with there is an update to the program and that should fix your
-
How do I get Apple TV2's "Computers" to display my computer ??
How do I get my computer to display on the Apple TV2 menu in the Computers category ?? I have homesharing turned on in iTunes and Apple TV2 using the same login name and password. Is it a firewall problem ? The other areas of Apple TV2 are working
-
Why does my iPod touch keep repeating the same song?
Since I loaded the software update 4.1 my music keeps replaying one song unless I choose to shuffle. What have I done?
-
Hello... Can u help me plz to update my iphone 3G
Hi can u plz help me to update my iphone 3G
-
Define Rules for Variants (Daily Work Schedules)
Hi All, I wanted to set up the following rule for varients : If Holiday Falls on SUnday then Monday should be change Off. I have created Varient for DWS. as NORM , NORM - "C". 01 03 .X........ X......... ......X