Adding hard coded column values to a result set.
DB version:10gR2
Example from sample schema SCOTT
select e.ename, e.empno, d.loc
from
emp e inner join dept d on (e.deptno=d.deptno)
and e.ename like 'M%';
ENAME EMPNO LOC
MARTIN 7654 CHICAGO
MILLER 7934 DALLAS
For every ename like 'MARTIN' the following two rows (hardcoded column values 001-985 and 003-745 ) should get created.
PAY_TYPES PAY_CODES
001 985
003 745
Everything else must remain same.
The result set should look like the following. Here two rows got created for MARTIN and MILLER.Everything else remains the same
ENAME EMPNO PAY_TYPES PAY_CODES LOC
MARTIN 7654 001 985 CHICAGO
MARTIN 7654 003 745 CHICAGO
MILLER 7934 001 985 DALLAS
MILLER 7934 003 745 DALLAS
How is this possible?
Hello Scott,
Try this,
SELECT ENAME, EMPNO, PAY_TYPES, PAY_CODES, LOC
FROM (SELECT K.*, ROW_NUMBER() OVER(PARTITION BY ENAME ORDER BY ENAME) ID
FROM (SELECT *
FROM (SELECT ENAME, EMPNO, LOC
FROM EMP E, DEPT D
WHERE E.DEPTNO = D.DEPTNO
AND ENAME LIKE 'M%')
WHERE CONNECT_BY_ISLEAF = 1
CONNECT BY LEVEL <= 2) K)
MODEL
DIMENSION BY (ENAME, ID)
MEASURES ( EMPNO, LOC, '000' AS PAY_TYPES, '000' AS PAY_CODES )
RULES ( PAY_TYPES[FOR (ENAME) IN (SELECT ENAME FROM EMP WHERE ENAME LIKE 'M%' ),1] = '001' ,
PAY_CODES[FOR (ENAME) IN (SELECT ENAME FROM EMP WHERE ENAME LIKE 'M%' ),1] = '985' ,
PAY_TYPES[FOR (ENAME) IN (SELECT ENAME FROM EMP WHERE ENAME LIKE 'M%' ),2] = '003' ,
PAY_CODES[FOR (ENAME) IN (SELECT ENAME FROM EMP WHERE ENAME LIKE 'M%' ),2] = '745' ) Regards,
Christian Balz
Similar Messages
-
How to use model clause without hard coding the values in it?
Query
select acct_no,
gl_code,
CASE
WHEN entry_type_label IN ('Earned Revenue') THEN
'Earned Revenue'
ELSE
'Deferred Revenue Credit'
END AS entry_type_label,
CASE
WHEN entry_type_label IN ('Opening Balance') THEN
'Opening Balance'
WHEN entry_type_label IN ('Deferred Revenue Credit') THEN
'Invoice Amount'
WHEN entry_type_label IN ('Earned Revenue') THEN
'Earned Revenue'
WHEN entry_type_label IN ('Closing Balance') THEN
'Closing Balance'
ELSE
'Deferred Revenue Credit'
END AS label,
entry_type_no,
orig_chg_start_date,
period_no,
-amt as amt
from revrec_test
WHERE acct_no = 1788562
AND entry_type_no IN (2, 4) model dimension by(acct_no,
gl_code,
entry_type_label,
entry_type_no,
orig_chg_start_date,
period_no) measures(amt) rules upsert
all(amt 1788562,
'UNEARNED-10011561',
'Opening Balance',
2,
'02-OCT-17 08.30.00 AM',
190 = 0,
amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
190 = amt 1788562,
'UNEARNED-10011561',
'Deferred Revenue Credit',
2,
'02-OCT-17 08.30.00 AM',
190 - amt 1788562,
'EARNED-10011561',
'Earned Revenue',
4,
'02-OCT-17 08.30.00 AM',
190,
amt 1788562,
'UNEARNED-10011561',
'Opening Balance',
2,
'02-OCT-17 08.30.00 AM',
191 = amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
190,
amt 1788562,
'UNEARNED-10011561',
'Deferred Revenue Credit',
2,
'02-OCT-17 08.30.00 AM',
191 = 0,
amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
191 =
(amt 1788562, 'UNEARNED-10011561', 'Opening Balance', 2,
'02-OCT-17 08.30.00 AM', 191 + amt 1788562, 'UNEARNED-10011561',
'Deferred Revenue Credit', 2, '02-OCT-17 08.30.00 AM', 191) - amt
1788562,
'EARNED-10011561',
'Earned Revenue',
4,
'02-OCT-17 08.30.00 AM',
191,
amt 1788562,
'UNEARNED-10011561',
'Opening Balance',
2,
'02-OCT-17 08.30.00 AM',
192 = amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
191,
amt 1788562,
'UNEARNED-10011561',
'Deferred Revenue Credit',
2,
'02-OCT-17 08.30.00 AM',
192 = 0,
amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
192 =
(amt 1788562, 'UNEARNED-10011561', 'Opening Balance', 2,
'02-OCT-17 08.30.00 AM', 192 + amt 1788562, 'UNEARNED-10011561',
'Deferred Revenue Credit', 2, '02-OCT-17 08.30.00 AM', 192) - amt
1788562,
'EARNED-10011561',
'Earned Revenue',
4,
'02-OCT-17 08.30.00 AM',
192,
amt 1788562,
'UNEARNED-10011561',
'Opening Balance',
2,
'02-OCT-17 08.30.00 AM',
193 = amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
192,
amt 1788562,
'UNEARNED-10011561',
'Deferred Revenue Credit',
2,
'02-OCT-17 08.30.00 AM',
193 = 0,
amt 1788562,
'UNEARNED-10011561',
'Closing Balance',
2,
'02-OCT-17 08.30.00 AM',
193 =
(amt 1788562, 'UNEARNED-10011561', 'Opening Balance', 2,
'02-OCT-17 08.30.00 AM', 193 + amt 1788562, 'UNEARNED-10011561',
'Deferred Revenue Credit', 2, '02-OCT-17 08.30.00 AM', 193) - amt
1788562,
'EARNED-10011561',
'Earned Revenue',
4,
'02-OCT-17 08.30.00 AM',
193)
ORDER BY period_no, entry_type_no;
The above query works fine. But i have hard coded the values. I want to do the same operation for different account number which is going to have different periodic no. How can I achieve it?
Thanks in advance.Create Statement
CREATE TABLE table_one(
ACCT_NO NUMBER(38),
GL_CODE VARCHAR2(300),
ENTRY_TYPE_LABEL CHAR(50),
ENTRY_TYPE_NO NUMBER,
ORIG_CHG_START_DATE TIMESTAMP(0) WITH LOCAL TIME ZONE,
ORIG_CHG_END_DATE TIMESTAMP(0) WITH LOCAL TIME ZONE,
PERIOD_NO NUMBER(38),
AMT NUMBER(38,10)
Insert Statement
INSERT ALL
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'U-11561','Deferred Revenue Debit',3,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',100,13.87)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'E-11561','Earned Revenue',4,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',102,-14.83)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'E-11561','Earned Revenue',4,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',101,-14.35)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'E-11561','Earned Revenue',4,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',100,-13.87)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'U-11561','Deferred Revenue Debit',3,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',103,0.95)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'U-11561','Deferred Revenue Debit',3,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',102,14.83)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'U-11561','Deferred Revenue Debit',3,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',101,14.35)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'E-11561','Earned Revenue',4,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',103,-0.95)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1001,'U-11561','Deferred Revenue Credit',2,'02-OCT-17 08.30.00 AM','01-JAN-18 01.30.00 PM',100,-44)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',106,44.91)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Accounts Receivable',1,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',104,60)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,3.93)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',106,11.75)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',107,6.86)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,-7.82)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',106,-23.47)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',107,-13.69)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',107,-6.86)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,7.82)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',106,23.47)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',107,13.69)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',104,-9.13)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,-44.91)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',106,-44.91)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',107,-35.91)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,-3.93)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,44.91)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',104,9.13)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Earned Revenue',4,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',106,-11.75)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Credit',2,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,38.48)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Credit',2,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,-19.24)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Credit',2,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',104,-60)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Accounts Receivable',1,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,38.48)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Accounts Receivable',1,'20-DEC-13 09.30.00 AM','16-FEB-14 09.30.00 AM',105,19.24)
INTO table_one(acct_no, gl_code, entry_type_label, entry_type_no, orig_chg_start_date, orig_chg_end_date, period_no, amt) VALUES(1002,'Recurring Flat Fees COA Code','Deferred Revenue Debit',3,'17-NOV-13 09.30.00 AM','16-FEB-14 09.30.00 AM',107,35.91)
SELECT * FROM dual;
Expected Result
S.NO
ACCT_NO
GL_CODE
ENTRY_TYPE_LABEL
ENTRY_TYPE_NO
ORIG_CHG_START_DATE
PERIOD_NO
AMT
DESCRIPTION
1
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
100
0
Opening Account
2
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
100
44
Invoice
3
1001
E-11561
Earned Revenue
4
02-OCT-17 08.30.00 AM
100
13.87
Invoice Paid
4
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
100
30.13
Closing Account
5
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
101
30.13
Opening Account
6
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
101
0
Invoice
7
1001
E-11561
Earned Revenue
4
02-OCT-17 08.30.00 AM
101
14.35
Invoice Paid
8
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
101
15.78
Closing Account
9
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
102
15.78
Opening Account
10
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
102
0
Invoice
11
1001
E-11561
Earned Revenue
4
02-OCT-17 08.30.00 AM
102
14.83
Invoice Paid
12
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
102
0.95
Closing Account
13
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
103
0.95
Opening Account
14
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
103
0
Invoice
15
1001
E-11561
Earned Revenue
4
02-OCT-17 08.30.00 AM
103
0.95
Invoice Paid
16
1001
U-11561
Deferred Revenue Credit
2
02-OCT-17 08.30.00 AM
103
0
Closing Account
Description
We must start opening account as zero and end with closing account as zero by doing manipulation with invoice and invoice paid.
Process
Initial Stage
Subsequent stage
Opening Account
0
(=closing Account)
Invoice
max value of account no which has entry type no 2
0
Invoice Paid
taken from the field amount which has entry type no 4
taken from the field amount which has entry type no 4
Closing Account
(=[opening account + invoice] - invoice paid)
(=[opening account + invoice] - invoice paid)
Note
1) Each account may have different periodic no.
2) Some account may have more than 4 distinct period no and less than 4 distinct periodic no.
3) Description column from expected result is not an part of table. It is been added for easier understanding. -
How to Create a new column from two different result sets
How to Create a new column from two different result sets, both the result set uses the different date dimensions.
i got solutions for this is apply filters in column formula it self, based on the requirement.
-
Hide or Remove OCI Check Box column from Standard MDM Result Set iview
Hi,
Can we hide or remove the OCI Check box column from the Standard MDM Result set ivew?
Though i have made OCI disabled, I dont want to display the check boxes along with the product list.
Can you please help?
Thanks and best regards,
Arun prabhu SHi Arun,
If you are talking about the very first check box, then that is not related to OCI. Use of check box is to anable multiple item selection which can be used adding the records in the workflow, for comparison etc.
Regards,
Jitesh Talreja -
How to get Implicit Dimensions/Dimension Values in the result set?
Hi All,
How does endeca return implicitly selected dimensions in the result set? For example, consider a dimension set up for Television data as below.
Brand
Samsung
LG
Philips
Type
LEDs
LCDs
Plasma
Lets say, I refine the result set by brand, by selecting Philips. Now lets assume that there were 2 results returned for philips and both the results were of Type - Plasma. In this case, Endeca does not return the Type dimension in the result set, as we cannot drill down the 2 results further based on LED or LCD.
How does Endeca return these implicit dimensions in the result set in such scenarios? Suppose if there was a requirement to show to the user that both the results were of Type - Plasma, how do we get this information from Endeca, by default?
Thanks in advance :)How does Endeca return these implicit dimensions in the result set in such scenarios?Check out: Navigation.getCompleteDimensions() or Navigation.getCompleteDimGroups()
http://docs.oracle.com/cd/E28910_01/PresentationAPI.622/apidoc/javadoc/navigation/index.html -
How to put entries in a for loop without hard coding the values
I have a below pl/sql block that needs to flag a claim based on claim number values given that I have in an excel sheet. Is there a way to capture those 500 claims efficiently in the select statement in the pl/sql without hardcoding these from value 1 ...to value 500 (as listed below)???
DECLARE
ln_ctr NUMBER := 0;
BEGIN
FOR lrecclaimnumber
IN ( SELECT entityid claimnumber
FROM mpi_fnx.wfTokenEntity wte
WHERE wte.entityid IN
('Value1','Value2',....'Value 500')
LOOP
mpi_fnx.pkgSaveClaimData.spMarkClaimInvalid (pivClaimNumber => lrecclaimnumber.claimnumber,
pininvalidreasonid => 304,
pinuserid => 4999
ln_ctr := ln_ctr + 1;
END LOOP;
DBMS_OUTPUT.put_line ('Total Entries Processed: ' || ln_ctr);
END;
/DECLARE
ln_ctr NUMBER := 0;
BEGIN
FOR lrecclaimnumber
IN ( SELECT entityid claimnumber
FROM mpi_fnx.wfTokenEntity wte
WHERE wte.entityid IN
(select 'Value '|| level as col_name from dual connect by level <=500)
LOOP
mpi_fnx.pkgSaveClaimData.spMarkClaimInvalid (pivClaimNumber => lrecclaimnumber.claimnumber,
pininvalidreasonid => 304,
pinuserid => 4999
ln_ctr := ln_ctr + 1;
END LOOP;
DBMS_OUTPUT.put_line ('Total Entries Processed: ' || ln_ctr);
END;
/ bye
TPD -
Getting maximum and minimum of all values in a result set
Hi,
I want to find the maximum and minimum of values of a column in answers. For example, suppose there are three columns x,y,z and 'x' has values 1,2,3. I want to display the result as:
x y z max(x) min(x)
1 y1 z1 3 1
2 y2 z2 3 1
3 y3 z3 3 1
I tried to use the Max and Min functions. But the result is displayed as
1 y1 z1 1 1
2 y2 z2 2 2
3 y3 z3 3 3
Any help is greatly appreciated.
Thanks,
KK
Edited by: 842704 on Aug 16, 2011 12:44 PMwhere did you give this max and min ?
You need to type Max( column_name) in the formula of the column and dont choose the max function from the dop down of the "Aggregation Rule"
This should work...
Thanks
Ashish -
Include Column type in XML result set
Hi
I'm trying to get result of my query as XML but how I can specify columns data type in xml attributes?
This is my query:
SELECT * FROM Acc.GL FOR XML AUTO, ELEMENTS, TYPE, BINARY BASE64;
Unfortunately in XML result, column types are not specified:
<row>
<Id>23</Id>
<GLCode>1</GLCode>
<BranchRef>1</BranchRef>
<Title>Foo Title</Title>
<Balance>1</Balance>
</row>
<row>
<Id>24</Id>
<GLCode>2</GLCode>
<BranchRef>1</BranchRef>
<Title>Bar Title</Title>
<Balance>1</Balance>
</row>
What I expect is something like this:
<row>
<Id type="int">23</Id>
<GLCode type="int">1</GLCode>
<BranchRef type="int">1</BranchRef>
<Title type="nvarchar">Foo Title</Title>
<Balance type="int">1</Balance>
</row>
<row>
<Id type="int">24</Id>
<GLCode type="int">2</GLCode>
<BranchRef type="int">1</BranchRef>
<Title type="nvarchar">Bar Title</Title>
<Balance type="int">1</Balance>
</row>
What should I change in my query?
Jalalxhow I can specify columns data type in xml attributes?
Hello,
XML Format don't allow to specify the data types in this way, you have to create XSD = "Schema Definition" instead, here are the data types defined.
Olaf Helper
[ Blog] [ Xing] [ MVP] -
How to use column name from subquery result set.
I have these 2 tables
SQL> select * from temp
2 ;
TABLE_NAME COLUMN_NAME TYPE
lst name STATUS
lst val
SQL> select * from lst;
TYPE NAME
VAL
STATUS Pending
Pendiente
STATUS Closed
Cerrado
STATUS ABC
ABSI want to select column_name from temp table and generate select statements.
select name from lst;
select (select COLUMN_NAME from temp where rownum<2) from lst;
SQL> select (select COLUMN_NAME from temp where rownum<2) from lst;
(SELECTCOLUMN_NAMEFROMTEMPWHER
name
name
nameoutput I expect is
SQL> select name from lst;
NAME
Pending
Closed
ABCMichaelS wrote:
Can I do it using SQLe.g.:)
I was just about to post a similar approach (which should work from 10.2 and upwards) :
SQL> SELECT value(x).getRootElement() col_name,
2 extractvalue(value(x),'*') col_value
3 FROM ( SELECT column_name, table_name
4 FROM temp
5 WHERE rownum = 1
6 ) v
7 , XMLTable(
8 '/ROWSET/ROW/*'
9 passing dbms_xmlgen.getXMLType('SELECT '||v.column_name||' FROM '||v.table_name)
10 ) x
11 ;
COL_NAME COL_VALUE
NAME Pending
NAME Closed
NAME ABC -
Row to column conversion in large result set
I need to get the differnt levels of alerts for each user, with the total alert counts and counts for each type of alert.
SELECT COUNT(*) TOTAL,
u.name,
d.deptname,
COUNT(CASE WHEN al.severity = 5 THEN 1 END) INDETERMINATE,
COUNT(CASE WHEN al.severity = 4 THEN 1 END) WARNING,
COUNT(CASE WHEN al.severity = 3 THEN 1 END) MINOR,
COUNT(CASE WHEN al.severity = 2 THEN 1 END) MAJOR,
COUNT(CASE WHEN al.severity = 1 THEN 1 END) CRITICAL
FROM alerts al, user u, dept d
WHERE al.userid = u.userid
AND u.deptid = d.deptid
AND al.time = sysdate - 4/24
AND al.time <= sysdate
GROUP BY u.name, d.deptname This might be inefficient especially when the amount of data is huge and potentially you could be looking at millions of rows in a given interval. So I was thinking of grouping by severity, which would eliminate the CASE statements, but then the problem on group by is that I get it as a rows instead of columns.
Would anyone have a suggestion as to do it effeciently especially one that has millions of rows? Thanks.I guess eventually we are probably going to move towards that, but using a staright forward query is the immediate solution and any help on that would be great. Thanks.
-
Custom row-fetch and how to get column values from specific row of report
Hi -- I have a case where a table's primary key has more than 3 columns. My report on the
table has links that send the user to a single-row DML form, but of course the automatic
fetch won't work because 1) I can't set more than 3 item values in the link and 2) the
auto fetch only handles 2 PK columns.
1)
I have written a custom fetch (not sure it's the most elegant, see second question) that is working
for 3 or few PK columns (it references the 1-3 item values set in the link), but when there are
more than 3, I don't know how to get the remaining PK column values for the specific row that was
selected in the report. How can I access that row's report column values? I'll be doing it from the
form page, not the report page. (I think... unless you have another suggestion.)
2)
My custom fetch... I just worked something out on my own, having no idea how this is typically
done. For each dependent item (database column) in the form, I have a source of PL/SQL
function that queries the table for the column in question, using the primary key values. It works
beautifully, though is just a touch slow on my prototype table, which has 21 columns. Is there
a way to manually construct the fetch statement once for the whole form, and have APEX be smart
about what items get what
return values, so that I don't have to write PL/SQL for every item? Because my query data sources
are sometimes in remote databases, I have to write manual fetch and dml anyway. Just would like
to streamline the process.
Thanks,
CarolHI Andy -- Well, I'd love it if this worked, but I'm unsure how to implement it.
It seems I can't put this process in the results page (the page w/ the link, that has multiple report rows), because the link for the row will completely bypass any after-submit processes, won't it? I've tried this in other conditions; I thought the link went directly to the linked-to page.
And, from the test of your suggestion that I've tried, it's not working in the form that allows a single row edit. I tried putting this manually-created fetch into a before header process, and it seems to do nothing (even with a hard-coded PK value, just to test it out). In addition, I'm not sure how, from this page, the process could identify the correct PK values from the report page, unless it can know something about the row that was selected by clicking on the link. It could work if all the PK columns in my edit form could be set by the report link, but sometimes I have up to 5 pk columns.
Maybe part of the problem is something to do with the source type I have for each of the form items. With my first manual fetch process, they were all pl/sql functions. Not sure what would be appropriate if I can somehow do this with a single (page level?) process.
Maybe I'm making this too hard?
Thanks,
Carol -
I'm using JDev 11.1.1.6 and when I type a value into an af:inputListOfValues component and hit either the enter key or the tab key it will replace the value I entered with the first item in the LOV result set. If enter a value and just click out of the af:inputListOfValues component it works correctly. If I use the popup and search for a value it works correctly as well. I have a programmatic view object which contains a single transient attribute (this is the view object which is used to create the list of value component from) and then I have another entity based view object which defines one of its attributes as a list of value attribute. I tried using an entity based view object to create the LOV from and everything works as expected so I'm not sure if this is a bug when using programmatic view objects or if I need more code in the VOImpl. Also, it seems that after the first time of the value being replaced by the first value in the result set that it will work correctly as well. Below are some of the important code snippets.
Also, it looks like it only doesn't work if the text entered in the af:inputListOfValues component would only have a single match returned in the result set. For instance given the result set in the code: Brad, Adam, Aaron, Fred, Charles, Charlie, Jimmy
If we enter Cha, the component works as expected
If we enter A, the component works as expected
If we enter Jimmy, the component does not work as expected and returns the first value of the result set ie. Brad
If we enter Fred, the component does not work as expected and returns the first value of the result set ie. Brad
I also verified that I get the same behavior in JDev 11.1.1.7
UsersVOImpl (Programmatic View Object with 1 transient attribute)
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import oracle.adf.share.logging.ADFLogger;
import oracle.jbo.JboException;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
// --- File generated by Oracle ADF Business Components Design Time.
// --- Wed Sep 18 15:59:44 CDT 2013
// --- Custom code may be added to this class.
// --- Warning: Do not modify method signatures of generated methods.
public class UsersVOImpl extends ViewObjectImpl {
private static ADFLogger LOGGER = ADFLogger.createADFLogger(UsersVOImpl.class);
private long hitCount = 0;
* This is the default constructor (do not remove).
public UsersVOImpl () {
* executeQueryForCollection - overridden for custom java data source support.
protected void executeQueryForCollection (Object qc, Object[] params, int noUserParams) {
List<String> usersList = new ArrayList<String>();
usersList.add("Brad");
usersList.add("Adam");
usersList.add("Aaron");
usersList.add("Fred");
usersList.add("Charles");
usersList.add("Charlie");
usersList.add("Jimmy");
Iterator usersIterator = usersList.iterator();
setUserDataForCollection(qc, usersIterator);
hitCount = usersList.size();
super.executeQueryForCollection(qc, params, noUserParams);
} // end executeQueryForCollection
* hasNextForCollection - overridden for custom java data source support.
protected boolean hasNextForCollection (Object qc) {
Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
if (usersListIterator.hasNext()) {
return true;
} else {
setFetchCompleteForCollection(qc, true);
return false;
} // end if
} // end hasNextForCollection
* createRowFromResultSet - overridden for custom java data source support.
protected ViewRowImpl createRowFromResultSet (Object qc, ResultSet resultSet) {
Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
String user = (String)usersListIterator.next();
ViewRowImpl viewRowImpl = createNewRowForCollection(qc);
try {
populateAttributeForRow(viewRowImpl, 0, user.toString());
} catch (Exception e) {
LOGGER.severe("Error Initializing Data", e);
throw new JboException(e);
} // end try/catch
return viewRowImpl;
} // end createRowFromResultSet
* getQueryHitCount - overridden for custom java data source support.
public long getQueryHitCount (ViewRowSetImpl viewRowSet) {
return hitCount;
} // end getQueryHitCount
@Override
protected void create () {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
} // end create
@Override
protected void releaseUserDataForCollection (Object qc, Object rs) {
Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
usersListIterator = null;
super.releaseUserDataForCollection(qc, rs);
} // end releaseUserDataForCollection
} // end class
<af:inputListOfValues id="userName" popupTitle="Search and Select: #{bindings.UserName.hints.label}" value="#{bindings.UserName.inputValue}"
label="#{bindings.UserName.hints.label}" model="#{bindings.UserName.listOfValuesModel}" required="#{bindings.UserName.hints.mandatory}"
columns="#{bindings.UserName.hints.displayWidth}" shortDesc="#{bindings.UserName.hints.tooltip}" autoSubmit="true"
searchDesc="#{bindings.UserName.hints.tooltip}"
simple="true">
<f:validator binding="#{bindings.UserName.validator}"/>
</af:inputListOfValues>I have found a solution to this issue. It seems that when using a programmatic view object which has a transient attribute as its primary key you need to override more methods in the ViewObjectImpl so that it knows how to locate the row related to the primary key when the view object records aren't in the cache. This is why it would work correctly sometimes but not all the time. Below are the additional methods you need to override. The logic you use in retrieveByKey would be on a view object by view object basis and would be different if you had a primary key which consisted of more than one attribute.
@Override
protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i) {
return retrieveByKey(viewRowSetImpl, null, key, i, false);
@Override
protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, String string, Key key, int i, boolean b) {
RowSetIterator usersRowSetIterator = this.createRowSet(null);
Row[] userRows = usersRowSetIterator.getFilteredRows("UserId", key.getAttribute(this.getAttributeIndexOf("UserId")));
usersRowSetIterator.closeRowSetIterator();
return userRows;
@Override
protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i, boolean b) {
return retrieveByKey(viewRowSetImpl, null, key, i, b); -
Passing hard-coded string parameters into a FUNCTION
I created a Function that accepts two INT and two VARCHAR2 parameters. I want to access it in a SELECT statement and manually pass in parameters to it.
For example,
SELECT FN_MYFUNC(10, 20, 'string1', 'string2') FROM DUAL;
However, when I do this the hard-coded strings don't seem to be recognized by the Function. But, if I were to pass in a Fieldname from a TABLE then the above function works. Is there something extra I need to do to pass in hard-coded strings into a function?I have pasted the function where this problem is occuring below. If I use it in a SELECT, for example....
SELECT fn_GetRegValueFromRegData(3, 3, 'REG', '119') FROM DUAL;
.....it returns blank everytime when it should return a numeric value. However, this only occurs if I hard-code the parameter values (like above). However, if I pass in fieldnames from a TABLE, for example.....
SELECT fn_GetRegValueFromRegData(RegLink, EeLink, ChqType, RegCode) FROM RegData;
......then I get data back! Any idea why data is returned when I pass in fieldnames but not when I pass in hard-coded parameter values?
=================================================
CREATE OR REPLACE FUNCTION fn_GetRegValueFromRegData
(p_RegLink INT,
p_EELink INT,
p_ChequeType VARCHAR2,
p_RegCode1 VARCHAR2,
p_RegCode2 VARCHAR2 := '-1')
RETURN NUMBER
AS
v_regvalue NUMBER(14,5);
BEGIN
BEGIN
--retrieve data using the REGCODE1 value
SELECT a.regvalue INTO v_regvalue
FROM regdata a
WHERE a.RegCode = p_RegCode1
AND a.RegLink = p_RegLink
AND a.eeLink = p_EELink
AND a.ChqType = p_ChequeType
AND a.EndDate IS NULL;
EXCEPTION
WHEN OTHERS
THEN
--retrieve data using the REGCODE2 value
SELECT a.regvalue INTO v_regvalue
FROM regdata a
WHERE a.RegCode = p_RegCode2
AND a.RegLink = p_RegLink
AND a.eeLink = p_EELink
AND a.ChqType = p_ChequeType
AND a.EndDate IS NULL;
END;
RETURN v_regvalue;
END;
/ -
Can formula column values be used as parameters
Post Author: vdm
CA Forum: Formula
Hi,
I have various formula columns setup in my crystal report, these formula columns act as prompts when end users run the report. i am using crystal reports xi and sql server databse.
Now I would like to use these formula columns to restrict my result set. basically, these should act as predicates (where clauses) to my query.
Is there a way to pass formula columns as parameters to stored procedures or to commands or to simpy add them to a sql query ?
thanks in advancePost Author: foghat
CA Forum: Formula
Have you tried adding the formula fields as a filter in the Record Selection Formula editor?So Report --> Selection Formulas --> Recordand add: {database.field_a} = and {database.field_b} = and so on -
Eliminate repeating column values
Hi,
I have my source table below values:
CLIENT_ID BEGIN_DT END_DT R RES_TYPE_DESC
109800001 20-MAR-97 23-AUG-98 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
109800001 24-AUG-98 03-SEP-98 1 SHIFT STAFF RESIDENTIAL COMPONENT 3 BED
109800001 04-SEP-98 18-MAR-00 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
121874001 20-MAR-98 15-DEC-03 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
121874001 14-MAY-97 15-DEC-03 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
121874001 16-DEC-03 11-MAY-05 4 SUPERVISED LIVING
504407361 07-SEP-97 05-SEP-07 3 OWN/FAMILY HOME
504564902 06-NOV-97 03-NOV-06 3 OWN/FAMILY HOME
506169803 20-AUG-97 31-MAY-99 3 OWN/FAMILY HOME
506169803 01-JUN-99 29-FEB-00 1 SHIFT STAFF RESIDENTIAL COMPONENT 3 BED
506169803 01-MAR-00 18-AUG-02 4 SUPERVISED LIVING
CLIENT_ID BEGIN_DT END_DT R RES_TYPE_DESC
506169803 19-AUG-02 24-JUL-03 5 RESIDENTIAL SUPPORT SERVICE
506169803 25-JUL-03 23-JUN-04 2 FOSTER/COMPANION CARE RESIDENTIAL COMPON
506169803 24-JUN-04 17-AUG-05 5 RESIDENTIAL SUPPORT SERVICE
14 rows selected.
at row no 4 and 5 for client_id = '121874001'
It has repeating END_DT = '15-DEC-03'
I want to have only one record for client_id = '121874001' where BEGIN_DT IS MINIMUM begin_Dt value (i.e. begin_Dt = '14-MAY-97' and END_DT = '15-DEC-03')
so I can have 2 rows instead of 3 rows for client_id = '121874001'
This is part of my table records my table contains multiple clients.
can some one help me writing SQL ?
Thanks in advance
JayTo display non-repeating information while showing the minimun begin_dt, you need to apply the aggregate funtion MIN to the begin_dt column and the GROUP BY clause to the rest of the columns, as follows:
SELECT client_id, MIN(begin_dt) BEGIN_DT, end_dt, r, res_type_desc
FROM your_source_table
GROUP BY client_id, end_dt, r, res_type_desc;
(use your real column names; your pasted result set seems to append some column names)
Good luck,
Luis
Maybe you are looking for
-
Hi All, When i run payment run Vendor is always separated into few line items...Why they cannot be combined together?? Thanks Rafi
-
Storage Bin for Interim Storage Type 902 for GR
Hi, We know that the the dynamic storage bin for goods receipt for PO is the PO number. However, when we are posting GR, system creates TR with interim storage bin as material document number. I looked into the movement type config. However, we can o
-
Hi Friends, I would be getting the date format in yyyyMMdd and i have to display it in dd-MMM-yyyy. I could not see suck option in 'date trans' function. Could some one shed somelight on this.
-
Hi Scenario : Step 10: i've a base price say (proo) for eg 100 Step 20" Tax (mwst) for eg 4%= 4 Step 30 : step 10+step 20 = 104 now my scenario is when i negogatie with my end customer i say it's RS 104 so wen i enter in my sales order the Gross pric
-
Trying to get 32-bit Vista to see more than 2.5 gb of my 4gb ram - T500
Hello all, I've been reading what I'm able to find on the subject, and have tried the following suggestions from (http://www.ocmodshop.com/ocmodshop.aspx?a=989) to bump up the amount of physical ram that Vista sees. I've tried to forceenable pae, and