Using multiple 'for' statements in an 11g pivot query
oracle: 11.2.0.3
Basically I need to pivot around 2 different columns (I think I need to 'for' clauses').
See below.
Below is pseudo code from non-11g pivot statement.
I am trying to figure out how to do with pivot.
-- note field names are pseudo code and not real values
-- note that the field after 'then' in the case statement is different for the 2 pivots
select my_id,
max( (case when myfield = 'MYVALUE1' then mydate_date else null end)) as MYVALUE1,
to_number(max( (case when myfield = 'MYVALUE' then myfieldvalue else null end))) as MYVALUE2,
min (insert_date ) insert_date
from mytable
group by myidso if I'm doing this in 11g pivot syntax I am stuck at:
-- if I add max(fieldvalue), I think I will pivot too many times. I just want 2 extra columns. Can I add a second 'for' statement?
select *
from mytable
pivot (
max(mydate)
for myfield in ('MYVALUE1' as MYVALUE1)
)
My concern about trying that is that SQL will do extra pivots that I won't use. Which means more work. I saw a blog entry by someone in the oak table (I can't remember who or the link) that showed an example that the pivot clause has about the same logical IOs as using the old max(case statement) but the response time was much better. This was a very rare case where performance is significantly improved without affecting LIOs. So there isn't a good measure. I wish I had the link and generally people in the oak table are very good. So I trust posts by them.
so basically I am not sure how to measure whether doing the extra pivots are using extra resources. This is going to be a fairly performance intensive query due to the volume of data it has to feed through.
I'll give it a try, but my inability to measure it is a bit concerning.
Similar Messages
-
Problem Using Multiple With Statements
I'm having a problem using multiple WITH statements. Oracle seems to be expecting a SELECT statement after the first one. I need two in order to reference stuff from the second one in another query.
Here's my code:
<code>
WITH calculate_terms AS (SELECT robinst_current_term_code,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
END first_term,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
END second_term
FROM robinst
WHERE robinst_aidy_code = :aidy)
/*Use terms from calculate_terms to generate attendance periods*/
WITH gen_attn_terms AS
SELECT
CASE
WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
END first_attn_period,
CASE
WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
END second_attn_period
FROM calculate_terms
SELECT *
FROM gen_attn_terms
<code>
I get ORA-00928: missing SELECT keyword error. What could be the problem?You can just separate them with a comma:
WITH calculate_terms AS (SELECT robinst_current_term_code,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
END first_term,
CASE
WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
END second_term
FROM robinst
WHERE robinst_aidy_code = :aidy),
/*Use terms from calculate_terms to generate attendance periods*/
gen_attn_terms AS
SELECT
CASE
WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
END first_attn_period,
CASE
WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
END second_attn_period
FROM calculate_terms
)Not tested because there are no scripts. -
11G Pivot Query with Oracle EBS
Hello all,
We are trying to use the 11G pivot query function with data from Oracle E-Business Suite. We have an 11G database installed with our Oracle APEX. We cannot seem to get the pivot function to work. At a glance, would anyone be able to see any glaring errors in our syntax. I am not certain it is possible to provide test data so...
We are trying to have column headings with the Period Names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as the dataset.
When we run the sql we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or insight would be greatly appreciated.
select * from (
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751')
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
group by segment2, period_namelilhelp wrote:
Hello all,
We are trying to use the 11G pivot query function with data from Oracle E-Business Suite. We have an 11G database installed with our Oracle APEX. We cannot seem to get the pivot function to work. At a glance, would anyone be able to see any glaring errors in our syntax. I am not certain it is possible to provide test data Why not?
>
We are trying to have column headings with the Period Names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as the dataset.
When we run the sql we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or insight would be greatly appreciated.
select * from (
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751')
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
group by segment2, period_nameDon't use GROUP BY. When you use PIVOT, the grouping is implied by what is in the PIVOT clause and what is not.
Try this:
select *
from (
select segment2
, accounted_dr
, period_name
from gl_je_lines a
, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751'
pivot (
sum (accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
;which is just your posted query without the GROUP BY clause. -
11G Pivot Query with parameters
Hello all,
I would like to find some way, any way to pass parameters to a pivot query. The following pivot query works, but I would like segment2 to be a variable as well as the period names so....
select * from
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 >='007611' and segment2 <='007751' AND period_name in ('SEP-08','OCT-08','NOV-08'))
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08') )
....would be something like....
select * from
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 >= :P4_OBJECT_FROM AND and segment2 <=:P4_OBJECT_TO AND period_name in &P4_EPSB_PERIOD_HOLD.)
pivot
sum(accounted_dr)
for period_name in (&P4_EPSB_PERIOD_HOLD.) )
It is our understanding that we have to hardcode period names and objects, but we would like to get around that. Does anyone have any ideas or tricks?
Thankslilhelp wrote:
Hello all,
We are trying to use the 11G pivot query function with data from Oracle E-Business Suite. We have an 11G database installed with our Oracle APEX. We cannot seem to get the pivot function to work. At a glance, would anyone be able to see any glaring errors in our syntax. I am not certain it is possible to provide test data Why not?
>
We are trying to have column headings with the Period Names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as the dataset.
When we run the sql we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or insight would be greatly appreciated.
select * from (
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751')
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
group by segment2, period_nameDon't use GROUP BY. When you use PIVOT, the grouping is implied by what is in the PIVOT clause and what is not.
Try this:
select *
from (
select segment2
, accounted_dr
, period_name
from gl_je_lines a
, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751'
pivot (
sum (accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
;which is just your posted query without the GROUP BY clause. -
I have an advanced function I have been working on that looks something like this:
Function Do-Something
[cmdletbinding()]
Param
[Parameter(Mandatory=$true,
[ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)]
[string[]]$Param1,
[Parameter(Mandatory=$true,
[ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)]
[string[]]$Param2,
[Parameter(Mandatory=$true,
[ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)]
[string[]]$Param3
Begin {}
Process
My question is, how do I get the values such as "Yes", "Y", "No", and "N" that's located in the [ValidateSet()] validation attribute processed correctly without having to use multiple "If" and "ElseIf"
statements.
For instance, I want to avoid the following, because I know there is a faster and more efficient way (less typing) to do it:
If ($param1 -match "Yes" -or "Y" -and $param2 -match "Yes" -or "Y" -and $param3 -match "Yes" -or "Y")
#Do something here
ElseIf ($param1 -match "No" -or "N" -and $param2 -match "Yes" -or "Y" -and $param3 -match "Yes" -or "Y")
#Do something
I was reading that splatting may help me here, but I am new to the splatting technique and need some help with this one.
I appreciate any help that anyone can offer.
ThanksIs this what you are trying to ask how to do? Your posted script is written incorrectly and will not work at all.
Function Do-Something{
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)]
[ValidateSet('Yes','No','Y','N')]
[string]$p1,
[Parameter(Mandatory=$true)]
[ValidateSet('Yes','No','Y','N')]
[string]$p2
Begin{
Process{
# parse the strings to booleans
$p1a=if($p1 -match 'Yes|Y'){$true}else{$false}
$p2a=if($p2 -match 'Yes|Y'){$true}else{$false}
if($p1a){Write-Host 'P1 is good' -ForegroundColor green}
if($p2a){Write-Host 'P2 is good' -ForegroundColor green}
if($p1a -and $p2a){
Write-Host 'All conditions met' -ForegroundColor green
}else{
Write-Host 'Conditions not met' -ForegroundColor red
PS C:\scripts> Do-Something Y n
P1 is good
Conditions not met
PS C:\scripts> Do-Something n n
Conditions not met
PS C:\scripts> Do-Something y y
P1 is good
P2 is good
All conditions met
This handles case and creates a tracking Boolean fo reach parameter so you can just build simple logic.
¯\_(ツ)_/¯ -
Use Multiple Insert Statements in Prepared Statements
Hi Friends
i am stuck in a problem for which i need your help.i will brief you about the issue below.
I am having Multiple Insert Statements which i need to execute to put the data in the database.i have a doubt about the use of the executeUpdate() function in the statement interface. sample code is as below.
stmt = conn.prepareStatement("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, ) VALUES(PID, 2, '123123123', '123', '66', 1, 1 );");
int n =stmt.executeUpdate();
Now the problem is how do i insert multiple Insert statements using the conn.prepareStatement().should i do like
stmt = conn.prepareStatement("")
int n =stmt.executeUpdate();
stmt = conn.prepareStatement("")
int n =stmt.executeUpdate();
stmt = conn.prepareStatement("")
int n =stmt.executeUpdate(); ..................................
should i use the same steps to execute each individual query and then use executeUpdate().
Please let me know the correct procedure to be followed to execute these tasks.waiting for a positive reply from your side.
Thanks & Regards
Vikram KHi
Thanks a lot once agin for the reply.
I think i have figured out the solution. I am using SQL statements in the Prepared statements(""). But now i have dropped the idea of using the prepared statement and decided to use the simple Statement instead.
what i have done is as below.
conn = ConnectionFactory.getInstance().getConnection();
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, heightMeasurementType, weightMeasurementType ) VALUES(PID, '1', '1', '0', '1', 'Mr', CONCAT('Jason ', PID), 'R', 'Mawdsley', '123', '66', 1, 1 );");
stmt.executeUpdate("INSERT into Cp () Values ()");
stmt.executeUpdate("INSERT into gp () Values ()");
stmt.executeUpdate("INSERT into jk () Values ()");
I think this makes sense to use the Statement and execute all the queries in one shot rather than using PS.
thanks a lot for your help.
Regards
Vikram K -
Trying to use multiple if statements to set a variable in my script
I am importing a csv file to create user accounts.. i have it working.. but now i want to have the script look at a variable, and based on that variable set other variables, like the ou or home directory path etc..
here's what i have so far.. it seems to select the 2nd option ASH unless i # it out then it selects the first option..i am clearly missing something simple here.... i can't just use an else statement as i will need many lines of logic to support the many
different ou's, home dir shares etc.. globally...
import-csv $csv | foreach-object {
$site=$_.site
$HomeDArl= "\\teleflex\global\home\medical\na\arl"
$HomeDASH= "\\ashfs01.arrowintl.com\user"
if ($site='ARL'){
$homed = $HomeDArl
if ($site='ASH'){
$homed =$HomeDASHThanks for the push in the right direction..
Import-CSV $filepath | ForEach-Object {
$site=$_.site
switch ($site) {
Arl {$homed = "\\teleflex\global\home\medical\na\arl"}
Ash {$homed ="\\ashfs01.arrowintl.com\user"} -
ORA-00911: invalid character using multiple select statements
I am getting an ORA-00911: invalid character error when trying to execute 2 select statements using ODP.NET.
cmd.CommandText = "select sysdate from dual;select sysdate from dual;";
cmd.Connection = conn;
cmd.CommandType = System.Data.CommandType.Text;
conn.Open();
OracleDataReader dr = cmd.ExecuteReader();
This works in SQL server but for some reason it appears this does not work in Oracle?
If this is the case what is a vaiable workaround? Wrapping the 2 statements in a transaction?
Seems strange that you can't return multiple result sets using in-line sql statements.Oracle doesn't support passing multiple statements like that, and this is unrelated to ODP.NET.
SQL> select * from emp;select * from dept;
select * from emp;select * from dept
ERROR at line 1:
ORA-00911: invalid character
You could do it via an anonymous block and ref cursors though if you dont want to do it via a stored procedure..
using System;
using System.Data;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
public class test
public static void Main()
using (OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger;"))
con.Open();
string strSql = "begin open :refcur1 for select * from emp;" +
"open :refcur2 for select * from dept;" +
"open :refcur3 for select * from salgrade;end;";
using (OracleCommand cmd = new OracleCommand(strSql, con))
cmd.Parameters.Add("refcur1", OracleDbType.RefCursor, ParameterDirection.Output);
cmd.Parameters.Add("refcur2", OracleDbType.RefCursor, ParameterDirection.Output);
cmd.Parameters.Add("refcur3", OracleDbType.RefCursor, ParameterDirection.Output);
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
cmd.Parameters["refcur1"].Dispose();
cmd.Parameters["refcur2"].Dispose();
cmd.Parameters["refcur3"].Dispose();
foreach (DataTable dt in ds.Tables)
Console.WriteLine("\nProcessing {0} resultset...", dt.ToString());
foreach (DataRow row in dt.Rows)
Console.WriteLine("column 1: {0}", row[0]);
}Hope it helps,
Greg -
Calculation using multiple select statements - APEX 4.0
Hello,
I am new to APEX, PL/SQL and have some SQL knowledge, but I pick up things quickly. I want to make a page item equal to the value of a Select statement minus another Select statement. The statements pull from the same tables and only differ slightly in the where clause. I do not know the best way to create this calculation. Can someone please assist.
Select Statement #1
select sum(JE_TRANSACTIONS.DEBIT_AMOUNT) as "Release"
from "REVREC_FORMS" "REVREC_FORMS",
"JOURNAL_ENTRIES" "JOURNAL_ENTRIES",
"JE_TRANSACTIONS" "JE_TRANSACTIONS"
where "JOURNAL_ENTRIES"."RELATED_REVREC"="REVREC_FORMS"."REVREC_ID"
and "JOURNAL_ENTRIES"."RECORD_ID_"="JE_TRANSACTIONS"."RELATED_JOURNAL_ENTRY"
and "JOURNAL_ENTRIES"."RELEASE_TYPE" ='Release'
and "JOURNAL_ENTRIES"."REVENUE_TYPE" ='Software'
and "REVREC_FORMS"."REVREC_ID" =:P12_REVREC_ID
Select Statement #2
select sum(JE_TRANSACTIONS.DEBIT_AMOUNT) as "Deferral"
from "REVREC_FORMS" "REVREC_FORMS",
"JOURNAL_ENTRIES" "JOURNAL_ENTRIES",
"JE_TRANSACTIONS" "JE_TRANSACTIONS"
where "JOURNAL_ENTRIES"."RELATED_REVREC"="REVREC_FORMS"."REVREC_ID"
and "JOURNAL_ENTRIES"."RECORD_ID_"="JE_TRANSACTIONS"."RELATED_JOURNAL_ENTRY"
and "JOURNAL_ENTRIES"."RELEASE_TYPE" ='Deferral'
and "JOURNAL_ENTRIES"."REVENUE_TYPE" ='Software'
and "REVREC_FORMS"."REVREC_ID" =:P12_REVREC_IDHow about
select sum(decode(release_type,'Deferral',je_transactions.debit_amount)) - sum(decode(release_type,'Release',je_transactions.debit_amount)) as result
from "REVREC_FORMS" "REVREC_FORMS",
"JOURNAL_ENTRIES" "JOURNAL_ENTRIES",
"JE_TRANSACTIONS" "JE_TRANSACTIONS"
where "JOURNAL_ENTRIES"."RELATED_REVREC"="REVREC_FORMS"."REVREC_ID"
and "JOURNAL_ENTRIES"."RECORD_ID_"="JE_TRANSACTIONS"."RELATED_JOURNAL_ENTRY"
and "JOURNAL_ENTRIES"."REVENUE_TYPE" ='Software'
and "REVREC_FORMS"."REVREC_ID" =:P12_REVREC_IDScott -
11g pivot query syntax question
I searched the forums and I have seen questions similiar to the one I am asking, but its not the exact same issue.
I need 3 fields in my 'for' clause. I get 'column ambiguously defined. I think I get this error for a different reason that other people asking the question.
The others seem to be doing more than 1 function in the pivot clause and those need an alias. I give an alias with my 1 function and still get an error.
ORA-00918: column ambiguously defined
I used aliases like the recommendation in other posts and I still get the same error. I think I need 3 columns in the for clause.
--note that this is just a test table. These are not real names going into production
create table pivot_tab (
pk1 number,
pk2 number,
myElement varchar2(30),
myElementDate date);
pk1,pk2 are the unique key.
I need this to return as: the vlaues after pk2, can be any alias. This is just an example.
pk1 pk2 MY1_DATE, MY2_DATE, MY3_DATE
select *
from pivot_tab
PIVOT ( max(myElementDate) for myElement
in (''MY1','MY2','MY3'))
I saw a couple of references to this syntax, but I get syntax errors.
ora--00906: missing parentheses. So I dont think this syntax works.
select *
from pivot_tab
PIVOT ( max(myElementDate) for (pk1,pk2,myElement)
in (''MY1','MY2','MY3'))Edited by: Guess2 on May 6, 2013 6:50 AMdon't have any sample data or expected results to test this with maybe
SELECT *
FROM (SELECT pk1,
pk2,
myelement,
myelementdate
FROM pivot_tab) PIVOT (MAX (myElementDate)
FOR myElement
IN ('MY1' AS MY1, 'MY2' AS MY2, 'MY3' AS MY3));or maybe you are trying to pivot by the first part of the pk?
with pivot_tab as (select 1 pk1, 2 pk2, 'MY1' myelement, sysdate myelementdate from dual union all
select 1 pk1, 3 pk2, 'MY2' myelement, add_months(sysdate,2) myelementdate from dual union all
select 1 pk1, 4 pk2, 'MY3' myelement, add_months(sysdate,3) myelementdate from dual union all
select 2 pk1, 5 pk2, 'MY1' myelement, sysdate myelementdate from dual union all
select 2 pk1, 6 pk2, 'MY2' myelement, add_months(sysdate,6) myelementdate from dual union all
select 2 pk1, 7 pk2, 'MY3' myelement, add_months(sysdate,7) myelementdate from dual )
SELECT *
FROM (SELECT pk1,
myelement,
myelementdate
FROM pivot_tab) PIVOT (MAX (myElementDate)
FOR myElement
IN ('MY1' AS MY1, 'MY2' AS MY2, 'MY3' AS MY3));
PK1 MY1 MY2 MY3
1 5/6/2013 10:07:40 AM 7/6/2013 10:07:40 AM 8/6/2013 10:07:40 AM
2 5/6/2013 10:07:40 AM 11/6/2013 10:07:40 AM 12/6/2013 10:07:40 AMEdited by: pollywog on May 6, 2013 10:08 AM -
How to use OFFSET for CHAR type value in Bex query
infoobject A value = 1102007
Type = CHAR
I want to have an offset for this infoobject created in query say 1 to 12 months
in month of 10/2007 value = 1102007
remember above 1 is always CONSTANT
then
in month of 11/2007 value = 1112007
in month of 12/2007 value = 1122007
how to do this since the infoobject is of TYPE- CHAR ,its gives we cannot do the OFFFSET in the query ,for doing OFFSET the infoobject must be of type numeric or NUMC.
is it possible achieve this in to update rules?? since i cannot change the type of this infoobject now in the middle of production support
please help
thanksHi,
You will have to add a characteristic to your cube.
The format should be NUMC
In the update-routine you will have to convert the char value to numc
Success
udo -
Hello again,
I am just learning how to use the for statements and the while statements and am having some problems.
I need to display the squares of numbers from 1-10. Here is what I have and am getting an error for an illegal expression. My question is, How do I set up the code to recognize the squaring?
public class squareFor
public static void main(String[] args)
int total = 0;
for(int number = 1; number *=1)
total *= number;
System.out.printf("Sum is %d\n", total);
}Well I tried a little bit more and this is what I got. Why am I not able to get them to square?
public class squareFor
public static void main(String[] args)
int total = 0;
for(int number = 1;number <= 10; number ++)
int x= 1*1;
int w= 2*2;
int y= 3*3;
int z= 4*4;
int a= 5*5;
int b= 6*6;
int c= 7*7;
int d= 8*8;
int e= 9*9;
int f= 10*10;
total *= number;
System.out.printf("Sum is %d\n", total);
} -
Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT
Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT. Below SQL is an example of what I am trying to do - In this case instead of using JOIN, can I have three pivot_for_clauses in the same sql?
SQL:
MERGE INTO Test_1 dest
USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
FROM (SELECT company_id,action_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id) IN ((1) as num_logins,(2) as num_logouts,(61) as
num_logins_from_mobile_device,(16) as num_pref_changed,....)) P1
JOIN
(SELECT company_id,action_type_id,tx_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice, (4,4) AS
edit_invoice,(3,3) as num_checks,(3,47) as num_paychecks,(3,7) as num_recvd_payments,(3,9) as num_bills,
(3,35) as num_estimates,(3,46) as num_purchase_orders)) P2
on P1.company_id=P2.company_id
JOIN
(SELECT company_id,action_type_id,list_type_id
FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
PIVOT (count(action_type_id) FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,(3,1) as
num_accounts,(3,4) as num_employees,(3,6) as num_customers,(3,14) as num_memorized_reports)) P3
on P2.company_id=P3.company_id
left outer JOIN
(SELECT company_id,create_date,count(*) as num_logos
FROM qbo.companylogos_1 group by company_id,create_date having trunc(create_date)=trunc(sysdate)-1) P4
on P3.company_id=P4.company_id
ORDER BY P1.company_id) source
ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))WHEN MATCHED THEN
UPDATE SET dest.num_items = source.num_items where 1=2
WHEN NOT MATCHED THEN
INSERT (dest.company_id,.....) values (source.company_id,.....);Maybe
MERGE INTO Test_1 dest
USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
FROM (select *
from (SELECT company_id,action_type_id
FROM Testauditinfo_1
where trunc(audit_date_time) = trunc(sysdate)-1
) a
PIVOT (count(action_type_id)
FOR (action_type_id) IN ((1) as num_logins,
(2) as num_logouts,(61) as num_logins_from_mobile_device,
(16) as num_pref_changed,....
) P1
JOIN
(select *
from (SELECT company_id,action_type_id,tx_type_id
FROM Testauditinfo_1
where trunc(audit_date_time) = trunc(sysdate)-1
) a
PIVOT (count(action_type_id)
FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice,
(4,4) AS edit_invoice,
(3,3) as num_checks,
(3,47) as num_paychecks,
(3,7) as num_recvd_payments,
(3,9) as num_bills,
(3,35) as num_estimates,(3,46) as num_purchase_orders
) P2
on P1.company_id = P2.company_id
JOIN
(select *
from (SELECT company_id,action_type_id,list_type_id
FROM Testauditinfo_1
where trunc(audit_date_time) = trunc(sysdate)-1
) a
PIVOT (count(action_type_id)
FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,
(3,1) as num_accounts,
(3,4) as num_employees,
(3,6) as num_customers,
(3,14) as num_memorized_reports
) P3
on P2.company_id = P3.company_id
left outer JOIN
(SELECT company_id,create_date,count(*) as num_logos
FROM qbo.companylogos_1
group by company_id,create_date
having trunc(create_date) = trunc(sysdate)-1
) P4
on P3.company_id = P4.company_id
ORDER BY P1.company_id
) source
ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))
WHEN MATCHED
THEN UPDATE SET dest.num_items = source.num_items where 1 = 2
WHEN NOT MATCHED
THEN INSERT (dest.company_id,.....)
values (source.company_id,.....)Did you try it ?
Regards
Etbin -
Using multiple variable names in a for statement?
I have searched, and I just can't seem to find how to do something, I do not have the code atm, but easy enough to explain...
I have a GUI that has 3 rows of 3 fields...
emp1Name, emp1Phone, emp1Fax
emp2Name, emp2Phone, emp2Fax
emp3Name, emp3Phone, emp3Fax
I also have a tabbed file that has the input for each of these fields, it looks something like...
Mike 602-111-1111 602-111-1112
Dave 602-222-2222 602-222-2223
Bethany 602-333-3333 602-333-3334
Here is my method...
private void getFile() {
myFile = new File("C:/javainput.txt");
msgField.setText("Welcome!");
try {
BufferedReader br = new BufferedReader(new FileReader(myFile));
String s;
while ((s=br.readLine())!=null){
String f[] = s.split("\t");
emp1Name.setText(f[0]);
emp1Phone.setText(f[1]);
emp1Fax.setText(f[2]);
br.close();
} catch (IOException e) {
msgField.setText("INPUT FILE NOT FOUND!");
}My question is, how do I cycle through emp1, emp2 and emp3 in a for statement. I tried empName, but that obviously isn't correct.
Help, or point me to where I can read on this?
Thank you!
Edited by: 805764 on Oct 27, 2010 12:10 PMDo one thing at a time. First, define your Employee class. Compile it, debug it. Test it. Make sure that you can create Employees, set their names, phone numbers, etc., and get them back.
Once that works, familiarize yourself with arrays, if necessary, completely separately from your Employee class.
Once you're comfortable with arrays and with defining a new class (i.e., Employee), write a tiny test program that just, say, creates an array of a certain size and populates it with Employees, and then iterates over it printing out each Employee's information to the console.
Once that works, set it aside. Now work on a GUI. Start by just displaying one or two hardcoded names and phone numbers. Once that works, add a bit more to it--say by getting that hardcoded information from inside Employee objects.
And so on.
Right now you're biting off too much at once. Keep working on one very small new step at a time, only move on to the next step once the previous one is solid, and do the steps independently of each other first, and then combine their respective results. It may sound like a lot of work, but I promise you, in the end, it's faster, easier, and far less frustrating to do it this way.
At any given step, if you get stuck, post a question here, providing an [url http://sscce.org]SSCCE that shows what you're trying to do, and clearly explain exactly what problems you're having. -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M
Maybe you are looking for
-
Hello All, I am working on a SOAP to SOAP (Backend as ECC where I am exposing an RFC as Web Service). Once the Web service is generated for RFC and the WSDL is imported in PI, I can see that all the fields in different nodes become mandatory. Is it h
-
Trying to locate an Application File for InDesign
Im trying to download the blurb plug in and at the set up stage it asks me to locate the Application File for my Adobe InDesign CS5 in my files but i cant locate it any ideas how i can locate it?
-
Servlet 2.3 error handling
Hi, Once again, I have problems with the additions in Servlet 2.3's error handling. I'm looking at SRV 9.9.2. To be concrete, I need to catch every RuntimeException with an error-page which shows the
-
How can I test if the battery is finished? How long does a battery last? Is there a guarantee on the battery? if it is the battery....where do I get another? I am in Pretoria South Africa.
-
Ensure that all database components/objects provided by Oracle are VALID
Hi Guys need some clarification concern the below point from -> 1503653.1 Ensure that all database components/objects provided by Oracle are VALID in the source database prior to starting the upgrade. Ensure that you do not have duplicate objects in