SQL Query to Fetch 500 Rows at once
Hi,
Due to performance issue of the SQL query takes lot of time to execute. I tried modifying the code as mentioned below but it is not working to fetch when search is implemented. Actually data is more than 1 Million Records so it takes lot of time to query the data.
SELECT DISTINCT
IMV.*,
nvl(imv.party_name,imv.bill_to_name) "Bill To Name",
Imv.Ship_To_City "Reseller City",
Imv.Ship_To_State "Reseller State",
Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
Cl.City "Customer City",
Cl.State "Customer State",
EDB2_GLOBAL.COUNTRY_NAME_THEATER(CL.COUNTRY,'COUNTRY') "Customer Country",
EDB2_GLOBAL.COUNTRY_NAME_THEATER(CL.COUNTRY,'THEATER') "Customer Theater"
FROM IB_SUPPORT_CONTRACTS_MV IMV,
customer_products cp,
customer_locations cl
WHERE
UPPER(TRIM(IMV.SERIAL_NUMBER)) = UPPER(TRIM(CP.PRODUCT_SERIAL_NUMBER(+) ) )
AND CP.LOCATION_ID = CL.LOCATION_ID(+)
AND ROWNUM <= 501
Please suggest me how to improve the performance of the query.
Thanks
Sudhir
Hi,
As mentioned already, this condition is really hurting performance:
UPPER(TRIM(IMV.SERIAL_NUMBER)) = UPPER(TRIM(CP.PRODUCT_SERIAL_NUMBER(+) ) )
Could you trim and capitalize the serial numbers before storing them? Do you really need to remember exactly how the serial numbers were entered? If you really do, then store it in one column, and store UPPER (TRIM (serial_number)) in a different column. Starting in Oracle 11, this could be a virtual column; in any version (7 or higher), it could be maintained by a trigger. Failing that, create a function-based index on UPPER (TRIM (serial_number)).
Similar Messages
-
SQL query to fetch 2 rows in one
Hi, following is sample data:
COLLMETHID EEID XORDERID AMOUNT
BREDM 3136 3435698 3000
VISA 3136 3435698 7190
BREDM 6607 3519115 1492
BREDM 6614 3558451 1500
VISA 6614 3558451 149
BREDM 6616 3567631 2120
VISA 6616 3567631 158
BREDM 8356 3558864 899
And I need this result:
xorderid eeid coll1 coll2 sum_AMOUNT
3435698 3136 BREDM VISA 10190
3519115 6607 BREDM null 1492
3558451 6614 BREDM VISA 2992
please help me
Amitesh
Its very urgent. My project's UAT is blocking due to this bug.
Amiteshthis may help
QL> With t As
2 (
3 Select 'BREDM' c1, 3136 eid , 3435698 Xid, 3000 amt From dual Union All
4 Select 'VISA', 3136, 3435698, 7190 From dual Union All
5 Select 'BREDM', 6607, 3519115, 1492 From dual Union All
6 Select 'BREDM', 6614, 3558451, 1500 From dual Union All
7 Select 'VISA', 6614, 3558451, 149 From dual Union All
8 Select 'BREDM', 6616, 3567631, 2120 From dual Union All
9 Select 'VISA', 6616, 3567631, 158 From dual Union All
10 Select 'BREDM', 8356, 3558864, 899 From dual
11 )
12 Select Distinct
13 eid,
14 Xid,
15 first_value(c1) over (Partition By eid, Xid Order By eid) "c1",
16 last_value(c1) over (Partition By eid, Xid Order By eid) "c2" ,
17 Sum (amt ) over (Partition By eid, Xid) "amt"
18 From t;
EID XID c1 c2 amt
6616 3567631 BREDM VISA 2278
8356 3558864 BREDM BREDM 899
6607 3519115 BREDM BREDM 1492
6614 3558451 BREDM VISA 1649
3136 3435698 BREDM VISA 10190
OR
SQL> With t As
2 (
3 Select 'BREDM' c1, 3136 eid , 3435698 Xid, 3000 amt From dual Union All
4 Select 'VISA', 3136, 3435698, 7190 From dual Union All
5 Select 'BREDM', 6607, 3519115, 1492 From dual Union All
6 Select 'BREDM', 6614, 3558451, 1500 From dual Union All
7 Select 'VISA', 6614, 3558451, 149 From dual Union All
8 Select 'BREDM', 6616, 3567631, 2120 From dual Union All
9 Select 'VISA', 6616, 3567631, 158 From dual Union All
10 Select 'BREDM', 8356, 3558864, 899 From dual
11 )
12 Select Distinct
13 eid,
14 Xid,
15 first_value(c1) over (Partition By eid, Xid Order By eid) "c1",
16 Case When last_value(c1) over (Partition By eid, Xid Order By eid)
17 = first_value(c1) over (Partition By eid, Xid Order By eid)
18 Then Null
19 Else last_value(c1) over (Partition By eid, Xid Order By eid)
20 End "c2" ,
21 Sum (amt ) over (Partition By eid, Xid) "amt"
22 From t;
EID XID c1 c2 amt
6616 3567631 BREDM VISA 2278
6614 3558451 BREDM VISA 1649
3136 3435698 BREDM VISA 10190
8356 3558864 BREDM 899
6607 3519115 BREDM 1492Message was edited by:
Nicloei W -
SQL query to fetch WIP jobs agains a customer
Hi All,
Can anyone please help me with a SQL query to fetch WIP jobs agains a customer.
Regards,
ShrutiIf you are using ATO functionality and if you are reserving sales orders to work orders, you can link them as follows
Using customer name, identify the open sales order headers and lines.
For each line, query reservations (mtl_reservations) using demand id fields.
For those reservations where supply = wip job, use the supply id fields and get wip_entity_id.
Using wip_entity_id, get wip_entity_name(job#) from wip_entities table.
Once a job is completed, this link is lost.
Sandeep Gandhi -
SQL query to fetch records from 26 onwards
Want to know SQL query to fetch records from 26 onwards.
See the fifth entry on the FAQ page:
Re: How to attach a java bean in forms6i -
How will write SQL query to fetch data from each Sub-partition..
Hi All,
Anyone does have any idea about How to write SQL query to fetch data from Sub-partition.
Actually i have one table having composite paritition(Range+list)
Now if i want to fetch data from main partition(Range) the query will be
SELECT * FROM emp PARTITION(q1_2005);
Now i want to fetch data at sub-partition level(List) .But i am not able to get any SQL query for that.
Pls help me to sort out.
Thanks in Advance.
AnwarSELECT * FROM emp SUBPARTITION(sp1);
-
SQL query to fetch approximately 9000 rows
Hi,
I am using the following SQL query in a java class. Using JDBC to connect to an Oracle database using JRUN app server connection pooling.
SELECT PT.ACCOUNT_NUMBER,PAYMENT_REF_ID, TO_CHAR (PT.DATE_CREATED, 'MM/DD/YYYY'),
PT.AMOUNT_PAID, DECODE(STATUS_VALUE,'Cancelled','Canceled',STATUS_VALUE)
FROM EPAY_PAYMENT_TRANSACTIONS PT, EPAY_STATUS_LOOKUP SL
WHERE
PT.CLIENT_NAME = 'someclientname'
AND TO_CHAR(DATE_PAYMENT_SCHEDULED,'MM/DD/YYYY') = '08/28/2006'
AND PT.PAYMENT_STATUS = SL.STATUS_CODE
ORDER BY PT.DATE_CREATED DESC
EPAY_PAYMENT_TRANSACTIONS is a huge table consisting of thousands of rows. There are 4 indexes defined on this table but not on the columns used in the join condition of the query.
EPAY_STATUS_LOOKUP is a much smaller table mainly used for lookup consisting of some 100 rows.
The above query fetches approx 9000 records and takes a very long time to execute. Is there any way it can be optimized or we can change some attributes on the tables involved for speeding up the query?
Thanks in advance,
Nisha.So the task is to avoid FTS on EPAY_PAYMENT_TRANSACTIONSWell, maybe...
But I believe that we have yet to hear more details about data distribution, execution plans and so on.
Because it all depends...
Consider simple testcase:
SQL> select * from v$version where rownum = 1;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
SQL> -- Create "small" table
SQL>
SQL> create table build_t as
2 select rownum x,
3 rpad('*', 200, '*') padding
4 from dual
5 connect by level <= 100;
Table created.
SQL> -- Create "large" table - initially, add 9000 rows which satisfy join criteria
SQL>
SQL> create table probe_t as
2 select mod(rownum - 1, 100) + 1 x,
3 dbms_random.value y,
4 rpad('*', 200, '*') padding
5 from dual
6 connect by level <= 9000;
Table created.
SQL> -- Now, add some extra rows to large table - "thousands of rows"
SQL>
SQL> insert into probe_t
2 select rownum + 100,
3 0,
4 rpad('*', 200, '*') padding
5 from dual
6 connect by level <= 100000;
100000 rows created.
SQL> exec dbms_stats.gather_table_stats(user, 'BUILD_T')
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats(user, 'PROBE_T')
PL/SQL procedure successfully completed.
SQL> -- Ok, let's measure ...
SQL>
SQL> set autot traceonly
SQL>
SQL> select a.*, b.*
2 from build_t a,
3 probe_t b
4 where a.x = b.x
5 order by b.y;
9000 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1387 Card=109 Bytes=45017)
1 0 SORT (ORDER BY) (Cost=1387 Card=109 Bytes=45017)
2 1 HASH JOIN (Cost=1386 Card=109 Bytes=45017)
3 2 TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
4 2 TABLE ACCESS (FULL) OF 'PROBE_T' (Cost=1355 Card=109000 Bytes=22781000)
Statistics
0 recursive calls
0 db block gets
3280 consistent gets
0 physical reads
0 redo size
360756 bytes sent via SQL*Net to client
7096 bytes received via SQL*Net from client
601 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
9000 rows processedOn my server, this query finished in less that second and took 3280 LIO to complete.
Now, which index did you mean to build? I guess it's and index on join column, isn't it?
If so - let's build it and measure again:
SQL> create index idx_probe_t on probe_t(x);
Index created.
SQL> select /*+ ORDERED USE_NL(a b) */
2 a.*, b.*
3 from build_t a,
4 probe_t b
5 where a.x = b.x
6 order by b.y;
9000 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=211 Card=109 Bytes=45017)
1 0 SORT (ORDER BY) (Cost=211 Card=109 Bytes=45017)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'PROBE_T' (Cost=3 Card=1 Bytes=209)
3 2 NESTED LOOPS (Cost=210 Card=109 Bytes=45017)
4 3 TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
5 3 INDEX (RANGE SCAN) OF 'IDX_PROBE_T' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
0 db block gets
9124 consistent gets
21 physical reads
0 redo size
360756 bytes sent via SQL*Net to client
7096 bytes received via SQL*Net from client
601 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
9000 rows processedLook at this - 9124 consistent gets, almost three times larger than in case of hash join.
Full table scan is not something to be avoided at all cost.
Indexing - sometimes it is good,
sometimes it's just useless,
sometimes it only makes things worse...
It all depends on underlying data distribution. That's why I asked user527580 to tell us more.
Kind regards. -
SQL query to fetch Online Payslip Details
Hi All,
First of all "Happy Diwali" to you all and sorry for asking too much. Actually I need to develope an SQL query which will fetch all the details that appears in online payslip(employee self service) including employee details, earning and deduction elements their value, TAX deducted, absence details etc. And the details should match exactally to our online payslip details.
I am sure many of you have come across this requirement and have developed this already. If you still have that query could you please pass it to me. I know expecting a readymade sql query would be too much and therefore just let me know all the tables I need use for this so that I can start writting query by my own. Actually any help in this regard will be much appreciated.
P.S. We are still using 11i :-(
Thank you all once again,
AvinashHi All,
Thank you all for your help on this. The forum was really helpful to get answer of my question. I have almost got answer to all my question. Hence marking this "Answered" :-) I have prepared some sql which fetches the information from PAY_ACTION_INFORMATION for Australia legislation and would like to share it with you all so that you can utalize it if needed.
------------ For Employee Details ---------------------------------------
select pai.action_information1 "Employee"
,pai.action_information18 "Employer Name"
,pai.action_information10 "Employee Number"
,pai.action_information19 "Position"
,pai.action_information14 "Assignment Number"
,pai.action_information17 "Job"
,pai.action_information7 "Grade Step"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'EMPLOYEE DETAILS'
and action_context_id = &action_context_id
------------ for IBN Number ----------------------------------------------
select pai.action_information21 "Employer ABN"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'AU EMPLOYEE DETAILS'
and action_context_id = &action_context_id
------- For Balances ------------------------------------------------------
select pai.action_information1 "Description"
,pai.action_information4 "YTD"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC BALANCES'
and action_context_id = &action_context_id
--------- Taxable Earning ------------------------------
select pai.action_information1 "Description"
,pai.action_information9 "Rate"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ELEMENTS'
and action_information4 = 'Taxable Earnings'
and action_context_id = &action_context_id
----------- Pre Tax Deduction -------------
select pai.action_information1 "Description"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ELEMENTS'
and action_information4 = 'Pre Tax Deductions'
and action_context_id = &action_context_id
--------------- Non Taxable Earnings -----------
select pai.action_information1 "Description"
,pai.action_information9 "Rate"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ELEMENTS'
and action_information4 = 'Non Taxable Earnings'
and action_context_id = &action_context_id
--------- for Tax Deductions ----------------------
select pai.action_information1 "Description"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ELEMENTS'
and action_information4 = 'Tax Deductions'
and action_context_id = &action_context_id
---------- Post Tax Deductions -----------------
select pai.action_information1 "Description"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ELEMENTS'
and action_information4 = 'Post Tax Deductions'
and action_context_id = &action_context_id
--------- Employer Superannuation Contributions ----------------------
select pai.action_information1 "Superannuation Fund Name"
,pai.action_information5 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ELEMENTS'
and action_information4 = 'Employer Superannuation Contributions'
and action_context_id = &action_context_id
----------- Payments -----------------------------
select pai.action_information18 "Payment Method"
,pai.action_information6 "Account Number"
,pai.action_information16 "Payment Amount"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'EMPLOYEE NET PAY DISTRIBUTION'
and action_context_id = &action_context_id
------------- Other Pay Advice Information ------------
select pai.action_information14 "Description"
,pai.action_information6 "Value"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'EMPLOYEE OTHER INFORMATION'
and action_information2 = 'ELEMENT'
and action_context_id = &action_context_id
-------------------- Other Balance Information -----------
select pai.action_information14 "Description"
,pai.action_information6 "Value"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'EMPLOYEE OTHER INFORMATION'
and action_information2 = 'BALANCE'
and action_context_id = &action_context_id
------------------- Pay Period and Salary ------------
select pai.action_information28 "Annual Salary"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'EMPLOYEE DETAILS'
--and action_information2 = 'BALANCE'
and action_context_id = &action_context_id
--------------- Annual Leave Information ------------
select pai.action_information1 "Name"
,decode(pai.action_information5,'D','Day','H','Hours') "Unit"
,pai.action_information4 "Balance"
from apps.pay_action_information pai
where 1 = 1
and pai.action_information_category = 'APAC ACCRUALS'
and action_context_id = &action_context_id
----------- Message to Employee -----------
select pai.action_information6 "Message to Employee"
from apps.pay_action_information pai
where 1 = 1
and action_information_category = 'EMPLOYEE OTHER INFORMATION'
and action_information2 = 'MESG'
and action_context_id = &action_context_id
---------------- Leave Taken -------------
select pai.action_information2 "Name"
,pai.action_information4 "Start Date"
,pai.action_information5 "End Date"
,pai.action_information6 "Amount Taken"
,pai.action_information8 "This Pay"
from apps.pay_action_information pai
where 1 = 1
and action_information_category = 'APAC ABSENCES'
and action_context_id = &action_context_id
Thanks,
Avinash -
SQL Query to convert multiple rows to a single row output
I have the following sql query;
SELECT B.ClientID,
B.BillNo, B.[BillDate],
B.CurrencyCode,
B.BAmount
FROM tblCompanyDetails CD
CROSS
APPLY (
SELECT TOP 5 B1.ClientID,
B1.[BillNumber],
B1.[BillDate], B1.[CurrencyCode] AS CCY,
B1.[BillAmount]
FROM tblBills B1
WHERE ROUND(B1.[BillAmount],2)<>0
AND B1.ClientID=CD.CompanyID
AS B
WHERE CD.ContactId=235405
ORDER
BY B.ClientID,B.BillNo
DESC
This gives me the following row output;
ClientID
BillNo
BillDate
CurrencyCode
BAmount
94466
425616
2015-04-07
GBP
5000
94466
424517
2015-01-15
GBP
6000
94466
424455
2014-10-15
GBP
4000
However, I would like the ouput to appear like this;
ClientID
BillNo1
BillDate
CCY
BAmount
BillNo2
BillDate
CCY
BAmount
BillNo3
BillDate
CCY
BAmount
94466
425616
2015-04-07
GBP
5000
424517
2015-01-15
GBP
6000
424455
2014-10-15
GBP
4000I have tried to create a sample based on your question
CREATE TABLE MyTable
ClientID INT ,
BillNo INT,
BillDate DATE,
CurrencyCode varchar(5),
BAmount INT
INSERT INTO MyTable
VALUES (94466,425616,'2015-04-07','GBP',5000),
(94466,424517,'2015-01-15','GBP',6000),
(94466,424455,'2014-10-15','GBP',4000)
Then I have used another table to put ranking in that, you can actually tweak your statement to include rank also
CREATE TABLE RowTable
ClientID INT ,
BillNo INT,
BillDate DATE,
CurrencyCode varchar(5),
BAmount INT,
Ranking INT
INSERT INTO RowTable
SELECT * , ROW_NUMBER() OVER (ORDER BY ClientID) as row
FROM MyTable
Once your data is ready then execute below dynamic query
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(col+cast(Ranking as varchar(10)))
from RowTable
cross apply
select 'BillNo', 1 union all
select 'BillDate', 2 union all
select 'CurrencyCode', 3 union all
select 'BAmount' , 4
) c (col, so)
group by col, so, Ranking
order by Ranking, so
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT ClientId,' + @cols + '
from
select clientid, col+cast(Ranking as varchar(10)) col, value
from RowTable
cross apply
SELECT ''BillNo'', cast(BillNo as varchar(20)) union all
SELECT ''BillDate'', cast(BillDate as varchar(20)) union all
SELECT ''CurrencyCode'', CurrencyCode union all
SELECT ''BAmount'', CAST(BAmount as varchar(10))
) c (col, value)
) x
pivot
max(value)
for col in (' + @cols + ')
) p '
execute sp_executesql @query;
Output:
Hope this will help. -
SQL Query to fetch a specific field in xml
Hi,
Below is my sample Xml file.
<?xml version = "1.0" encoding = "UTF-8"?>
<methodCall xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd">
<methodName>rBatchFile </methodName>
<params>
<param>
<value>
<struct>
<member>
<name>filename</name>
<value>
D:\test.txt
</value>
</member>
<member>
<name>batchId</name>
<value>
L1
</value>
</member>
</struct>
</value>
</param>
</methodName>
</methodCall>
I want to query a "value" field based on the "name" field. I tried with the following query which didnt work.
SELECT a.extract('//value/text()' , 'xmlns:="http://www.tibco.com/schemas/CS4_new1/Schema.xsd" ')
FROM ( SELECT t.customerinfo.extract('//member[name="filename"]','xmlns:="http://www.tibco.com/schemas/CS4_new1/Schema.xsd" ')
FROM cust_order t ) a;
Please do provide the SQL query ASAP.with tab as (
select xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
<methodCall xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd">
<methodName>rBatchFile </methodName><params>
<param>
<value>
<struct>
<member>
<name>filename</name>
<value>
D:\test.txt
</value>
</member>
<member>
<name>batchId</name>
<value>
L1
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
') a from dual
--end of sample data
SELECT
extractvalue(column_value,'/member/name') name,
extractvalue(column_value,'/member/value') value
from tab t,xmltable('xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd"','for $i in //member return $i' passing t.a)An example...but i tweaked the xml...check the xml namespace once before executing...
without adding the namespaces...code will be like...
with tab as (
select xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
<methodCall >
<methodName>rBatchFile </methodName><params>
<param>
<value>
<struct>
<member>
<name>filename</name>
<value>
D:\test.txt
</value>
</member>
<member>
<name>batchId</name>
<value>
L1
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
') a from dual
--end of sample data
SELECT
extractvalue(column_value,'/member/name') name,
extractvalue(column_value,'/member/value') value
from tab t,xmltable('for $i in //member return $i' passing t.a)Ravi Kumar -
SQL Query updateable report with row selector. Update process.
I have a SQL Query updateable report with the row selector(s).
How would I identify the row selector in an update process on the page.
I would like to update certain columns to a value of a select box on the page.
Using the basic:
UPDATE table_name
SET column1=value
WHERE some_column=some_value
I would need to do:
UPDATE table_name
SET column1= :P1_select
WHERE [row selector] = ?
Now sure how to identify the [row selector] and/or validate it is checked.
Thanks,
BobI don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
It should be like
<input id="..." value="" type="checkbox" name="fXX" >we are interested in the name attribute , get that number (between 01 and 50)
Replace that number in the code, for instance if it was f05 , the code would use
apex_application.g_f05
--i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record. -
SQL query to fetch the catalog category for a PLM item
Hi All,
Can anyone help me with a sql query of how we can fetch the catalog category for a PLM item.
Regards,
ShrutiHi,
You could monitor the SMSProv.log when you check the category of an application. It shows that SQL query the SCCM provider used is related to function fn_ListCategoryInstances.
Best Regards,
Joyce -
Sql query to fetch data based on date conditons
Hi All,
We have to schedule a script that runs at 1:00 AM from Monday to Friday.
The script will run a sql query ,that will fetch the data from sql database 2008 based on the below conditions.
Case 1: If date = current Date then retrieve the data of the previous Date.
Case 2: If date = Monday then retrieve the entries of Friday ,Saturday and Sunday.
Please help us on how we can achieve this.
ThanksHi,
Are you asking about Patrick's
solution?
If so I highly recommend NOT to use this solution. PLease read LMU92's
and
Visakh16's responses.
Why not to use it?
1. This solution is not deterministic!
A deterministic algorithm is an algorithm which, given a particular input, will always produce the same output. This solution give different values for different setting! It is depending for example on "SET LANGUAGE" value
As mentioned above if you try to use any other languge then English then this query will not work since you will never get the value "Sunday"
2. Moreover! Even if you are using "SET LANGUAGE 'English'" then this
solution depend on "SET DATEFIRST" and only take into consideration that the value can be 1 or 7, using any other value you will get that @weekendDateMod is null!
What can you use?
let's test some value first to get the solution yourself. We know that we don't care about "SET LANGUAGE" since I will not use any language dependency but we need to examine "SET DATEFIRST". Try to change the value from 1 to 7 and check
the value of this query
SET DATEFIRST 1 -- Change this value from 1 to 7!
DECLARE @Sunday DATE = '2014-08-03' -- This is Sunday
DECLARE @Munday DATE = '2014-08-04' -- This is Munday
SELECT DATEPART(DW,@Sunday),DATEPART(DW,@Munday), @@DATEFIRST
Can you see the behavior ?
The results are hidden here (select the text and you will see them)
DATEFIRST___Sunday_______Monday
1___________7___________1
2___________6___________7
3___________5___________6
4___________4___________5
5___________3___________4
6___________2___________3
7___________1___________2
assuming you did the exercise above yourself, then you can now think now what is the filter that you need...
You can use a filter on those two parameters together using "where DATEPART... and @@DATEFIRST...) or using one combine check. Can you think how?
Notice that this value is always 2 on Monday! Regarding our setting
(DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7
Please Don't Go Down Before YOu Understand!
Now we can go to the solution
* I really hope that you read all and did the small exercise yourself! You can not become a developer by copy answers, and this is the reason that from the start I only gave you tha way and not the final query!
DECLARE @CurrentDate DATE = '2007-08-20' -- This is only for testing since you should use the function GETDATE() instead
DECLARE @MinDateToFilter DATE
SET @MinDateToFilter = CASE
WHEN ((DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7) = 2 THEN DATEADD(DAY,-4,@CurrentDate)
ELSE DATEADD(DAY,-1,@CurrentDate)
END
SELECT *
FROM sales.salesOrderHeader
WHERE orderDate > @MinDateToFilter
I hope this was useful :-)
[Personal Site] [Blog] [Facebook] -
Hi,
I am to trying to fetch session id of a previously submitted process of a search button......so that i can display the search results in a different page.....so is there any sql query or pl/sql procedure to fetch the session id.>
Please update your forum profile with a real handle instead of "968337".
I am to trying to fetch session id of a previously submitted process of a search button......It's not all clear what you are trying to do. The documentation describes an APEX session and its ID thus:
>
A session is a logical construct that establishes persistence (or stateful behavior) across page views. Each session is assigned a unique identifier. The Application Express engine uses this identifier (or session ID) to store and retrieve an application's working set of data (or session state) before and after each page view.
>
This means that each page view and page submission does not have its own session ID, but uses the session ID established when the user's current session began (which is usually through logon and authentication).
Given this definition of session and session ID, are you therefore referring to the ID of some previous user session in which a page was submitted by a search button? Or some private meaning that you have yet to fully explain?
so that i can display the search results in a different page.....so is there any sql query or pl/sql procedure to fetch the session id.The session ID of the current session is available using the the built-in substitution string<tt>APP_SESSION</tt> built-in substitution string.
When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
<li>Full APEX version
<li>Full DB/version/edition/host OS
<li>Web server architecture (EPG, OHS or APEX listener/host OS)
<li>Browser(s) and version(s) used
<li>Theme
<li>Template(s)
<li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
Following the guidelines in these documents will also help to explain the problem in much more detail and with sufficient background for it to be understood:
<li>+How to ask questions+
<li>+{message:id=9360002}+
With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand. -
SQL query Output exceeds 65000 rows in excel
Hi,
I have a SQL file attached to my concurrent program. The query in the SQL file returns tab separated output that i need to email as a csv through the same SQL file.
The issue I am facing is that the query returns about 157000 records but only 65536 are being displayed in the excel worksheet.
How can I get all the records by accommodating them in multiple worksheets of the same excel file?
Please help!
I am using EBS 11i.
Code I am using in SQL file:
set pages 3000
set lines 300
set heading off
set term off
set feedback off
set verify off
set echo off
set serverout off
spool /tmp/TEST.csv
select 'Header'
from dual
SELECT column1||CHR(9)||column2
FROM staging_table
spool off
set lines 1000 pages 40 head off echo off veri off
select 'cd /tmp; cat $XX_TOP/install/sql/disclaimer.txt > x.dat; cat '||'/tmp/TEST.csv'||' | uuencode '||'/tmp/TEST.csv'
||' > '||substr('/tmp/TEST.csv',1,length('/tmp/TEST.csv')-4)||'.dat >> x.dat'
||' ; mail -s ''' ||'&1'||''' '||'&2'||' < x.dat'
||' ; rm '||substr('/tmp/TEST.csv',1,length('/tmp/TEST.csv')-4)||'.dat'||' ;'
from dual
list
spool /tmp/email.txt
spool off
host chmod 777 /tmp/email.txt
host /tmp/email.txt
Thanks
Edited by: user10648285 on May 13, 2011 5:27 AMopen a blank Excel (2007 version), go to Data tab, then from External Data click From Text, select the CSV file (That having more than 65k records), click import, then from "start import at row" select 65001 and click next button, select delimiter as Comma, click Next button and filaly finish.
In this way you will have the data after 65k rows in excel. Now you can simply open that cvs file in excel then you will have first 65k records (remening part will be discarded).
So now you have two excel files and you can paste it in two diff tab.
Note - you can repeate this activity if you have more than 130000 records... -
Can you please explain how this query is fetching the rows?
here is a query to find the top 3 salaries. But the thing is that i am now able to understand how its working to get the correct data :How the data in the alias table P1 and P2 getting compared. Can you please explain in some steps.
SELECT MIN(P1.SAL) FROM PSAL P1, PSAL P2
WHERE P1.SAL >= P2.SAL
GROUP BY P2.SAL
HAVING COUNT (DISTINCT P1.SAL) <=3 ;
here is the data i used :
SQL> select * from psal;
NAME SAL
able 1000
baker 900
charles 900
delta 800
eddy 700
fred 700
george 700
george 700
Regards,
Renu... Please help me in understanding the query.
Your query looks like anything but a Top-N query.
If you run it in steps and analyze the output at the end of each step, then you should be able to understand what it does.
Given below is some brief information on the same:
test@ora>
test@ora> --
test@ora> -- Query 1 - using the non-equi (theta) join
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT p1.sal AS p1_sal, p1.NAME AS p1_name, p2.sal AS p2_sal,
12 p2.NAME AS p2_name
13 FROM psal p1, psal p2
14 WHERE p1.sal >= p2.sal;
P1_SAL P1_NAME P2_SAL P2_NAME
1000 able 1000 able
1000 able 900 baker
1000 able 900 charles
1000 able 800 delta
1000 able 700 eddy
1000 able 700 fred
1000 able 700 george
1000 able 700 george
900 baker 900 baker
900 baker 900 charles
900 baker 800 delta
900 baker 700 eddy
900 baker 700 fred
900 baker 700 george
900 baker 700 george
900 charles 900 baker
900 charles 900 charles
900 charles 800 delta
900 charles 700 eddy
900 charles 700 fred
900 charles 700 george
900 charles 700 george
800 delta 800 delta
800 delta 700 eddy
800 delta 700 fred
800 delta 700 george
800 delta 700 george
700 eddy 700 eddy
700 eddy 700 fred
700 eddy 700 george
700 eddy 700 george
700 fred 700 eddy
700 fred 700 fred
700 fred 700 george
700 fred 700 george
700 george 700 eddy
700 george 700 fred
700 george 700 george
700 george 700 george
700 george 700 eddy
700 george 700 fred
700 george 700 george
700 george 700 george
43 rows selected.
test@ora>
test@ora>This query joins PSAL with itself using a non equi-join. Take each row of PSAL p1 and see how it compares with PSAL p2. You'll see that:
- Row 1 with sal 1000 is >= to all sal values of p2, so it occurs 8 times
- Row 2 with sal 900 is >= to 9 sal values of p2, so it occurs 7 times
- Row 3: 7 times again... and so on.
- So, total no. of rows are: 8 + 7 + 7 + 5 + 4 + 4 + 4 + 4 = 43
test@ora>
test@ora> --
test@ora> -- Query 2 - add the GROUP BY
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT p2.sal AS p2_sal,
12 COUNT(*) as cnt,
13 COUNT(p1.sal) as cnt_p1_sal,
14 COUNT(DISTINCT p1.sal) as cnt_dist_p1_sal,
15 MIN(p1.sal) as min_p1_sal,
16 MAX(p1.sal) as max_p1_sal
17 FROM psal p1, psal p2
18 WHERE p1.sal >= p2.sal
19 GROUP BY p2.sal;
P2_SAL CNT CNT_P1_SAL CNT_DIST_P1_SAL MIN_P1_SAL MAX_P1_SAL
700 32 32 4 700 1000
800 4 4 3 800 1000
900 6 6 2 900 1000
1000 1 1 1 1000 1000
test@ora>
test@ora>Now, if you group by p2.sal in the output of query 1, and check the number of distinct p1.sal, min of p1.sal etc. you see that for p2.sal values - 800, 900 and 1000, there are 3 or less p1.sal values associated.
So, the last 3 rows are the ones you are interested in, essentially. As follows:
test@ora>
test@ora> --
test@ora> -- Query 3 - GROUP BY and HAVING
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT p2.sal AS p2_sal,
12 COUNT(*) as cnt,
13 COUNT(p1.sal) as cnt_p1_sal,
14 COUNT(DISTINCT p1.sal) as cnt_dist_p1_sal,
15 MIN(p1.sal) as min_p1_sal,
16 MAX(p1.sal) as max_p1_sal
17 FROM psal p1, psal p2
18 WHERE p1.sal >= p2.sal
19 GROUP BY p2.sal
20 HAVING COUNT(DISTINCT p1.sal) <= 3;
P2_SAL CNT CNT_P1_SAL CNT_DIST_P1_SAL MIN_P1_SAL MAX_P1_SAL
800 4 4 3 800 1000
900 6 6 2 900 1000
1000 1 1 1 1000 1000
test@ora>
test@ora>
test@ora>That's what you are doing in that query.
The thing is - in order to find out Top-N values, you simply need to scan that one table PSAL. So, joining it to itself is not necessary.
A much simpler query is as follows:
test@ora>
test@ora>
test@ora> --
test@ora> -- Top-3 salaries - distinct or not; using ROWNUM on ORDER BY
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT sal
12 FROM (
13 SELECT sal
14 FROM psal
15 ORDER BY sal DESC
16 )
17 WHERE rownum <= 3;
SAL
1000
900
900
test@ora>
test@ora>
test@ora>And for Top-3 distinct salaries:
test@ora>
test@ora> --
test@ora> -- Top-3 DISTINCT salaries; using ROWNUM on ORDER BY on DISTINCT
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT sal
12 FROM (
13 SELECT DISTINCT sal
14 FROM psal
15 ORDER BY sal DESC
16 )
17 WHERE rownum <= 3;
SAL
1000
900
800
test@ora>
test@ora>
test@ora>You may also want to check out the RANK and DENSE_RANK analytic functions.
RANK:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions123.htm#SQLRF00690
DENSE_RANK:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions043.htm#SQLRF00633
HTH
isotope
Maybe you are looking for
-
IPod touch "slide to unlock" not responding, same with "slide to power off."
I'm trying to fix my friend's iPod 5. As of last night she said that her iPod will not slide to unlock, as if the touchscreen is unresponsive. However, assistive touch is turned on and that functions fine. The device also cannot be powered down,
-
Updated original iPhone to OS 3.0 don't even have the App Icon now!
Updated original iPhone to OS 3.0 now most APPs are missing ? ! Anything I can do?
-
Any ideas on how to get this old game working on the newer model computer? The message I get is that it wont run it "because Classic environment is no longer supported".
-
Hello, I've been trying to open an IMovie in my MacBook Pro that I transferred from my IPad through ITunes. However I receive the following message from the IMovie: This version of iMovie cannot import Trailers created in iMovie for iOS. I have
-
New rows in Adobe table are not added to WD Context
Hi experts: we have several Adobe Interactive forms. Each has a table. the user can add rows to the table, but when they do, the WD ABAP context does not get additional rows added to it. The new rows appear on the form, but not in the context. If