...where like ('% query returning mul rows %') - how?
Hi
I have a situation where in my main query's where clause I have to use like ('% <value returned from query2>%'). However, my query2 can return multiple rows.
It is something like this:
Select .....
from table1 t1
where path like ('%<query2>%').
Path can have multiple values - it is just representing a parent child relationship like 1/2/3. 1 is a parent of 2. 2 is a parnt of 3 and so on. What I get from query2 could be either of these. So I have to use like and not in. How may I achieve this?
select lvl,
Path
from (select distinct level as lvl,
sys_connect_by_path(parent,'/') Path
from table1 t1
connect by prior child = parent)
where instr(path,((select parent --+
from (select parent, sm, rank() over (order by sm desc) r |
from (SELECT parent, SUM(CT1) as sm |
FROM ((select parent,count(child) ct1 |
from table1 t1 |
where group by parent |
-- end level 1) |
UNION ALL |
(select parent, count(child) ct2 | try to move this sub-query
from table1 t1 | at the FROM clause
where child in --first level |
(select parent |
from (select distinct parent,count(child) ct1 |
from table1 t1 |
where group by parent) q1)-- end level 1 |
group by parent))--MAIN SEL |
GROUP BY parent)) |
where r =1))) > 0--end instr --+
and lvl = 1
you may try to move sub-queries in your WHERE clause to the FROM clause.
Message was edited by:
Warren Tolentino
justin has the same idea :D
Similar Messages
-
Adding the results of subqueries, where one subquery returns no rows
I am creating a complex SQL statement- many of the columns consist of the sum of two subqueries. Here is a simplified example:
SELECT NAME, ID,
(SELECT AMT1 FROM TABLE1 WHERE ID = 111) + (SELECT AMT2 FROM TABLE2 WHERE ID = 222),
(SELECT AMT3 FROM TABLE3 WHERE ID = 333) + (SELECT AMT4 FROM TABLE4 WHERE ID = 444),
FROM TABLE
WHERE...
The problem is, within one select item, if one subquery returns no rows and the other returns a row of data, the sum of the two is displayed as zero. For example, if 'SELECT AMT1 FROM TABLE1 WHERE ID = 111' returns a row, with a value of AMT1 = 1000, and 'SELECT AMT2 FROM TABLE2 WHERE ID = 222' returns no rows, the result is displayed as 0, not 1000. It reminds me of when you add a number and a NULL, and get NULL - the number gets ignored.
Is there a way to embed some conditional logic in the subquery, to say 'if no rows returned, AMT = 0, else AMT = value'? Any help would be appreciated.Yikes, you appear to have stumbled upon DMFH!
You can use NVL like this -
SQL> select
2 (select 1 from dual) + (select 2 from dual) x
3 from dual;
X
3
SQL> edi
Wrote file afiedt.sql
1 select
2 (select 1 from dual) + (select 2 from dual where 0 = 1) x
3* from dual
SQL> /
X
SQL> edi
Wrote file afiedt.sql
1 select
2 (select 1 from dual) + nvl((select 2 from dual where 0 = 1),0) x
3* from dual
SQL> /
X
1
SQL>(DMFH = Data Model From Hell) -
Query returns more row than expected
1. select * from view_name where col1 = 'value1' returns 12 rows
2. select * from (view script) where col1 = 'value1' returns 24 rows
i have a view called view_name. If i use view_name directly in the query, it returns 12 rows. But if i use the select script directly in from clause, it returns more rows. I am not able to find out why it is happening so. Any pointers will be helpful.Are you saying that the SQL for view_name and view_script are identical? Can you post them?
-
XML attributes makes my query return no rows
Hello everyone,
I've an odd problem.
I'm querying some XML, but the attributes in one of the tags make my query return no rows; if I remove the attributes, then the query works as expected.
The XML is below; it's the attributes in the Report tag that cause the issues:
<result errorCode="0">
<return>
<Report
xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&rs%3AFormat=xml&rc%3ASchema=True"
Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="Items_x0020_status_x0020_information">
<Tablix1>
<Details_Collection>
<Details ItemId="914P7" Username="test" user_role="IT"
first_name="Barry" last_name="Donovan" organisation=""
content_format="On_Screen" modified_date="26/05/2011 13:16:49"
item_status="Draft" status_date="" component_name="" demand="" />
</Details_Collection>
</Tablix1>
</Report>
</return>
</result>My query is:
select
a.item_id
,a.username
,a.user_role
,a.first_name
,a.last_name
,a.supplier_id
,a.format
,a.modified_date
,a.item_status
,a.completion_date
,a.component_code
from dual
,xmltable
('/result/return/Report/Tablix1/Details_Collection/Details'
passing p_xml
columns
item_id varchar2(1000) path '@ItemId'
,username varchar2(1000) path '@Username'
,user_role varchar2(1000) path '@user_role'
,first_name varchar2(1000) path '@first_name'
,last_name varchar2(1000) path '@last_name'
,supplier_id varchar2(1000) path '@organisation'
,format varchar2(1000) path '@content_format'
,modified_date varchar2(1000) path '@modified_date'
,item_status varchar2(1000) path '@item_status'
,completion_date varchar2(1000) path '@status_date'
,component_code varchar2(1000) path '@demand'
) a;I've tried stripping out the attributes in the tag, which does work, but some of the XML I'm expecting back may be quite large (many records), so that caused issues in itself. I'd rather deal with it and not mess with the XML itself if possible.
Any help would be hugely appreciated!
Thank you very much in advance.
Robin
Edited by: User_resU on Apr 12, 2012 2:50 PMExample:
SQL> ed
Wrote file afiedt.buf
1 with t as (select xmltype('<result errorCode="0">
2 <return>
3 <Report
4 xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&rs%3AFormat=xml&rc%3ASchema=True"
5 Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xmlns="Items_x0020_status_x0020_information">
7 <Tablix1>
8 <Details_Collection>
9 <Details ItemId="914P7" Username="test" user_role="IT"
10 first_name="Barry" last_name="Donovan" organisation=""
11 content_format="On_Screen" modified_date="26/05/2011 13:16:49"
12 item_status="Draft" status_date="" component_name="" demand="" />
13 </Details_Collection>
14 </Tablix1>
15 </Report>
16 </return>
17 </result>') as xml from dual)
18 --
19 -- end of test data
20 --
21 select
22 a.item_id
23 ,a.username
24 ,a.user_role
25 ,a.first_name
26 ,a.last_name
27 ,a.supplier_id
28 ,a.format
29 ,a.modified_date
30 ,a.item_status
31 ,a.completion_date
32 ,a.component_code
33 from t
34 ,xmltable
35 (xmlnamespaces('Items_x0020_status_x0020_information' as "x0"),
36 '//x0:Report/x0:Tablix1/x0:Details_Collection/x0:Details'
37 passing xml
38 columns
39 item_id varchar2(1000) path '@ItemId'
40 ,username varchar2(1000) path '@Username'
41 ,user_role varchar2(1000) path '@user_role'
42 ,first_name varchar2(1000) path '@first_name'
43 ,last_name varchar2(1000) path '@last_name'
44 ,supplier_id varchar2(1000) path '@organisation'
45 ,format varchar2(1000) path '@content_format'
46 ,modified_date varchar2(1000) path '@modified_date'
47 ,item_status varchar2(1000) path '@item_status'
48 ,completion_date varchar2(1000) path '@status_date'
49 ,component_code varchar2(1000) path '@demand'
50* ) a
SQL> /
ITEM_ID
USERNAME
USER_ROLE
FIRST_NAME
LAST_NAME
SUPPLIER_ID
FORMAT
MODIFIED_DATE
ITEM_STATUS
COMPLETION_DATE
COMPONENT_CODE
914P7
test
IT
Barry
Donovan
On_Screen
26/05/2011 13:16:49
Draft -
I select a data from one table
select * from taxon --- it returns rows
this table has 5 columns -- branchcode, no,trackno,invno,serialno
if i use the following query
select * from taxon where branchcode='CNHJCT'
It return no rwos , but there is data
if i change the above query like
select * from taxon where branchcode like '%CNHJCT'
it returns the rows , but if i check the value of the branchcode there is no space
on both side .
How i can troble shoot this problem
rdsThe is clearly some other characters to the left of the string.
Look at the output of this query, and you will probably see them.
SELECT DUMP(branchcode) col, DUMP('CNHJCT') pred
FROM taxon
WHERE branchcode LIKE '%CNHJCT'John
Message was edited by:
John Spencer
If I didn't have to re-type everything three times because I can't type, I would have beaten BluShadow :-) -
Silly old fogey (me) cannot figure out why this query returns 1 row
Hi all,
In reference to {thread:id=2456973}, why does
select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
, sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
from emp group by job;only return 1 row and not 1 for each job? I actually had to test it myself to believe it.
It returns data as if the query were
select sum(CLERKS), sum(SALESMANS)
from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
from emp group by job)Using only a single aggregate (either count or sum) returns 1 row per job, as expectedJohn Stegeman wrote:
It returns data as if the query were
select sum(CLERKS), sum(SALESMANS)
from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
from emp group by job)
Exactly the point ;-)
Seems like Oracle actually can do a "double group by" in the same operation.
Witness the explain plans in this example:
SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
2 , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
3 from scott.emp group by job;
CLERKS SALESMANS
0 0
0 0
0 0
0 4
4 0
Execution Plan
Plan hash value: 1697595674
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 40 | 4 (25)| 00:00:01 |
| 1 | HASH GROUP BY | | 5 | 40 | 4 (25)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------And compare it to this one with the double aggregates:
SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
2 , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
3 from scott.emp group by job;
CLERKS SALESMANS
4 4
Execution Plan
Plan hash value: 417468012
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (25)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 8 | 4 (25)| 00:00:01 |
| 2 | HASH GROUP BY | | 1 | 8 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------There is both HASH GROUP BY and SORT AGGREGATE.
It does not really make sense to do an aggregate on an aggregate - if both aggregates are used "on the same group-by level".
The sum() aggregates are used upon an already aggregated value, so it does look like Oracle actually treats that as "first do the inner aggregate using the specified group by and then do the outer aggregate on the result with no group by."
Look at this example where I combine "double" aggregates with "single" aggregates:
SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
2 , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
3 , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2
4 , count(*) COUNTS
5 from scott.emp group by job;
CLERKS SALESMANS SALESMANS2 COUNTS
4 4 1 5
Execution Plan
Plan hash value: 417468012
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (25)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 8 | 4 (25)| 00:00:01 |
| 2 | HASH GROUP BY | | 1 | 8 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------When mixing "double" and "single" aggregates, Oracle decides that single aggregates belong in the "outer" aggregation.
SALESMAN2 is doing a count on the aggregated job column that is the result of the "inner" group by - therefore only 1.
The count(*) also counts the result of the "inner" aggregation.
I am not sure if this is documented or if it is a "sideeffect" of either the internal code used for GROUPING SETS or the internal code used for allowing analytic functions like this:
SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
2 , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
3 , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2
4 , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2
5 from scott.emp group by job;
CLERKS SALESMANS CLERKS2 SALESMANS2
0 0 4 4
4 0 4 4
0 0 4 4
0 0 4 4
0 4 4 4
Execution Plan
Plan hash value: 4115955660
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 40 | 4 (25)| 00:00:01 |
| 1 | WINDOW BUFFER | | 5 | 40 | 4 (25)| 00:00:01 |
| 2 | SORT GROUP BY | | 5 | 40 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------Personally I think I would have preferred if Oracle raised an error on this "double aggregation" and thus require me to write it this way (if that is the result I desired):
select sum(CLERKS), sum(SALESMANS)
from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
from emp group by job)I can not really think of good use-cases for the "double aggregation" - but rather that it could give you unnoticed bugs in your code if you happen to do double aggregation without noticing it.
Interesting thing to know ;-) -
Repeating frame not visible when the query returns no rows
I've developed a report whose output looks like this:
Subinventory | Part Code |Part Description |Ordered Qty | Received Qty
Mentone St | BATT | non serialised item | |
Mentone St | SONY | spare parts MIN MAX | 30| 0
In the above report
subinventory, Part Code, Part description are in one repeating frame and Ordered and received qty are in other repeating frame.
for a perticular part code there may not be ordered or received quantities. Means the seond query fetches no rows for the perticulat partcode. In that case report is showing null(blank) but I want to print ZERO there.
If I use NVL in the query it'll effect only when the query fetches some rows.
I've tried with formula columns. for example in the formula column
IF :ordered_qty IS NULL THEN
v_ordered_qty :=0;
ELSE
v_ordered_qty := :ordered_qty;
END IF;
return(v_ordered_qty);
I've assigned this formula column as source to the Ordered Qty Filed. Then also its not working.
Any help in this regards is highly apprecialted
regards,
Vijmay be you can modify your code like below:
SELECT i.subinventory, i.part_code, i.part_description, i.min_qty, i.max_qty,
NVL (j.quantity, 0) ordered_qty,
NVL (j.quantity_delivered, 0) received_qty
FROM (SELECT DISTINCT c.secondary_inventory subinventory,
b.segment1 part_code, b.description part_description,
c.min_minmax_quantity min_qty,
c.max_minmax_quantity max_qty, b.inventory_item_id,
b.organization_id
FROM mtl_system_items_b b,
mtl_item_sub_inventories_all_v c
WHERE b.inventory_item_id = c.inventory_item_id
AND b.organization_id = c.organization_id
AND UPPER (c.secondary_inventory) =
NVL (UPPER (DECODE (:p_sub_inv,
'ALL', '',
:p_sub_inv
UPPER (c.secondary_inventory)
)) i,
(SELECT mtrl.inventory_item_id, mtrl.organization_id,
mtrl.to_subinventory_code,
NVL (SUM (mtrl.quantity), 0) quantity,
NVL (SUM (mtrl.quantity_delivered), 0) quantity_delivered
FROM mtl_txn_request_lines mtrl, mtl_system_items_b msi
WHERE mtrl.inventory_item_id = msi.inventory_item_id
AND mtrl.organization_id = msi.organization_id
AND mtrl.reference_type_code = 2
AND UPPER (mtrl.to_subinventory_code) =
NVL (UPPER (DECODE (:p_sub_inv, 'ALL', '', :p_sub_inv)),
UPPER (mtrl.to_subinventory_code)
AND TRUNC (mtrl.creation_date)
BETWEEN NVL (TRUNC (TO_DATE (:p_from_date,
'yyyy/mm/dd hh24:mi:ss'
TRUNC (mtrl.creation_date)
AND NVL (TRUNC (TO_DATE (:p_to_date,
'yyyy/mm/dd hh24:mi:ss'
TRUNC (mtrl.creation_date)
GROUP BY mtrl.inventory_item_id,
mtrl.organization_id,
mtrl.to_subinventory_code) j
WHERE i.inventory_item_id = j.inventory_item_id(+)
AND i.organization_id = j.organization_id(+) -
SQL Query returning no rows, please help!!
I have a table that contains user audits for a particular procedures alongwith the date stamp. Now, I want to list all the procedures not accessed by the users within the last 6 months. Or, all the procedures that have not been used/accessed during the last 6 months.
This is what I am trying but is not returning any rows:
SELECT DISTINCT proc_name,
TRUNC (entry_date)
FROM log_web
WHERE proc_name NOT IN (SELECT proc_name
FROM log_web
WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180))
ORDER BY 2 DESC
Please advise.
Thank you in advance.Two possibilities leap to mind.
First, are you sure that there are any prodcedures not accessed in the last six months?
Second, is there a chance that there could be records with a null value in proc_name? If the sub-query used in a NOT IN predicate returns even one null value, the query will return no rows.
Does this return rows?
SELECT DISTINCT proc_name, TRUNC(entry_date)
FROM log_web
WHERE proc_name NOT IN (SELECT proc_name
FROM log_web
WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180) and
proc_name IS NOT NULL)
ORDER BY 2 DESCJohn -
Query return no rows in Answers but retrun rows in sql
Hi all,
I have the following query which return 3 rows in SQL promple but return no row in Answer and Execute direct request what is the problem any idea?
select abc_date,abc_asset_desc,sum(abc_market_val_lcy+abc_int_accr_lcy) "Stock"
from abc
group by abc_date,abc_asset_descRegardsHi,
i really appriciate your reply
pls tell me briefly from where i can set log-level > 2 ?? and from where check the physical log of SQL ?
Followig message is arise at server log
ORA-01455 converting column overflow integer datatype at OCI call OCIStmtFetch,Bulk fetched failed
Message was edited by:
53637 -
Optimizing javascript where I have query returning 3000 rows.
Hi,
I have a javascript running which is called when user selects from a list and a query is run which fetches the records and puts them in the select lists for other 6 dropdowns on the page. when the user selects from the list, it takes a lot of time to fetch the data. I am wondering how I can optimize this javascript.
the javascript is :
<script language="JavaScript" type="text/javascript">
function get_select_list_xml1(pThis,pSelect)
var l_Return = null;
var l_Select = html_GetElement(pSelect);
var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=CAS_SEL_LIST',&APP_PAGE_ID.);
get.add('CAS_SEL_PROJ_ID_ITEM',pThis.value);
gReturn = get.get('XML');
if(gReturn && l_Select){
var l_Count = gReturn.getElementsByTagName("option").length;
l_Select.length = 0;
for(var i=0;i<l_Count;i++){
var l_Opt_Xml = gReturn.getElementsByTagName("option");
appendToSelect(l_Select, l_Opt_Xml.getAttribute('value'),
l_Opt_Xml.firstChild.nodeValue)
get = null;
function get_select_list_xml2(pThis,pSelect)
var l_Return = null;
var l_Select = html_GetElement(pSelect);
var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=cas_sel_list_hosting_cluster',&APP_PAGE_ID.);
get.add('CAS_SEL_PROJ_ID_ITEM',pThis.value);
gReturn = get.get('XML');
if(gReturn && l_Select){
var l_Count = gReturn.getElementsByTagName("option").length;
l_Select.length = 0;
for(var i=0;i<l_Count;i++){
var l_Opt_Xml = gReturn.getElementsByTagName("option")[i];
appendToSelect(l_Select, l_Opt_Xml.getAttribute('value'),
l_Opt_Xml.firstChild.nodeValue)
get = null;
function appendToSelect(pSelect, pValue, pContent)
var l_Opt = document.createElement("option");
l_Opt.value = pValue;
if(document.all){
pSelect.options.add(l_Opt);
l_Opt.innerText = pContent;
}else{
l_Opt.appendChild(document.createTextNode(pContent));
pSelect.appendChild(l_Opt);
</script>
query which is run as a process is :
BEGIN
OWA_UTIL.mime_header ('text/xml', FALSE);
HTP.p ('Cache-Control: no-cache');
HTP.p ('Pragma: no-cache');
OWA_UTIL.http_header_close;
HTP.p('<select>');
HTP.p ('<option value="' || null || '">'|| '-Select Jack from the list-' ||
'</option>');
FOR c IN (
select JACK_NUM a_j_n, jack_NUM b_j_n from (select JACK_NUM from CTS_LIST_OF_JACKS where NOT EXISTS ( select jack from cts_server_jack_info where (cts_server_jack_info.jack = CTS_LIST_OF_JACKS.jack_num))) where JACK_NUM != :cas_sel_proj_id_item order by jack_num
LOOP
HTP.p ('<option value="' || c.a_j_n || '">' || c.b_j_n || '</option>');
END LOOP;
HTP.p('</select>');
END;
thanks,
gargiHi,
I have a javascript running which is called when user selects from a list and a query is run which fetches the records and puts them in the select lists for other 6 dropdowns on the page. when the user selects from the list, it takes a lot of time to fetch the data. I am wondering how I can optimize this javascript.
the javascript is :
<script language="JavaScript" type="text/javascript">
function get_select_list_xml1(pThis,pSelect)
var l_Return = null;
var l_Select = html_GetElement(pSelect);
var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=CAS_SEL_LIST',&APP_PAGE_ID.);
get.add('CAS_SEL_PROJ_ID_ITEM',pThis.value);
gReturn = get.get('XML');
if(gReturn && l_Select){
var l_Count = gReturn.getElementsByTagName("option").length;
l_Select.length = 0;
for(var i=0;i<l_Count;i++){
var l_Opt_Xml = gReturn.getElementsByTagName("option");
appendToSelect(l_Select, l_Opt_Xml.getAttribute('value'),
l_Opt_Xml.firstChild.nodeValue)
get = null;
function get_select_list_xml2(pThis,pSelect)
var l_Return = null;
var l_Select = html_GetElement(pSelect);
var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=cas_sel_list_hosting_cluster',&APP_PAGE_ID.);
get.add('CAS_SEL_PROJ_ID_ITEM',pThis.value);
gReturn = get.get('XML');
if(gReturn && l_Select){
var l_Count = gReturn.getElementsByTagName("option").length;
l_Select.length = 0;
for(var i=0;i<l_Count;i++){
var l_Opt_Xml = gReturn.getElementsByTagName("option")[i];
appendToSelect(l_Select, l_Opt_Xml.getAttribute('value'),
l_Opt_Xml.firstChild.nodeValue)
get = null;
function appendToSelect(pSelect, pValue, pContent)
var l_Opt = document.createElement("option");
l_Opt.value = pValue;
if(document.all){
pSelect.options.add(l_Opt);
l_Opt.innerText = pContent;
}else{
l_Opt.appendChild(document.createTextNode(pContent));
pSelect.appendChild(l_Opt);
</script>
query which is run as a process is :
BEGIN
OWA_UTIL.mime_header ('text/xml', FALSE);
HTP.p ('Cache-Control: no-cache');
HTP.p ('Pragma: no-cache');
OWA_UTIL.http_header_close;
HTP.p('<select>');
HTP.p ('<option value="' || null || '">'|| '-Select Jack from the list-' ||
'</option>');
FOR c IN (
select JACK_NUM a_j_n, jack_NUM b_j_n from (select JACK_NUM from CTS_LIST_OF_JACKS where NOT EXISTS ( select jack from cts_server_jack_info where (cts_server_jack_info.jack = CTS_LIST_OF_JACKS.jack_num))) where JACK_NUM != :cas_sel_proj_id_item order by jack_num
LOOP
HTP.p ('<option value="' || c.a_j_n || '">' || c.b_j_n || '</option>');
END LOOP;
HTP.p('</select>');
END;
thanks,
gargi -
I have an oracle table with spatial index with the following details:
( Oracle 9i 9.2.0.4 )
SRS : 8265
Data Extents : -77.129588,38.815658 to -76.879555,38.985733
The SDO_GEOM_METADATA has the following entry
DIMINFO :SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -180, 180, .001111949), SDO_DIM_ELEMENT('Y',-90, 90, .001111949))
SRID :8265
I get no rows back with the following query
SELECT * FROM DCLANDMARKS WHERE
(MDSYS.SDO_RELATE(GEOLOC,
MDSYS.SDO_GEOMETRY(
2003, -- 2-dimensional polygon
8265,
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1), -- polygon with hole
MDSYS.SDO_ORDINATE_ARRAY(-91,-80, 91,-80, 91,80, -91,80,-91,-80)
),'QUERYTYPE=WINDOW MASK=ANYINTERACT') = 'TRUE')
However changing the ordinate array above to
MDSYS.SDO_ORDINATE_ARRAY(-90,-80, 90,-80, 90,80, -90,80,-90,-80)
Returns rows ? Seems like the extents for Y are being used for X ?
Any ideas ? - We have not been able to work around this one ???
ThanksHi,
Every geodetic (long/lat) polygon in Oracle must have area less than 1/2 the surface area of the earth. Both of your polygons as specified are illegal in spatial. The first one can be fixed changing the rotation of the ordinates in the ordinate array.
The second one is exactly 1/2 the surface area of the earth - you cannot code this polygon this way.
What you can do is change the geometry to a multipolygon, and break the geometry into two polygons, using it only with SDO_FILTER or SDO_RELATE with the anyinteract mask.
Hope this helps,
Dan -
WITH clause query:- Returns No Rows
Hi,
I am using the following query with, WITH clause, but some how it give "0 rows" returned,
The underlying query does returns row when run in stand alone mode,
With v_score_his_old
As
SELECT schs_run_date,schs_loc_shortcut_source,schs_lot_number,schs_facility_new,schs_facility_old, schs_operation_new,
schs_operation_old,schs_route_new,schs_route_old,schs_product_new,schs_product_old,schs_owner_old,schs_intransit,
schs_date,schs_transaction,schs_quantity_1_new,schs_quantity_1_old,/*0,*/schs_if_count_new,schs_if_count_old,
schs_preprocessed,schs_consumed_quantity,/*'Y',*/schs_if_id,schs_if_id_old,fif_fac_loc_id
FROM scm_score_his,full_item_facilities,location_params
WHERE schs_state = 0
AND fif_if_id = schs_if_id_old
AND lopo_param_value = to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB', 'SITE_SORT')
AND (schs_loc_shortcut_source = 'MP' OR schs_loc_shortcut_source = 'RE' OR schs_loc_shortcut_source = 'VI')
UNION ALL
SELECT schb_run_date,schb_loc_shortcut_source,schb_lot_number,schb_facility_new,schb_facility_old,schb_operation_new,
schb_operation_old,schb_route_new,schb_route_old,schb_product_new,schb_product_old,schb_owner_old,schb_intransit,
schb_date,schb_transaction,schb_quantity_1_new,schb_quantity_1_old,/*0,*/schb_if_count_new,schb_if_count_old,schb_preprocessed,
schb_consumed_quantity,/*'Y',*/schb_if_id,schb_if_id_old,fif_fac_loc_id
FROM scm_score_his_backups,full_item_facilities,location_params
WHERE schb_state = 0
AND fif_if_id = schb_if_id_old
AND lopo_param_value = to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB', 'SITE_SORT')
AND schb_date >= trunc(sysdate - 84)
AND (schb_loc_shortcut_source = 'MP' OR schb_loc_shortcut_source = 'RE' OR schb_loc_shortcut_source = 'VI')
Select schs_run_date,schs_loc_shortcut_source,schs_lot_number
From v_score_his_old
Where schs_loc_shortcut_source = 'MP';
Oracle version is Oracle9i Enterprise Edition Release 9.2.0.6.0
I am not able to get where I can going wrong.
Please help me to understand this issue,
Regards
Umesh..With v_score_his_old
As
SELECT
schs_run_date,schs_loc_shortcut_source,schs_lot_numbe
,schs_facility_new,schs_facility_old,
schs_operation_new,
chs_operation_old,schs_route_new,schs_route_old,schs_p
roduct_new,schs_product_old,schs_owner_old,schs_intran
sit,
chs_date,schs_transaction,schs_quantity_1_new,schs_qua
ntity_1_old,/*0,*/schs_if_count_new,schs_if_count_old,
chs_preprocessed,schs_consumed_quantity,/*'Y',*/schs_i
f_id,schs_if_id_old,fif_fac_loc_id
FROM
cm_score_his,full_item_facilities,location_params
WHERE schs_state = 0
AND fif_if_id = schs_if_id_old
AND lopo_param_value =
to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB',
'SITE_SORT')
AND (schs_loc_shortcut_source = 'MP' OR
schs_loc_shortcut_source = 'RE' OR
schs_loc_shortcut_source = 'VI')
UNION ALL
SELECT
schb_run_date,schb_loc_shortcut_source,schb_lot_number
,schb_facility_new,schb_facility_old,schb_operation_ne
w,
chb_operation_old,schb_route_new,schb_route_old,schb_p
roduct_new,schb_product_old,schb_owner_old,schb_intran
sit,
chb_date,schb_transaction,schb_quantity_1_new,schb_qua
ntity_1_old,/*0,*/schb_if_count_new,schb_if_count_old,
schb_preprocessed,
chb_consumed_quantity,/*'Y',*/schb_if_id,schb_if_id_ol
d,fif_fac_loc_id
FROM
cm_score_his_backups,full_item_facilities,location_par
ams
WHERE schb_state = 0
AND fif_if_id = schb_if_id_old
AND lopo_param_value =
to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB',
'SITE_SORT')
AND schb_date >= trunc(sysdate - 84)
AND (schb_loc_shortcut_source = 'MP' OR
schb_loc_shortcut_source = 'RE' OR
schb_loc_shortcut_source = 'VI')
ect
schs_run_date,schs_loc_shortcut_source,schs_lot_number
From v_score_his_old
Where schs_loc_shortcut_source = 'MP';
Hi!
I've a doubt. If u finally picking all the values which matched with field schs_loc_shortcut_source and which is 'MP' - then why r u using multiple condition in the WITH part? So, in that case, u don't have to write that additional filtering of the following lines in the outer query -
Where schs_loc_shortcut_source = 'MP';Regards.
Satyaki De. -
SQL query returns few rows, but holds on with several Gbs of RAM memory used
If I perform the following query:
SELECT d.DocumentGUID, d.DocumentID
FROM ImportDataBase.dbo.Document d
LEFT OUTER JOIN ContentDataBase.dbo.Document d2 ON (d.DocumentGUID = d2.DocumentGUID)
WHERE ( d2.DocumentGUID IS NULL ) -- new document in the ImportDB
OR ( d2.DocumentGUID IS NOT NULL AND d.QueryContent <> d2.QueryContent ) -- modified document in the ImportDB
It returns around 1000 rows and takes about 3 minutes to complete
It also raises up the RAM memory used from 2GB to 9GBs.
This memory used will remain used untill I restart the server. I have no need to make use of that memory, I already copied the returned rows of that query into a note pad for example. And any other reason of SQL has to to keep that memory stored by
that query, I dont want it.
Is there a way to release that memory I really dont need my SQL server to keep, without having to restart the SQL server?
and without topping the max memory the sql server uses, since I need my SQL server to use as much as it needs in other tasks(I dont think it needs to hold on to the above query memory used)
Thank You very much.Is there a way to release that memory I really dont need my SQL server to keep, without having to restart the SQL server?
and without topping the max memory the sql server uses, since I need my SQL server to use as much
A query can be resource intensive even if it returns a single row. Generally it is a good idea to set SQL Server MAX memory.
BOL: "Optimizing Server Performance Using Memory Configuration Options
The memory manager component of Microsoft SQL Server eliminates the need for manual management of the memory available to SQL Server. When SQL Server starts, it dynamically determines how much memory to allocate based on how much memory the operating system
and other applications are currently using. As the load on the computer and SQL Server changes, so does the memory allocated. For more information, see Memory Architecture.
The following server configuration options can be used to configure memory usage and affect server performance:
•min server memory
•max server memory
•max worker threads
•index create memory
•min memory per query
The min server memory server configuration option can be used to ensure that SQL Server does not release memory below the configured minimum server memory once that threshold is reached. This configuration option can be set to a specific value based on the
size and activity of your SQL Server. If you choose to set this value, set it to some reasonable value to ensure that the operating system does not request too much memory from SQL Server, which can affect SQL Server performance.
The max server memory server configuration option can be used to specify the maximum amount of memory SQL Server can allocate when it starts and while it runs. This configuration option can be set to a specific value if you know there are multiple applications
running at the same time as SQL Server and you want to guarantee that these applications have sufficient memory to run. If these other applications, such as Web or e-mail servers, request memory only as needed, then do not set the max server memory server
configuration option, because SQL Server releases memory to them as needed. However, applications often use whatever memory is available when they start and do not request more if needed. If an application that behaves in this manner runs on the same computer
at the same time as SQL Server, set the max server memory server configuration option to a value that guarantees that the memory required by the application is not allocated by SQL Server."
LINK:
http://technet.microsoft.com/en-us/library/ms177455(v=sql.105).aspx
Memory configuration:
http://www.sqlusa.com/bestpractices/memory-configuration/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
Why would this query return three rows?
select pc.tour_id,
pcp.project_id,
pc.contr_num,
pc.current_contr_status,
pc.current_contr_substat
from p_contract_lead pcl
left join p_contract pc on pc.contr_num = '2385108'--pcl.contr_num
left join p_contract_purchase pcp on pcp.contr_num ='2385108'-- pc.contr_num
where pcl.lead_id = '179772978'
in this query it returns me 3 rows,
in p_contract there is only 1 row with contr_num = '2385108'
and p_contract_purchase also has 1 row with contr_num = '2385108'
in p_contract_lead the lead_id = '179772978' has 3 records but they dont have contr_num=2385108
im just wondering why is giving me these results?
shouldnt it give me zero results since the pcl.lead_id = '179772978' does not equal contr_num=2385108?
i have version 12.0.0.6, maybe is the way i dont understand the left join works, or could be something else?
sorry for not creating a example , because i really dont know how.
thanks for your helpHi,
FROM l
LEFT OUTER JOIN r ON ...
means include all rows from l whether or not they have a match in r.
If you have 3 rows in l, then there will always be at least 3 rows in the result set, regardless of what's in r (if anything).
natpidgeon wrote:
in p_contract there is only 1 row with contr_num = '2385108'
and p_contract_purchase also has 1 row with contr_num = '2385108'
in p_contract_lead the lead_id = '179772978' has 3 records but they dont have contr_num=2385108
im just wondering why is giving me these results?
shouldnt it give me zero results since the pcl.lead_id = '179772978' does not equal contr_num=2385108? ...
What you just described is basically how an inner join works.
In this case, it doesn't matter in the least whether pcl.lead_id equals anything in pc or not. The join condition between pcl and pc is
pc.contr_num = '2385108'
That is, a row from pcl will match a row in pc if (and only if) pc.contr_num='2385108'. The join condition makes no mention of pcl.lead_id (or any other column in pcl, for that matter), so what's in pcl.lead_id (or any other column of pcl) doesn't play any role in deciding if rows match.
sorry for not creating a example , because i really dont know how.
Post CREATE TABLE statements for all 3 tables. You only need to include the columns that are used in this query.
Post 1 INSERT statement for p_contract, with contr_num = '2385108'. It wouldn't hurt to post an additional row that you know shouldn't appear in the results.
Post 1 INSERT statement for p_contract_purchase, also with contr_num = '2385108'. Again, it wouldn't hurt to post a 2nd row that does not meet the join condition.
Post 3 INSERT statements p_contract_lead with lead_id = '179772978' , but NOT contr_num='2385108'. Again, having another row with a different lead_id would make a better example. -
I have a problem with a query that includes 5 tables!
Equipment ec, (ec.cost, ec.workid)
Material mc, (mc.cost, mc.workid)
Labor lc, (lc.cost, lc.workid)
Work wo, (wo.workid)
Entity en
The primary key is the work id
The columns I need to extract are all the same - "cost"
The problem is that I need to extract the costs from all the tables (equipment/labor/material) where the work "id" is equal to the work "id".
The work table has a unique wo.workid but the other three tables can have
multiple nn.workid ('s).
This is the query I am working from at this time...
SELECT distinct wo.workid, wo.description, wo.supervisor, wo.acctnum,
wo.shop, wo.woaddress, wo.initiatedate,
TO_NUMBER (TO_CHAR (wo.initiatedate, 'MM')) AS mnth,
TO_NUMBER (TO_CHAR (wo.initiatedate, 'YYYY')) AS yr,
wo.actualfinishdate, wo.assetgroup, wo.unitsaccompdesc,
wo.unitsaccomplished,
sum(decode (lc.cost, 0, null, lc.cost)) labour_cost,
lc.laborname AS labour_name,
SUM (decode(mc.COST, 0, null, mc.cost)) AS material_cost,
mc.description AS mat_desc,
SUM (decode(ec.COST, 0, null, ec.cost)) AS equipment_cost,
ec.description AS equip_desc, en.module
FROM work wo,
equipment ec,
material mc,
labor lc,
entity en
WHERE (lc.COST <> 0 AND mc.COST <> 0 AND ec.COST <> 0)
AND wo.applytoentity = en.code
AND mc.workid = wo.workid
AND ec.workid = wo.workid
AND lc.workid = wo.workid
GROUP BY wo.workid,
wo.description,
wo.supervisor,
wo.acctnum,
wo.shop,
wo.woaddress,
wo.initiatedate,
wo.actualfinishdate,
wo.assetgroup,
wo.unitsaccompdesc,
wo.unitsaccomplished,
lc.COST,
lc.laborname,
mc.COST,
mc.description,
ec.COST,
ec.description,
en.module
any help would be appreciated!Hi John...
I am still getting duplicate values.
When the query grabs a value from the labour table it also grabs the values from the other tables and puts them in the same row... There are many rows in the three costs
tables and only one in the work table.
I have a dump of the rows but I cannot find a way to save it here.
Here is a cut down version of the data I am retrieving.
ID DESCRIPTION LAB MAT EQUIP
345 General Building Interior Maintenance Activities 136.60 59.89 133.60
345 General Building Interior Maintenance Activities 64.38 59.89 133.60
345 General Building Interior Maintenance Activities 42.92 59.89 133.60
345 General Building Interior Maintenance Activities 91.28 59.89 133.60
345 General Building Interior Maintenance Activities 374.24 59.89 133.60
345 General Building Interior Maintenance Activities 182.56 59.89 133.60
345 General Building Interior Maintenance Activities 175.68 59.89 133.60
345 General Building Interior Maintenance Activities 48.80 59.89 58.80
345 General Building Interior Maintenance Activities 89.48 59.89 58.80
345 General Building Interior Maintenance Activities 79.80 59.89 58.80
345 General Building Interior Maintenance Activities 294.88 59.89 58.80
345 General Building Interior Maintenance Activities 24.92 59.89 58.80
345 General Building Interior Maintenance Activities 147.44 59.89 58.80
345 General Building Interior Maintenance Activities 182.56 59.89 58.80
345 General Building Interior Maintenance Activities 98.59 59.89 58.80
345 General Building Interior Maintenance Activities 126.84 59.89 58.80
345 General Building Interior Maintenance Activities 55.00 59.89 6,656.00
345 General Building Interior Maintenance Activities 182.56 59.89 6,656.00
345 General Building Interior Maintenance Activities 98.59 59.89 6,656.00
345 General Building Interior Maintenance Activities 191.36 59.89 6,656.00
345 General Building Interior Maintenance Activities 136.60 59.89 66.96
345 General Building Interior Maintenance Activities 55.00 59.89 66.96
345 General Building Interior Maintenance Activities 491.04 59.89 66.96
345 General Building Interior Maintenance Activities 24.92 59.89 66.96
345 General Building Interior Maintenance Activities 182.56 59.89 66.96
345 General Building Interior Maintenance Activities 110.00 59.89 66.96
345 General Building Interior Maintenance Activities 162.80 59.89 66.96
345 General Building Interior Maintenance Activities 85.84 59.89 66.96
345 General Building Interior Maintenance Activities 65.44 59.89 66.96
345 General Building Interior Maintenance Activities 64.38 59.89 736.00
345 General Building Interior Maintenance Activities 79.80 59.89 736.00
Maybe you are looking for
-
How to to stop iPad mail from deleting email from server?
iPad 64 / Custom mail When I delete a mail from my iPad inbox, it is also deleted from my server. How do I configure To stop this? In other words, I like previewing my incoming email on my iPod, and I want to be able to keep my iPad email in box tidy
-
How to stop the option key from changing tools when trying to subtract from a selection?
How to stop the option key from changing my tools when I am trying to subtract from a selection? I'm running CS3 on Mac OS Leopard, and the automatic tool switching slows me down, but even preferences doesn't show a way to turn this off. Thanks for y
-
Merging pdfs with ability to edit a form
When I merge two pdfs in Acrobat 8 then reopen them in Reader (which is the only software my client has to view/edit pdfs) I can no longer save the data typed into the forms--I can print the document as is with the information, but the pdf form needs
-
I'm going to Chicago for a couple nights (I live in Michigan) and I was wondering if my iPhone will still work in another state or not. I'm assuming yes, but I would just like to double check. Thanks!
-
Printing a Vector to a JTextArea
I'm having major problems with my project. I can't get the information retrieved from a database to print to a JTable even though i've looked at so many different tutorials. I ended up printing the information to a JTextArea for now but i'm having pr