SQL Query to return multiple transactions in a 5 min. period
I have been asked to write a query that scans a table of financial transactions looking for more than 1 transaction by the same person (EmplID for example) within a 5 minute period. I am not sure if this is possible with SQL. Here are the details:
Table = MEALTRANSLEDGER
Relevant Columns:
"TRANDATE" DATE,
"EMPLID" NUMBER(9,0)
I need to select these columns when a particular EmplID has logged more than 1 transaction in a 5 minute period.
I know I could do this with PL/SQL or Perl by stepping through the rows of the table and calculating date differences, but I would really like to know if SQL could do it.
Thanks for the help.
Version Info:
SQL> select * from v$version where banner like 'Oracle%';
BANNER
Oracle Database 10g Release 10.2.0.4.0 - Production
You can use something along these lines to determine the minutes difference between transactions...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as emplid, to_date('01/01/2010 09:00:00', 'DD/MM/YYYY HH24:MI:SS') as trandate from dual union all
2 select 1, to_date('01/01/2010 09:10:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
3 select 1, to_date('01/01/2010 09:20:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
4 select 1, to_date('01/01/2010 09:45:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
5 select 1, to_date('01/01/2010 09:51:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
6 select 2, to_date('01/01/2010 09:12:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
7 select 2, to_date('01/01/2010 09:18:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
8 select 2, to_date('01/01/2010 09:22:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
9 select 2, to_date('01/01/2010 09:30:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
10 select 3, to_date('01/01/2010 09:05:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
11 select 3, to_date('01/01/2010 10:10:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
12 select 3, to_date('01/01/2010 11:15:00', 'DD/MM/YYYY HH24:MI:SS') from dual
13 )
14 --
15 select emplid, trandate
16 ,(trandate-lag(trandate) over (partition by emplid order by trandate)) * (24*60) as mins_diff
17 from t
18* order by emplid, trandate
SQL> /
EMPLID TRANDATE MINS_DIFF
1 01/01/2010 09:00:00
1 01/01/2010 09:10:00 10
1 01/01/2010 09:20:00 10
1 01/01/2010 09:45:00 25
1 01/01/2010 09:51:00 6
2 01/01/2010 09:12:00
2 01/01/2010 09:18:00 6
2 01/01/2010 09:22:00 4
2 01/01/2010 09:30:00 8
3 01/01/2010 09:05:00
3 01/01/2010 10:10:00 65
3 01/01/2010 11:15:00 65
12 rows selected.And then you can wrap that up to just highlight the problem ones...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as emplid, to_date('01/01/2010 09:00:00', 'DD/MM/YYYY HH24:MI:SS') as trandate from dual union all
2 select 1, to_date('01/01/2010 09:10:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
3 select 1, to_date('01/01/2010 09:20:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
4 select 1, to_date('01/01/2010 09:45:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
5 select 1, to_date('01/01/2010 09:51:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
6 select 2, to_date('01/01/2010 09:12:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
7 select 2, to_date('01/01/2010 09:18:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
8 select 2, to_date('01/01/2010 09:22:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
9 select 2, to_date('01/01/2010 09:30:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
10 select 3, to_date('01/01/2010 09:05:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
11 select 3, to_date('01/01/2010 10:10:00', 'DD/MM/YYYY HH24:MI:SS') from dual union all
12 select 3, to_date('01/01/2010 11:15:00', 'DD/MM/YYYY HH24:MI:SS') from dual
13 )
14 --
15 select emplid, trandate
16 from (
17 select emplid, trandate
18 ,(trandate-lag(trandate) over (partition by emplid order by trandate)) * (24*60) as mins_diff
19 from t
20 )
21 where mins_diff <= 5
22* order by emplid, trandate
SQL> /
EMPLID TRANDATE
2 01/01/2010 09:22:00
SQL>
Similar Messages
-
SQL- Query that return only one record
Hello,
is it possible to execute a pure SQL-Query which returns only one row although multiple rows are found.
It is no problem in PL/SQL, but I have no idea if the same is also possible in SQL.
thanks in advance
MichaelWhy not? There are 4 records in this table, but only selected one.
SQL> with t
2 as
3 (
4 select '#%$@#$@$@##$' Addr from dual
5 union all
6 select '18 Jalan Scott' from dual
7 union all
8 select '18 Lemana St' from dual
9 union all
10 select '32-penstation' from dual
11 union all
12 select '99999999999' from dual
13 )
14 select addr
15 from t
16 where rownum =1
17 /
ADDR
#%$@#$@$@##$
SQL>Cheers
Sarma. -
SQL query which return all the NET SERVICES which are avaiable in tnsname
hi all
how to write a sql query which return all the net services which are avaiable in tnsname.ora
Regards
sAlso, tnsnames.ora is stored on the client, and not necessarily on the server; it's possible (and quite likely) that the name I use for a database in my tnsnames.ora could be different from the name you use for the same database; conversely we might use the same name for two different databases.
Regards Nigel -
Query is returning multiple records for a bank account id and party id
Hi All,
I am not getting why this query is returning multiple records for a particular bank account id and party id:
SELECT instrument_payment_use_id
,instrument_type
,instrument_id
,start_date
,ext_pmt_party_id
FROM iby_pmt_instr_uses_all
WHERE instrument_id =:lv_num_ext_bank_account_id
and exists (select 1 from iby_external_payees_all b where PAYEE_PARTY_ID= :lv_num_party_id and b.ext_payee_id = ext_pmt_party_id)
I want above values to be used in api iby_disbursement_setup_pub.set_payee_instr_assignment in R12.
Please help asap.
ThanksO/P of query run for
SELECT rowid, instrument_payment_use_id
FROM iby_pmt_instr_uses_all
WHERE instrument_id =6642
AND EXISTS (
SELECT 1
FROM iby_external_payees_all b
WHERE payee_party_id= 85470
AND b.ext_payee_id = ext_pmt_party_id);
is below:
Rowid INSTRUMENT_PAYMENT_USE_ID
AABiDXAGIAABhiKAAS 236586
AABiDXAGRAABSjtAAz 148437
The version is R12 -
Human Workflow Task XPath query string returns multiple nodes.
I am looking for trouble shooting help for this error. I am no sure if it is a server or jdev issue.
I am running JDev version 10.1.3.3 and console version 10.1.3.1.0 locally.
General information on the BPEL process:
I have a temporary table in Oracle lite that I created items to be review by the user. I created a synchronous BPEL process. The first step in developing this process, I created the straight forward invoke the table to get the records, transform the records with a change the approve flag = "Y", and invoke the table to update the records. Works like a charm. I followed the online tutorial by dropping a human task after the transform, configured the parameters, setup the assignments, and moved the invoke to update table under the approved condition. If the table has only one record, the process runs great but if there are two records I get the following error message.
<selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"><part name="summary"><summary>XPath query string returns multiple nodes.
According to BPEL4WS spec 1.1 section 14.3, The assign activity part and query /ns3:TempItemCollection/ns3:TempItem/ns3:ItemNbr should not return multipe nodes.
Please check the BPEL source at line number "178" and verify the part and xpath query /ns3:TempItemCollection/ns3:TempItem/ns3:ItemNbr.
</summary>
</part></selectionFailure>
=================
The error occurs in the first assign of the Human task after the assign copies the fields for the title. I underlined line number 178.
<correlationSets>
<correlationSet name="WorkflowTaskIdCor"
properties="taskservice:taskId"/>
</correlationSets>
<sequence>
<assign name="HumanTask1_1_AssignTaskAttributes">
<copy>
<from expression="concat(ora:getProcessURL(), string('/HumanTask1/HumanTask1.task'))"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:taskDefinitionURI"/>
</copy>
<copy>
<from expression="number(3)"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:priority"/>
</copy>
<copy>
<from>
<payload xmlns="http://xmlns.oracle.com/bpel/workflow/task">
<Case xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<CourtDate xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<ErrorMessage xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<ItemName xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<Payment xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<Zip xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<ProcessFlag xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<LastUpdated xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<AddedDate xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<CityAttnyAmount xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<ApprovalFlag xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<ProlawKey xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
<ProcessKey xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
</payload>
</from>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:payload"/>
</copy>
<copy>
<from expression="concat(string('Item Fee Approval '), bpws:getVariableData('Invoke_1_Select_RecordsSelect_OutputVariable','TempItemCollection','/ns3:TempItemCollection/ns3:TempItem/ns3:ItemName'))"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:title"/>
</copy>
<copy>
<from variable="Invoke_1_Select_RecordsSelect_OutputVariable"
part="TempItemCollection"
query="/ns3:TempItemCollection/ns3:TempItem/ns3:ItemNbr"/>
<to variable="initiateTaskInput" part="payload"
query="/taskservice:initiateTask/task:task/task:payload/task:Item"/>
</copy>
<copy>
Thank you for any help you can give me.Here is how I solved this problem: I was told by the metalink folks that I should use the same verion of SOA console as jdev. So I went back to jdev 10.1.3.1. Rather than reading from the Oracle lite table, I dumped the table into a flat file. I read flat file and populated the workflow. Remember to set the 'messages in batch' flag in the file adapter to 1 and the number of records to skip to zero in the format builder for the flat file. The process now reads each record and creates an instance for that each record. In other words, if I have 8 records in my flat file, I will have 8 instances of the process running on the console. Thanks Jeremy for your help figuring this out.
Edited by: user7725126 on Nov 19, 2009 3:56 PM -
Error: XPath query string returns multiple nodes
Hi all,
I am facing issue with the assign activity.
Error message:
com.oracle.bpel.client.BPELFault: faultName: {{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure} parts: {{ summary=<summary>*XPath query string returns multiple nodes. The assign activity part and query are returning multiple nodes. The assign activity part and query named in the error message returned multiple nodes. It should return single node. According to BPEL4WS specification 1.1 section 14.3, the assign activity part and query named in the error message should not return multiple nodes. Verify the part and xpath query named in the error message at line number 2005 in the BPEL source*.
BPEL code:
<copy>
<from variable="Invoice_Tax_loopCounter"/>
<to variable="Var_Invoice_Tax_Contacts" part="payload" query="/ns30:Invoice_Tax_Contacts/ns30:Invoice/ns29:Get_InvoiceOutput[bpws:getVariableData'Invoice_Tax_loopCounter')]/ns29:ADDR_ATTRIBUTE2"/>
</copy>
We are using SOA 11.1.1.3 version.
Any pointers on this?
Thanks in advanceHi-
This is because you are have multiple nodes either in source or target XML.
My guess is some nodes of your XML might be repeating (means a single element/node has multiple values). Can you please check that or please post your XML here.
Edited by: 145678 on Mar 7, 2011 6:28 PM -
How to check the sql:query is return null value
I have use :
<sql:query var="sql1" dataSource="${db}">
select col_name from table_name
where a=<c:out value="${row.test1}"/>
and b='<c:out value="${row.test2}"/>'
</sql:query>
So, how can I check this statement return null value which is no record within this table?The Result should never be null but can be empty. You can check if the Result is empty using an if tag and checking the rowCount property:
<sql:query var="books"
sql="select * from PUBLIC.books where id = ?" >
<sql:param value="${bookId}" />
</sql:query>
<c:if test="${books.rowCount > 0}">
</c:if>http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL7.html#wp84217
Look for query Tag Result Interface -
Updating a table with a query that return multiple values
Hi,
I'm trying to update a table which contain these fields : ItemID, InventoryID, total amounts
with a query that return these values itemId, inventoryid and total amounts for each items
Mind you, not all the rows in the table need to be updated. only a few.
This what i wrote but doesn't work since the query return multiple values so i can't assign it to journalAmounts.
UPDATE [bmssa].[etshortagetemp]
SET JournalAmounts = (SELECT sum(b.BomQty) FROM [bmssa].[Bom] b
JOIN [bmssa].[SalesLine] sl ON sl.ItemBomId = b.BomId
JOIN [bmssa].[SalesTable] st ON st.SalesId = sl.SalesId
WHERE st.SalesType = 0 AND (st.SalesStatus IN (0,1,8,12,13)) AND st.DataAreaId = 'sdi'
GROUP BY b.itemid, b.inventdimid)
Any advise how to do this task?Remember that link to the documentation posted above that explains exactly how to do this. When you read it which part exactly were you having trouble with?
-
Print Child SQL which is returning multiple rows to single colum.
I have a requirement to print both Parent and Child SQLs rows to single row.
For Ex:
Parent row is returning single row
Id, Name, Primary Rate.
101, LName,FName ,30
Child row is returning multiple rows
Id, Name, Secondary Rate
101, LName,FName,15
101, LName,FName,10
The end result should be
101,LName,FName,30,15,10
Any suggestions please?Below is the XML TAG
<LIST_EMPLOYEERATE>
<EMPLOYEERATE>
<EMPNUMBER>112</EMPNUMBER>
<EMPNAME>Aaron</EMPNAME>
<PAYRATE>38.09</PAYRATE>
<JOBNAME>Technician</JOBNAME>
<EMPTYPE>Salary</EMPTYPE>
<LIST_ADDRATE>
<ADDRATE>
<ADDPAYRATE>26</ADDPAYRATE>
</ADDRATE>
<ADDRATE>
<ADDPAYRATE>7.9</ADDPAYRATE>
</ADDRATE>
</LIST_ADDRATE>
</EMPLOYEERATE>
</LIST_EMPLOYEERATE>
The Result should be (assume this is going onto excel spread sheet)
EmpNum EmpName Rate EmpType Rate1 Rate2
112 Aaron 38.09 Salary 26 7.9
Using @inline we are able to get 26 and 7.9 on the same line, but how to push 7.9 to next column?
Thanks! -
Need help with a SQL qurey that returns multiple rows for one record?
I have the following query where I use a CASE WHEN clause to determine the date of a shift that begins with "FRLO" on day1 - day14 of the pay period. It works great if a schedule record contains one day that begins "FRLO", but if more than one day is "FRLO" then it only returns the first day it finds and not the others. Is there some way to get the query to return a ron for every day 1 - 14 that begins "FRLO"? System if Oracle 11G
Order of the results is not important as this is part of a larger query that orders the results.
Thanks in advance for any help,
George
SELECT s.empid,
CASE
WHEN UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO'
THEN
pp.startpp
WHEN UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO'
THEN
pp.startpp + 1
WHEN UPPER (SUBSTR (s.Day3, 0, 4)) = 'FRLO'
THEN
pp.startpp + 2
WHEN UPPER (SUBSTR (s.Day4, 0, 4)) = 'FRLO'
THEN
pp.startpp + 3
WHEN UPPER (SUBSTR (s.Day5, 0, 4)) = 'FRLO'
THEN
pp.startpp + 4
WHEN UPPER (SUBSTR (s.Day6, 0, 4)) = 'FRLO'
THEN
pp.startpp + 5
WHEN UPPER (SUBSTR (s.Day7, 0, 4)) = 'FRLO'
THEN
pp.startpp + 6
WHEN UPPER (SUBSTR (s.Day8, 0, 4)) = 'FRLO'
THEN
pp.startpp + 7
WHEN UPPER (SUBSTR (s.Day9, 0, 4)) = 'FRLO'
THEN
pp.startpp + 8
WHEN UPPER (SUBSTR (s.Day10, 0, 4)) = 'FRLO'
THEN
pp.startpp + 9
WHEN UPPER (SUBSTR (s.Day11, 0, 4)) = 'FRLO'
THEN
pp.startpp + 10
WHEN UPPER (SUBSTR (s.Day12, 0, 4)) = 'FRLO'
THEN
pp.startpp + 11
WHEN UPPER (SUBSTR (s.Day13, 0, 4)) = 'FRLO'
THEN
pp.startpp + 12
WHEN UPPER (SUBSTR (s.Day14, 0, 4)) = 'FRLO'
THEN
pp.startpp + 13
END
startdate,
NULL starttime,
NULL endtime,
8 hours,
0 minutes
FROM schedules s
JOIN
payperiods pp
ON pp.periodid = s.periodid
WHERE UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day3, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day4, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day5, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day6, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day7, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day8, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day9, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day10, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day11, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day12, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day13, 0, 4)) = 'FRLO'
OR UPPER (SUBSTR (s.Day14, 0, 4)) = 'FRLO';
CURRENT OUTPUT
EMPID STARTDATE STARTTIME ENDTIME HOURS MINUTES
753738, 3/25/2013 , , ,8 ,0
753740, 3/25/2013 , , ,8 ,0
753748, 3/25/2013 , , ,8 ,0
DESIRED OUTPUT
EMPID STARTDATE STARTTIME ENDTIME HOURS MINUTES
753738, 3/25/2013 , , ,8 ,0
753740, 3/25/2013 , , ,8 ,0
753748, 3/25/2013 , , ,8 ,0
753738, 3/26/2013 , , ,8 ,0
753740, 3/26/2013 , , ,8 ,0
753740, 3/28/2013 , , ,8 ,0
753748, 1/1/2013 , , ,8 ,0
753738, 4/3/2013 , , ,8 ,0
753748, 4/3/2013 , , ,8 ,0
CREATE TABLE SCHEDULES
SCHEDULEID NUMBER(12) NOT NULL,
EMPID NUMBER(12) NOT NULL,
PERIODID VARCHAR2(6 BYTE) NOT NULL,
AREAID NUMBER(12) NOT NULL,
DAY1 VARCHAR2(50 BYTE),
DAY2 VARCHAR2(50 BYTE),
DAY3 VARCHAR2(50 BYTE),
DAY4 VARCHAR2(50 BYTE),
DAY5 VARCHAR2(50 BYTE),
DAY6 VARCHAR2(50 BYTE),
DAY7 VARCHAR2(50 BYTE),
DAY8 VARCHAR2(50 BYTE),
DAY9 VARCHAR2(50 BYTE),
DAY10 VARCHAR2(50 BYTE),
DAY11 VARCHAR2(50 BYTE),
DAY12 VARCHAR2(50 BYTE),
DAY13 VARCHAR2(50 BYTE),
DAY14 VARCHAR2(50 BYTE),
NOPTIND1 INTEGER DEFAULT 0,
NOPTIND2 INTEGER DEFAULT 0,
NOPTIND3 INTEGER DEFAULT 0,
NOPTIND4 INTEGER DEFAULT 0,
NOPTIND5 INTEGER DEFAULT 0,
NOPTIND6 INTEGER DEFAULT 0,
NOPTIND7 INTEGER DEFAULT 0,
NOPTIND8 INTEGER DEFAULT 0,
NOPTIND9 INTEGER DEFAULT 0,
NOPTIND10 INTEGER DEFAULT 0,
NOPTIND11 INTEGER DEFAULT 0,
NOPTIND12 INTEGER DEFAULT 0,
NOPTIND13 INTEGER DEFAULT 0,
NOPTIND14 INTEGER DEFAULT 0
CREATE TABLE PAYPERIODS
PERIODID VARCHAR2(6 BYTE) NOT NULL,
STARTPP DATE,
ENDPP DATE
Insert into SCHEDULES
(SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
DAY2, DAY3, DAY4, DAY5, DAY6,
DAY7, DAY8, DAY9, DAY10, DAY11,
DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693744, 753738, '082013', 2167, 'X',
'FRLO<1530>', 'FRLO<1530>', '1530', '1530', '1530',
'X', 'X', '1530', '1530', 'FRLO',
'1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0);
Insert into SCHEDULES
(SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
DAY2, DAY3, DAY4, DAY5, DAY6,
DAY7, DAY8, DAY9, DAY10, DAY11,
DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693745, 753740, '082013', 2167, 'X',
'FRLO<1530>', 'FRLO<1530>', '1530', 'FRLO', '1530',
'X', 'X', '1530', '1530', '1530',
'1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0);
Insert into SCHEDULES
(SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
DAY2, DAY3, DAY4, DAY5, DAY6,
DAY7, DAY8, DAY9, DAY10, DAY11,
DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693746, 753748, '082013', 2167, 'X',
'FRLO<1530>', '1530', '1530', '1530', '1530',
'X', 'X', 'FRLO<1530>', '1530', 'FRLO',
'1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0);
COMMIT;
Insert into PAYPERIODS
(PERIODID, STARTPP)
Values
('082013', TO_DATE('03/24/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;Do you have the opportunity to change the data model to have one day per row ? It would make this easier to get this result without the need for a 14-way CASE or UNION.
If not...
The case statement will return as soon as it matches one of the conditions. Since you want a match when any column in the row starts with FRLO you can use a UNION ALL treating each column as a separate result. There may be more efficient ways to do this, but here is one way:
Select S.Empid, Pp.Startpp Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day1, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+1 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day2, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+2 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day3, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+3 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day4, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+4 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day5, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+5 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day6, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+6 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day7, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+7 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day8, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+8 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day9, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+9 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day10, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+10 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day11, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+11 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day12, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+12 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day13, 0, 4)) = 'FRLO'
Union All
Select S.Empid, Pp.Startpp+13 Startdate, Null Starttime, Null Endtime, 8 Hours, 0 Minutes
From Schedules S Join Payperiods Pp On Pp.Periodid = S.Periodid
Where Upper (Substr (S.Day14, 0, 4)) = 'FRLO'
; -
SQL Query to return all the dependent objects
Hi,
I have a question.
Suppose I am creating a table with a join on 10 other tables, views etc..
And there are nested sub-queries in the CREATE statement.
How can I get the list of all the dependent objects for that table without counting them manually.
I know, we can right click the table/view name and check the dependent objects in Toad or SQL Developer.
But, I want to know the SQL query for getting that information.
Thanks
Rajivwell there is no way oracle would know what query was used when the table was created.
But here is one intuitive trick:
Step 1: Create a procedure that will have a cursor declared on the query you want to know what tables/views are used.
Step 2: Check USER_DEPENDENCIES to see what objects this procedure depends on
Let say you want to create TEST_A table using the following statement:
create table test_a
as
select *
from scott.emp,
scott.dept;
1 create or replace procedure test_temp
2 as
3 cursor test_cur is
4 select *
5 from scott.emp,
6 scott.dept;
7 begin
8 null;
9* end;
SQL> /
Procedure created.
SQL> show errors
No errors.
SQL> desc user_dependencies
Name Null? Type
NAME NOT NULL VARCHAR2(30)
TYPE VARCHAR2(17)
REFERENCED_OWNER VARCHAR2(30)
REFERENCED_NAME VARCHAR2(64)
REFERENCED_TYPE VARCHAR2(17)
REFERENCED_LINK_NAME VARCHAR2(128)
SCHEMAID NUMBER
DEPENDENCY_TYPE VARCHAR2(4)
SQL> select referenced_owner, referenced_name, referenced_type
2 from user_dependencies
3 where name='TEST_TEMP' and referenced_owner<>'SYS';
REFERENCED_OWNER
REFERENCED_NAME
REFERENCED_TYPE
SCOTT
DEPT
TABLE
SCOTT
EMP
TABLE
SQL>
SQL> drop procedure test_temp;
Procedure dropped.
SQL>Message was edited by:
tekicora
Message was edited by:
tekicora -
SQL query to assign multiple concurrent programs to concurrent manager.
Hello,
Do you have any script to assign a list of concurrent Program to distinct Concurrent Managers . Actually there are more than 100 programs need to be assigned to manager.ut
We can do it from front end,but it will take quite long time to finish this task.
Could you please help me on this.
Thanks & Regards,
Saroj.What are the details do i need to check before assign them to Custom Managers.
What do you mean by details you need to check?
Kindly provide me a sql query to get all the details before proceeding to assigning managers.
Concurrent programs definitions can be found in the following tables/views:
FND_CONCURRENT_PROGRAMS
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_PROGRAMS&c_owner=APPLSYS&c_type=TABLE
FND_CONCURRENT_PROGRAMS_TL
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_PROGRAMS_TL&c_owner=APPLSYS&c_type=TABLE
FND_CONCURRENT_PROGRAMS_VL
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_PROGRAMS_VL&c_owner=APPS&c_type=VIEW
Thanks,
Hussein -
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. -
Hi all,
I've a requirement where in I've to get multiple rows from a query.
The resultset should be something like this:
SELECT A
FROM dual;
A
1
2
3
4
5
6
7
8
9
10
Thanks in anticipation
RK RajuI'm not completely certain I understand the question. Just in case you're asking for something as simple as this ...
select rownum from all_objects where rownum <= 10;You didn't say what version you were using either (shame on you). You could use a collection or a pipeline depending on your version ...
create or replace type ttab_number is table of number;
create or replace function f_collection
return ttab_number is
tab_number ttab_number := ttab_number();
begin
for i in 1 .. 10 loop
tab_number.extend;
tab_number(tab_number.count) := i;
end loop;
return tab_number;
end f_collection;
select *
from table(f_collection)
create or replace function f_pipeline
return ttab_number
pipelined is
begin
for i in 1 .. 10 loop
pipe row(i);
end loop;
return;
end f_pipeline;
show errors
select *
from table(f_pipeline) -
SQL query to return list of table names.
Hi all,
I'm looking for a query that will return a list of the table names that exist in my Microsoft Access database.
Any ideas?http://forum.java.sun.com/thread.jsp?forum=31&thread=348287
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html
I would suggest you strat to use the search at the upper right.
You can leave it blank and the advanced search will appear.
You can then select the specific areas you want to search.
Maybe you are looking for
-
I have a scenario like File to ABAP Proxy. Input file is huge like 60 MB and it's a XML file. Currently, it's consuming large resources in both XI & R/3 system. I would like to use the option of Recordsets per Message using the File Content Conversio
-
Case for macbook unibody??
I have the Macbook unibody (aluminum with black keys) that ISN'T the pro and I've been looking everywhere trying to find a hard case for it. The only place I've found so far is www.mymacbookcase.com but the cases they have are plastic and I want to f
-
Webcam video plays back super fast speed
hi, does anyone know about this: when i record video from my creative Live! Cam Video IM Pro, the play back is like twice the speed of real life. like a video speeded up. it was working fine on my previous computer, which was windos xp, and i upgrade
-
How do I delete videos before they are downloaded?
I purchased a season of a tv show and it came with a behind the scenes with each episode but it takes up too much data and memory so I don't want to download them. The problem is I can't seem to be able to delete them from "downloads" section of my i
-
Automatically set the Black and the White points in Aperture?
Jasoninajeep, in this thread, refers to this Aperture Export article, which includes the helpful hint that holding "{Option}" while clicking the auto-luminance button in the Curves brick will cause Aperture to set the Black and the White points witho