Oracle Traspostion of Col to Rows
Hi
I have A table after processing a file like
Building Person
B New
P AMit
B Old
P Raj
B Old
P akshay
B New
P Atul
Value B: Building
P: Person
there are Only Two Values for Building i.e. New,Old
I need Output as :
Building
Person
New
AMit
Old
Raj
Old
akshay
New
Atul
Please Suggest Query for it.
I am able to Make
Building
Person
New
null
null
AMit
Old
null
null
Raj
Old
null
null
akshay
New
null
null
Atul
by this following query
select
decode( Building, 'New', Person, null ) Building,
decode( Building, 'Old', Person, null ) Person
from my_table;
Can i implement this in Interface.
Pl do not post duplicates - Column to Rows Convertion...or Transpose.
Similar Messages
-
Can you intercept an Oracle error from a "Process Row" process?
Hi,
Can you intercept an Oracle error from a "Process Row" process?
Example:
I have been just creating a validation process to check if I'm about to insert a duplicate record so I can give the user a "User friendly" error message.
It would be awesome if in the error message you can select "PL/SQL function returning result" and have it pass it to the Notification area..
I doubt there is a way but I thought I would ask..>
I think everyone is waiting for a better exception-handling, but even 4.0 won't bring any improvements in this area.This is kind of what bugged me about 4.0. I feel that they put more effort into making it cool and flashy and ignored some pretty basic core issues like error handling. I mean sure the new jquery powered application builder is nice, but your users never see that - they do however see you not being able to hook into the error handling. There are several issues that have lingered for years that keep getting passed over for other things - i mean the Forms conversion release was such a waste in my opinion. They could have used that release to fix some bugs.
Of course thats my 2 cents. -
Oracle.jbo.RowNotFoundException: JBO-25034: Row with handle not found
Hello,
I am developing a fusion web application on Jdeveloper 11.1.2.1.0.
I have a ADF table which is bound to a table in the backing bean. There is a "Process" button for each row that works completely fine. There is button called "Process All" beneath the table especially designed to do some processing with all the rows.. When I click the button, following happens with every row
1) A call is made to a webservice
2) Results from the webservice needs to be updated on that row in the database.
There is a process button for each row that works completely fine.
I am successful with the above two points for the first row. But when the control gets to the second row, results from webservice are retrieved but updating the results in the database is where I am seeing the problem.
I am doing the update via ApplicationmoduleImpl.java method:
public void markEFTTransaction(int eft_id)
System.out.println("In Application module markEFTTransaction");
System.out.println("EFT ID to mark is" + eft_id);
DBTransaction trans = getDBTransaction();
try
CallableStatement cs = trans.createCallableStatement("begin ? := ai.ba_p003_eft.mark_eft_transaction(?); end;", 0);
cs.registerOutParameter(1,Types.VARCHAR);
cs.setInt(2, eft_id);
cs.executeUpdate();
String result = cs.getString(1);
System.out.println(result);
if (result.equalsIgnoreCase("N"))
System.out.println("committed to database");
getTransaction().commit();
else
System.out.println("\n Transaction rolled back. \n");
getTransaction().rollback();
cs.close();
} catch (Exception e)
System.out.println("Exception is " + e);
view scope bean method:
public String ProcessAll()
RowKeySet rks = new RowKeySetImpl();
CollectionModel model = (CollectionModel)nonProcessedTable.getValue();
int rowcount = model.getRowCount();
for (int i = 0; i < rowcount; i++) {
model.setRowIndex(i);
Object key = model.getRowKey();
rks.add(key);
nonProcessedTable.setSelectedRowKeys(rks);
// Add event code here...
List<String> updateList = new ArrayList<String>();
RowKeySet selectedTransaction = nonProcessedTable.getSelectedRowKeys();
Iterator selectedTransactionIter = selectedTransaction.iterator();
System.out.println("we have " + nonProcessedTable.getSelectedRowKeys().size() + " rows selected");
DCBindingContainer bindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding transactionIter = bindings.findIteratorBinding("eftTransactionsforBillingAccountViewObj1Iterator");
RowSetIterator transactionRSIter = transactionIter.getRowSetIterator();
//Select Rows and perform transaction
while(selectedTransactionIter.hasNext())
Key key = (Key)((List)selectedTransactionIter.next()).get(0);
System.out.println("Key is" +key);
Row currentRow = transactionRSIter.getRow(key);
System.out.println("EFTT ID IS"+currentRow.getAttribute("efttId"));
Utilities.getApplicationModule().markEFTTransaction(Integer.parseInt(currentRow.getAttribute("efttId").toString()));
return null;
Output:
we have 26 rows selected
Key isoracle.jbo.Key[101 741 ]
Source breakpoint: unProcessedBean.java:443
EFTT ID IS741
<BindingContext> <findDataControl> [697] INFO: no refreshRegion, skipping cpx codebase lookup on AppModuleDataControl
In Application module markEFTTransaction
EFT ID to mark is741
N
committed to database
<ADFLogger> <begin> Commit transaction
<ViewObjectImpl> <afterCommit> [698] eftTransactionsforBillingAccountViewObj1 notify COMMIT ...
<DBTransactionImpl> <clearEntityCacheInternal> [699] Clearing EO cache for com.alliednational.ai.authorize.net.model.entities.bla
<ViewObjectImpl> <doClearCache> [700] Clearing VO cache for eftTransactionsforBillingAccountViewObj1
<ViewObjectImpl> <clearQueryCollectionCache> [701] Clear QueryCollection in cache for VO eftTransactionsforBillingAccountViewObj1
<ViewObjectImpl> <doClearCache> [702] Clearing VO cache for blaeftDetailViewObj1
<ViewObjectImpl> <clearQueryCollectionCache> [703] Clear QueryCollection in cache for VO blaeftDetailViewObj1
<DBTransactionImpl> <clearEntityCacheInternal> [704] Clearing EO cache for com.alliednational.ai.authorize.net.model.entities.eftt
<ViewObjectImpl> <doClearCache> [705] Clearing VO cache for eftTransactionsforBillingAccountViewObj1
<ViewObjectImpl> <clearQueryCollectionCache> [706] Clear QueryCollection in cache for VO eftTransactionsforBillingAccountViewObj1
<ViewObjectImpl> <doClearCache> [707] Clearing VO cache for blaeftDetailViewObj1
<ViewObjectImpl> <clearQueryCollectionCache> [708] Clear QueryCollection in cache for VO blaeftDetailViewObj1
<ADFLogger> <addContextData> Commit transaction
<ADFLogger> <end> Commit transaction
Key isoracle.jbo.Key[135 863 ]
<ActionListenerImpl> <processAction> oracle.jbo.RowNotFoundException: JBO-25034: Row with handle 13 is not found in rowset eftTransactionsforBillingAccountViewObj1.
javax.faces.el.EvaluationException: oracle.jbo.RowNotFoundException: JBO-25034: Row with handle 13 is not found in rowset eftTransactionsforBillingAccountViewObj1.
at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:965)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:346)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:204)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:173)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:122)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:293)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:199)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:180)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
Caused by: oracle.jbo.RowNotFoundException: JBO-25034: Row with handle 13 is not found in rowset eftTransactionsforBillingAccountViewObj1.
at oracle.jbo.server.ViewRowSetImpl.getRowFromHandle(ViewRowSetImpl.java:3220)
at oracle.jbo.server.ViewRowSetImpl.getRow(ViewRowSetImpl.java:3307)
at oracle.jbo.server.ViewRowSetImpl.getRow(ViewRowSetImpl.java:3294)
at oracle.jbo.server.ViewObjectImpl.getRow(ViewObjectImpl.java:10772)
at com.alliednational.ai.authorize.net.view.beans.unProcessedBean.ProcessAll(unProcessedBean.java:442)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(Unknown Source)
at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)
... 46 more
Any help is appreciated!!!
Shailaja.This error is often the result of an activation/passivation problem in the application. Have you tested your app with application module pooling turned off?
If not I suggest that you do this and make sure all errors coming up in this mode to be fixed first. After the app runs OK with application module pooling turned off check if the error still occurs.
Timo -
Has anyone been able to create a HtmlDataTable with dynamic col and rows?
Has anyone been able to create a HtmlDataTable with dynamic col and rows?
If so please explain. I am successfully able to dynamically add columns using the getChildren method of the htmldatatable object
BUT for each new column created no data is displayed.
I am only able to display data for columns originally created when i clicked and dragged the dataTable icon from the pallette in netbeans visual web kit.
Any help on this is greatly appreciated. I have been searching the web and these forums for around 8 hours and no one seems to have a working example of this. Lots of similar posts asking how to do it though :(
Thanks in advance.This might be useful: http://balusc.xs4all.nl/srv/dev-jep-dat.html
-
Col-to-Rows needed for MINUS later
Query 1
SCOTT@orcl>SELECT CUST_NAME, DOD_PROD_CODE, to_char(DOD_DOH_NO,999999) DOD_DOH_no,
2 to_char(DOH_SO_REF_NO,999999) DOH_SO_REF_NO
3 FROM DELIVERY_ORDER_HEADER, DELIVERY_ORDER_DETAIL, CUSTOMER_MASTER
4 WHERE DOH_NO = DOD_DOH_NO
5 AND DOH_PARTY_CODE = CUST_CODE
6 AND DOH_SO_REF_NO = 13
7 ORDER BY 2;
CUST_N DOD_PROD_CODE DOD_DOH DOH_SO_
ENERGY P01033691.1 11 13
ENERGY P01033691.5 11 13
ENERGY P01033691.5 12 13
ENERGY P01033691.7 11 13
ENERGY P01033691.7 12 13
ENERGY P01033691.8 12 13
ENERGY P0140000014 11 13
ENERGY P01400012 11 13
8 rows selected.Query 2
SCOTT@orcl>SELECT CUST_NAME, SALEVD_PROD_CODE, SALEVH_DO_REF_NO,
2 to_char(SALEVH_SO_REF_NO,999999) SALEVH_SO_REF_NO
3 FROM SALES_INVOICE_HEADER, SALES_INVOICE_DETAIL,CUSTOMER_MASTER
4 WHERE SALEVH_NO = SALEVD_SALEVH_NO
5 AND SALEVH_PARTY_CODE = CUST_CODE
6 AND SALEVH_SO_REF_NO = 13
7 ORDER BY 2;
CUST_N SALEVD_PROD_COD SALEVH_DO_ SALEVH_
ENERGY P01033691.1 11,12 13
ENERGY P01033691.5 11,12 13
ENERGY P01033691.7 11,12 13
ENERGY P01033691.8 11,12 13
ENERGY P0140000014 11,12 13
ENERGY P01400012 11,12 13
6 rows selected.i want Query No.2 to be exactly returning the same number of rows, like Query No.1 - 8 Rows.
for example, in Query 1, there are 2 rows returned for product code P01033691.5 & P01033691.7,
whereas in Query 2 they are shown on single rows.
This is not the only case, the situaton may change where there can be more than 2 or just 1 values (in this case 11,12)
for SALEVH_DO_REF_NO Col. in Query 2.
i want to always break Col-to-Rows for Query 2,
based on the DOD_PROD_CODE & DOD_DOH_NO of Query 1 matching with SALEVD_PROD_CODE, SALEVH_DO_REF_NO of Query 2 .
so that it will become easier finally to use MINUS between both Queries like this;
Query 3
SELECT CUST_NAME, DOD_PROD_CODE, to_char(DOD_DOH_NO,999999) DOD_DOH_no,
to_char(DOH_SO_REF_NO,999999) DOH_SO_REF_NO
FROM DELIVERY_ORDER_HEADER, DELIVERY_ORDER_DETAIL, CUSTOMER_MASTER
WHERE DOH_NO = DOD_DOH_NO
AND DOH_PARTY_CODE = CUST_CODE
AND DOH_SO_REF_NO = 13
MINUS
SELECT CUST_NAME, SALEVD_PROD_CODE, SALEVH_DO_REF_NO,
to_char(SALEVH_SO_REF_NO,999999) SALEVH_SO_REF_NO
FROM SALES_INVOICE_HEADER, SALES_INVOICE_DETAIL,CUSTOMER_MASTER
WHERE SALEVH_NO = SALEVD_SALEVH_NO
AND SALEVH_PARTY_CODE = CUST_CODE
AND SALEVH_SO_REF_NO = 13as per the above data the Query3 should not return any rows, but lets say a row gets added to Query 1 result,
i mean a new DOD_DOH_NO for the same DOH_SO_REF_NO. a 9th row for example;
ENERGY P01400012 13 13
and theres is no Invoice done, then Query 3 should return just 1 row which is just the above 1, the 9th row.
any help will be highly appreciated. TYMr. Massimo,
Your Query MUST return rows and those should be the following 8 rows;
CUST_NAME SALEVD_PROD_COD SALEVH_ SALEVH_
ENERGY P01033691.1 11 13
ENERGY P01033691.5 11 13
ENERGY P01033691.7 11 13
ENERGY P01400012 11 13
ENERGY P0140000014 11 13
ENERGY P01033691.5 12 13
ENERGY P01033691.7 12 13
ENERGY P01033691.8 12 13
8 rows selected.
Your Latest Query returned no rows at all;
SCOTT@orcl>SELECT CUST_NAME, DOD_PROD_CODE, to_char(DOD_DOH_NO,999999) DOD_DOH_no,
2 to_char(DOH_SO_REF_NO,999999) DOH_SO_REF_NO
3 FROM DELIVERY_ORDER_HEADER doh, DELIVERY_ORDER_DETAIL dod, CUSTOMER_MASTER c
4 WHERE DOH_NO = DOD_DOH_NO
5 AND DOH_PARTY_CODE = CUST_CODE
6 AND 0 = (select count(0) FROM SALES_INVOICE_HEADER, SALES_INVOICE_DETAIL,CUSTOMER_MASTER c2
7 WHERE SALEVH_NO = SALEVD_SALEVH_NO
8 AND SALEVH_PARTY_CODE = CUST_CODE
9 AND SALEVH_SO_REF_NO = DOH_SO_REF_NO
10 AND c2.CUST_NAME=c.CUST_NAME
11 AND SALEVD_PROD_CODE = DOD_PROD_CODE
12 AND regexp_like(SALEVH_DO_REF_NO ,'(^|,)'||to_char(DOD_DOH_NO,999999)||'(,|$)')
13 AND to_char(SALEVH_SO_REF_NO,999999) = to_char(DOH_SO_REF_NO,999999))
14 AND 0 < (select count(0) FROM SALES_INVOICE_HEADER, SALES_INVOICE_DETAIL
15 WHERE SALEVH_NO = SALEVD_SALEVH_NO
16 AND SALEVH_SO_REF_NO = DOH_SO_REF_NO
17 AND regexp_like(SALEVH_DO_REF_NO ,'(^|,)'||to_char(DOD_DOH_NO,999999)||'(,|$)'));
no rows selectedi will rephrase and putting my case again. i am sure this time you;ll have better grasp on it.
These are the records for Items actually Delivered,columns are;
Customer Name = CUST_NAME
Item Code = DOD_PROD_CODE
Deliver Order No. = DOD_DOH_NO (NUMBER)
Sales Order Ref. No. = DOH_SO_REF_NO
SELECT CUST_NAME, DOD_PROD_CODE, to_char(DOD_DOH_NO,999999) DOD_DOH_no,
to_char(DOH_SO_REF_NO,999999) DOH_SO_REF_NO,DOD_QTY_DISPATCHED
FROM DELIVERY_ORDER_HEADER, DELIVERY_ORDER_DETAIL, CUSTOMER_MASTER
WHERE DOH_NO = DOD_DOH_NO
AND DOH_PARTY_CODE = CUST_CODE
ORDER BY 3;
CUST_NAME DOD_PROD_CODE DOD_DOH DOH_SO_ DOD_QTY_DISPATCHED
TOPAZ P01400034 9 14 4
TOPAZ P01025299.5 9 14 8
TOPAZ P01025299.7 9 14 15
TOPAZ P0140000010 9 14 2
TOPAZ P01025299.2 9 14 10
TOPAZ P01025299.9 9 14 10
TOPAZ P01025299.3 9 14 10
ENERGY P01033691.1 11 13 2
ENERGY P01033691.5 11 13 4
ENERGY P01033691.5 12 13 4
ENERGY P01033691.7 11 13 5
ENERGY P01033691.7 12 13 5
ENERGY P01033691.8 12 13 5
ENERGY P01400012 11 13 3
ENERGY P0140000014 11 13 10
ENERGY P01033691.7 13 13 2
ENERGY P01033691.8 13 13 5
17 rows selected.
Query No. 2
The following are the Invoice issued for the Items Delivered above.
Not all Invoices have been issued, still left, are for DOD_DOH_NO 9 & 13.
The columns are ;
Customer Name = CUST_NAME
Item Code = SALEVD_PROD_CODE
Invoice Deliver Order Ref.No. = SALEVH_DO_REF_NO (VARCHAR2)
Sales Order Ref. No. = SALEVH_SO_REF_NO
SELECT SUBSTR(CUST_NAME,9,6) CUST_NAME, SALEVD_PROD_CODE, SALEVH_DO_REF_NO,
to_char(SALEVH_SO_REF_NO,999999) SALEVH_SO_REF_NO
FROM SALES_INVOICE_HEADER, SALES_INVOICE_DETAIL,CUSTOMER_MASTER
WHERE SALEVH_NO = SALEVD_SALEVH_NO
AND SALEVH_PARTY_CODE = CUST_CODE;
CUST_N SALEVD_PROD_COD SALEVH_DO_ SALEVH_ SALEVD_QTY
ENERGY P01033691.1 11,12 13 2
ENERGY P01033691.5 11,12 13 8
ENERGY P01033691.7 11,12 13 10
ENERGY P01033691.8 11,12 13 5
ENERGY P01400012 11,12 13 3
ENERGY P0140000014 11,12 13 10
6 rows selected.
Note: SALEVH_DO_REF_NO is VARCHAR2 field, that i have used save DOD_DOH_NO (type NUMBER) values,
in comma separated manner, offering user to club more than 1 Delivery Orders on a single Invoice.
Therefore i want a query that will turn Query2 result to something like;
CUST_NAME SALEVD_PROD_COD SALEVH_ SALEVH_
ENERGY P01033691.1 11 13
ENERGY P01033691.5 11 13
ENERGY P01033691.7 11 13
ENERGY P01400012 11 13
ENERGY P0140000014 11 13
ENERGY P01033691.5 12 13
ENERGY P01033691.7 12 13
ENERGY P01033691.8 12 13
8 rows selected. -
How to delete duplicate rows in oracle and retaining last duplicate rows
Hi,
I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
I just want to delete duplicate rows but also want to retain the last duplicate row.
For eg if one record is found three times ,i want to delete first and second record and retain
the third one i.e the last inserted one.
Regards
Paramdeep Singhuser13310594 wrote:
Hi,
I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
I just want to delete duplicate rows but also want to retain the last duplicate row.
For eg if one record is found three times ,i want to delete first and second record and retain
the third one i.e the last inserted one.Hi Paramdeep,
To start with, since you do not wish to keep multiple rows with same values, why allow them to get inserted in the first place?
Wouldn't it be easier to block duplicate rows from inserting by creating a Unique constraint on Column(s) that define a row as duplicate, then rather deleting duplicate rows periodically?
For deleting duplicate rows, there are N number of techniques available. Always remember, you need to have a rigid criteria that marks row as duplicate.
[url http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15258974323143]this is one recomended by tom for large tables.
Vivek L -
Obiee oracle gateway error while updating row count
Hi ,
OBIEE server 11.1.1.5 ,oracle server11g installed in linux 64bit,
while updating row count in Admin tool i am getting the following error
[NQODBC][SQL_STATE:HY000][nQSError:10058] A general error has occured.
[nQSError: 43113]Message returned from OBIS.
[nQSError:43093]An error occured while processing the EXECUTE PHYSICAL statement.
[nQSError:17003]Oracle gateway error: OCIEnvNIsCreate or OCIEnvInit failed to initialize environment.Please check your Oracle Client installation and make sure the correct version of OCI libraries are in the library path.
i am able to check the database from sqlplus it is working fine.
Any suggestion highly appreciated plzzzMake sure your connection pool is valid and able to import or execute reports.
If everything good as above said, in Physical layer database properties-> general tab choose the database version and try it once.
If not
Check the doc id 1271486.1
Or
To resolve the issue create a softlink (ln -s) in the <OracleBI>/server/Bin folder to link to the 32-bit Oracle Client Driver file.
The example below shows how to perform a softlink from the 64 bit directory:
cd /u10/app/orcladmin/oracle/OracleBI/server/Bin
ln -s $ORACLE_HOME/lib32/libclntsh.so.10.1 libclntsh.so.10.1
If helps mark -
[Oracle 8i] Query for N rows by column value?
I was just wondering if what I want to do is possible within my query (rather than programmatically)...
I want to return the N most recent records for each unique value in a particular column.
Here's a sample table:
CREATE TABLE orders
( order_no numeric(10)
part_no varchar(5)
close_date date
order_qty numeric(10)
scrap_qty numeric(10)
CONSTRAINT order_pk PRIMARY KEY (order_no)
);And some sample data....
INSERT INTO orders VALUES
(0000012345,'ABC-1',TO_DATE('01-01-2010','mm-dd-yyyy'),10,1);
INSERT INTO orders VALUES
(0000013498,'ABC-1',TO_DATE('01-05-2010','mm-dd-yyyy'),12,2);
INSERT INTO orders VALUES
(0000033452,'ABC-1',TO_DATE('01-10-2010','mm-dd-yyyy'),5,0);
INSERT INTO orders VALUES
(0000001468,'ABC-1',TO_DATE('01-15-2010','mm-dd-yyyy'),15,1);
INSERT INTO orders VALUES
(0000022349,'BR723',TO_DATE('01-03-2010','mm-dd-yyyy'),8,1);
INSERT INTO orders VALUES
(0000069581,'BR723',TO_DATE('01-05-2010','mm-dd-yyyy'),5,0);
INSERT INTO orders VALUES
(0000436721,'BR723',TO_DATE('01-10-2010','mm-dd-yyyy'),14,1);
INSERT INTO orders VALUES
(0000213446,'A5001',TO_DATE('01-06-2010','mm-dd-yyyy'),5,1);
INSERT INTO orders VALUES
(0000327987,'A5001',TO_DATE('01-08-2010','mm-dd-yyyy'),5,0);
INSERT INTO orders VALUES
(0000041353,'A5001',TO_DATE('01-14-2010','mm-dd-yyyy'),12,1);
INSERT INTO orders VALUES
(0000011241,'A5001',TO_DATE('01-15-2010','mm-dd-yyyy'),5,1);In this example, what I want to return are the 2 most recent orders (by close_date) for each part number.
Here is a table with the results I want to get, based on the scenario above:
order_no part_no close_date order_qty scrap_qty
0000001468 'ABC-1' '01-15-2010' 15 1
0000033452 'ABC-1' '01-10-2010' 5 0
0000436721 'BR723' '01-10-2010' 14 1
0000069581 'BR723' '01-05-2010' 5 0
0000011241 'A5001' '01-15-2010' 5 1
0000041353 'A5001' '01-14-2010' 12 1Is it possible to write a query to get these results, or am I going to have to query for all available data, and find the 2 most recent rows programmatically?
Thanks in advance!Hi,
user11033437 wrote:
I'm going to test that out right now. I think if it works, I may need to use dense_rank() rather than rank(), because it is possible that two orders for the same part number could have the same close date, and according to what I've looked up on the rank() and dense_rank() functions, rank() can give non-consecutive results if the values are the same.What's wrong with non-consecutive values?
Use RANK, DENSE_RANK or ROW_NUMBER depending on what you want.
For example; say a certain part has been ordered 8 times:
3 times with close_date January 29, 2010 (all at exactly the same time),
4 times with close_date January 28, 2010 (all at exactly the same time), and
1 time with close_date January 27, 2010.
If you ask for the last 2 rows:
RANK will give you the 3 rows from January 29. (All 3 have an equal claim to being in the top 2.)
DENSE_RANK will give you the 7 rows from January 28-29 (the last two values , regardless of how many rows have them).
ROW_NUMBER will give you 2 rows from January 29. (Which 2? It's arbitrary unless you add a tie-breaker to the ORDER BY clause.)
All these functions are available in Oracle 8.1. -
How Can i convert the Columns In to Row in a oracle Select Query ?
If the data is like this...
CTRY DT WT
KSA 20-MAR-09 200
KSA 02-MAY-09 20
UAE 22-JAN-09 20
UAE 02-JAN-09 30
UAE 22-MAY-09 20
we can convrt the rows dt into columns like this (We have done month wise ..We can chage the query to do
data wise)
SELECT CTRY,
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'JAN-2011' THEN SUM(WT) ELSE '' END AS 'JAN-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'FEB-2011' THEN SUM(WT) ELSE '' END AS 'FEB-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'MAR-2011' THEN SUM(WT) ELSE '' END AS 'MAR-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'APR-2011' THEN SUM(WT) ELSE '' END AS 'APR-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'MAY-2011' THEN SUM(WT) ELSE '' END AS 'MAY-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'JUN-2011' THEN SUM(WT) ELSE '' END AS 'JUN-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'JUL-2011' THEN SUM(WT) ELSE '' END AS 'JUL-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'AUG-2011' THEN SUM(WT) ELSE '' END AS 'AUG-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'SEP-2011' THEN SUM(WT) ELSE '' END AS 'SEP-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'OCT-2011' THEN SUM(WT) ELSE '' END AS 'OCT-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'NOV-2011' THEN SUM(WT) ELSE '' END AS 'NOV-2011',
CASE TO_CHAR(DT,'MON-YYYY') WHEN 'DEC-2011' THEN SUM(WT) ELSE '' END AS 'DEC-2011'
FROM TAB1
GROUP BY CTRY,TO_CHAR(DT,'MON-YYYY'); -
Suppress COL and ROW based actual period and previous one
Hi!
Here is a problem I am trying to solve:
Lets say you have in COL a list of products and in ROW a list of client.
Most of the products bought by the client are the same month after month...
Most of the clients are the same month after month...
So I would like my COL to suppress depending on period N and period N-1 because my products hardly change. To add a new one, I will put the INSERT = Y in my expansion.
I would like my ROW to suppress depending on period N and period N-1 because in the long list of my clients, only some of them buy my products. To add new clients, I will put the INSERT = Y in my expansion.
I hope the definition of my problem above is good, here is how I try to solve it in my EVDRE;
PARAMETER EXPANSION 1 | EXPANSION 2
ExpandIn ROW | COL
Dimension Product | Client
MemberSet basmembers | basmembers
BeforeRange |
AfterRange |
Suppress [2009.JAN,2009.FEB ] | [2009.JAN,2009.FEB]
Insert y | y
It doesnt work!
When I have data in January, and I check February the expansion returns totaly empty!!
Thanks for your help
Nic
NB: I forgot to add that I am running SP3 v 5.0.502.03
Edited by: Nicolas Argente on Jul 16, 2008 4:22 PMFor your information, I also raised a ticket at SAP Support Portal from this problem. I will keep you updated with this problem.
Nic -
Oracle Query failing for multiple rows:
Hey Guys,
I have been given a task to produce an ad-hoc report based on the following conditions (I will give you the structure of the table and details in the table below the requirements)
Requirements: Adhoc Report for Audit on CIT Income Allocation
1. Select from the RETURNS table:
• Id > 3600000 and
• Prog_program_cd = '01' and
• Return_status in ('ASSESSED', 'DU") and
• Tax year ending in 2009 (i.e. year portion of the Period_end_date is in 2009)
2. Retrieve the following fields from the RETURNS table :
• Id
• Entp_abn
• Acct_id
• Prog_program_cd
• Period_start_date
• Period_end_date
• Amend_ind
• Return_status
• Status_date
• Loctr_nbr
3. If there are multiple entries from the same account and tax year, only retain the latest record: From the records selected in step 2, if there are multiple records with the same Acct_Id and Period_end_date, only retain the record with the most recent Status_date (i.e. MAX value on the date).
4. Using the results from step 3, link to the applicable RETURN_LINE_ITEMS table where:
• RETURNS.Id = RETURN_LINE_ITEMS.Rtrn_Id
5. From the selected return on RETURN_LINE_ITEMS table, retrieve records where (value on Sch 000 Line 062 > 500,000) and (value on Sch 000 Line 066 < value on Sch 000 Line 062) :
• Sched_nbr = '000', and Litm_line_item_nbr = '062', and Active_ind = 'Y', get Revise_val_amt as 'ab_taxable_income'
• Sched_nbr = '000', and Litm_line_item_nbr = '066', and Active_ind = 'Y', get Revise_val_amt as 'amt_taxable_in_ab'
• Retain the return only if (ab_taxable_income > 500,000) and (amt_taxable_in_ab < ab_taxable_income)
The tables used in this are : RETURNS and RETURN_LINE_ITEMS
Structure of RETURNS table is:
ID
PROG_PROGRAM_CD
ACCT_ID
ACPE_ID
JENT_ID
PREV_RTRN_ID
ENTP_ABN
ACCT_OCCURNC_NBR
SOURCE_TYPE
RECEIVE_DATE
AMEND_IND
CMPLT_IND
PENALTY_OR_IND
RETURN_STATUS
STATUS_DATE
STATUS_USERID
PERIOD_START_DATE
PERIOD_END_DATE
NOTICE_STATUS
NOTICE_STATUS_DATE
NOTE_TEXT
PENALTY_OR_BY
PENALTY_OR_TMST
FILING_ID
CASE_ID
DOC_CONTRL_NBR
LOCTR_NBR
STATUTE_BARRED_DATE
MEDIA_TYPE
DISPSTN_TYPE
AMEND_TYPE
CALC_MODE
PROCESS_PASS_CNT
CONVRTD_IND
LOSS_PERIOD_END_DATE
MF_SYNC_CD
CREATED_BY
CREATED_TMST
MODIFIED_BY
MODIFIED_TMST
Structure of RETURN_LINE_ITEMS is:
ID
RTSC_ID
RTRN_ID
SCLI_ID
LITM_ID
ENTP_ABN
PROG_PROGRAM_CD
ACCT_OCCURNC_NBR
ACPE_END_DATE
SCHED_NBR
SCHD_VERSION_YR
SCHD_VERSION_NBR
RTSC_OCCUR_NBR
LITM_LINE_ITEM_NBR
SLIN_LINE_ITEM_ID
OCCUR_NBR
PREV_VAL_MOD_IND
VIABLE_IND
ACTIVE_IND
ACTION_CD
PREV_VAL_AMT
REVISE_VAL_AMT
PREV_VAL_TEXT
REVISE_VAL_TEXT
DISPLAY_SEQ_NBR
SYS_VAL_AMT
LITM_INNER_PASS_SEQ_NBR
CREATED_BY
CREATED_TMST
MODIFIED_BY
MODIFIED_TMST
So scripts to create the able tables are:
RETURNS
CREATE TABLE RETURNS
ID NUMBER(12),
PROG_PROGRAM_CD VARCHAR2(2 BYTE),
ACCT_ID NUMBER(12),
ACPE_ID NUMBER(12),
JENT_ID NUMBER(12),
ENTP_ABN NUMBER(9),
ACCT_OCCURNC_NBR NUMBER(4),
SOURCE_TYPE VARCHAR2(30 BYTE) DEFAULT 'BLANK',
RECEIVE_DATE DATE,
AMEND_IND VARCHAR2(1 BYTE) DEFAULT 'N',
CMPLT_IND VARCHAR2(1 BYTE) DEFAULT 'N',
PENALTY_OR_IND VARCHAR2(1 BYTE) DEFAULT 'N',
RETURN_STATUS VARCHAR2(12 BYTE),
STATUS_DATE DATE,
STATUS_USERID VARCHAR2(8 BYTE),
PERIOD_START_DATE DATE,
PERIOD_END_DATE DATE,
NOTICE_STATUS VARCHAR2(12 BYTE),
NOTICE_STATUS_DATE DATE,
LOCTR_NBR NUMBER(10),
MEDIA_TYPE VARCHAR2(30 BYTE),
DISPSTN_TYPE VARCHAR2(30 BYTE),
CONVRTD_IND VARCHAR2(1 BYTE) DEFAULT 'N')
RETURN_LINE_ITEMS
CREATE TABLE RETURN_LINE_ITEMS
ID NUMBER(12),
RTSC_ID NUMBER(12),
RTRN_ID NUMBER(12),
LITM_ID NUMBER(12),
ENTP_ABN NUMBER(9),
PROG_PROGRAM_CD VARCHAR2(2 BYTE),
ACCT_OCCURNC_NBR NUMBER(4),
ACPE_END_DATE DATE,
SCHED_NBR VARCHAR2(3 BYTE),
SCHD_VERSION_YR NUMBER(4) DEFAULT 0,
SCHD_VERSION_NBR NUMBER(3),
RTSC_OCCUR_NBR NUMBER(3),
LITM_LINE_ITEM_NBR VARCHAR2(3 BYTE),
SLIN_LINE_ITEM_ID NUMBER(12),
OCCUR_NBR NUMBER(3) DEFAULT 1,
PREV_VAL_MOD_IND VARCHAR2(1 BYTE) DEFAULT 'N',
VIABLE_IND VARCHAR2(1 BYTE) DEFAULT 'N',
ACTIVE_IND VARCHAR2(1 BYTE) DEFAULT 'Y',
PREV_VAL_AMT NUMBER(15,2),
REVISE_VAL_AMT NUMBER(15,2),
DISPLAY_SEQ_NBR NUMBER(3),
SYS_VAL_AMT NUMBER(15,2),
LITM_INNER_PASS_SEQ_NBR NUMBER(3)
So when you run the scripts above, the tables are created (I have tested it in TOAD)
Now let's feed data into both the tables
RETURNS table:
insert into RETURNS
VALUES
(3602448 , '01' ,288151,3876821,9345370 , 403232531, 1, 'TAXPAYER' ,12/4/2008 ,'N', 'Y','N','ASSESSED', 2/18/2009,'SANDEEP',1/2/2008,1/2/2009,
'PRINTED','2/18/2009, 6043073664,'PAPER', 'NOTICE','N');
insert into RETURNS
VALUES
(4117092 , '01' ,57794,3864551,10566221 , 400571410, 1, 'TAXPAYER' ,6/30/2010 ,'N', 'Y','N','ASSESSED', 2/18/2009,'SANDEEP',1/2/2008,1/2/2009,
'PRINTED','2/18/2009, 6043073664,'PAPER', 'NOTICE','N');
RETURN_LINE_ITEMS table:
INSERT INTO RETURN_LINE_ITEMS
VALUES
(266000770,7749234,3602448,1603,403232531, 01, 1, 1/1/2009, 000, 1998, 1,1, '062', 40,1, 'N','Y', -5440, -5440, 200,-5440,130);
INSERT INTO RETURN_LINE_ITEMS
VALUES
(266000773,7749234,3602448,1539,403232531, 01, 1, 1/1/2009, 000, 1998, 1,1, '066', 43,1, 'N','Y', NULL, 0, 215,0,200);
INSERT INTO RETURN_LINE_ITEMS
VALUES
(319820233,9028477,4117092,1603,400571410, 01, 1, 1/1/2009, 000, 1998, 1,1, '062', 40 ,1, 'N','Y', 790068, 790068, 200,790068,130);
INSERT INTO RETURN_LINE_ITEMS
VALUES
(319820236,9028477,4117092,1539,400571410, 01, 1, 1/1/2009, 000, 1998, 1,1, '062', 40 ,1, 'N','Y', NULL, 790, 215,790068,200);
This completes the test data.
Now based on the question posed by the Business Analyst, until "5 b" i.e where it's said:
Sched_nbr = '000', and Litm_line_item_nbr = '066', and Active_ind = 'Y', get Revise_val_amt as 'amt_taxable_in_ab'
I am able to retrieve data perfectly fine and the query for that is:
SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
from returns r1, return_line_items rtlnms
where r1.id = rtlnms.rtrn_id
and r1.id > 3600000
AND r1.prog_program_cd = '01'
AND r1.return_status in ('ASSESSED', 'DU')
and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
and rtlnms.sched_nbr = '000'
and RTLNMS.LITM_LINE_ITEM_NBR IN('062', '066')
and rtlnms.active_ind = 'Y' and r1.id in(4117092, 3602448)
The out put is : 4 rows returned which has litm_line_item_nbrs for all the returns in question (4117092, 3602448) and that is - 066,062,062, 066 with their respective amounts.
However against the business analyst's question 5 "C" which is - Retain the return only if (ab_taxable_income > 500,000) and (amt_taxable_in_ab < ab_taxable_income)
I should be getting 2 rows(one with '062' and '066') with return -4117092
So I am applying the logic as mentioned by business analyst's "5C" and run the following query:
SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
from returns r1, return_line_items rtlnms
where r1.id = rtlnms.rtrn_id
and r1.id > 3600000
AND r1.prog_program_cd = '01'
AND r1.return_status in ('ASSESSED', 'DU')
and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
and rtlnms.sched_nbr = '000'
and RTLNMS.LITM_LINE_ITEM_NBR IN('062', '066')
and rtlnms.active_ind = 'Y' and r1.id in(4117092, 3602448)
and r1.id in (select rtrn2.id
from returns rtrn2, return_line_items rtlnms2
where rtrn2.id= rtlnms2.rtrn_id
and rtrn2.id=r1.id
and nvl(decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT),0) > 500000 or rtlnms2.litm_line_item_nbr='066') and (
nvl(decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT),0) < nvl(decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT),0))
order by r1.acct_id , r1.period_end_date desc
I am only getting one row with for RETURN = 4117092 with litm_line_item_nbr (line item number) '062' where as I should also be getting line item number '066' along with '062'
Could any one of you please help me out. I am stuck and have tried everything at the office with no luck.
Many Many Thanks in Advance!
SandeepHi there,
I agree that without test case it's a bit complicated for you folks to solve. However I just could not. Anyways this is the query that I had to use to come to my solution and that is:
SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
from returns r1, return_line_items rtlnms
where
r1.id = rtlnms.rtrn_id and
r1.prog_program_cd = rtlnms.prog_program_cd and
r1.entp_abn = rtlnms.entp_abn and
r1.id > 3600000 AND r1.prog_program_cd = '01' AND r1.return_status in ('ASSESSED', 'DU')
and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
and rtlnms.sched_nbr = '000'
and rtlnms.active_ind = 'Y'
and r1.id in (4117092,3715944,4382179,3691435)
and RTLNMS.LITM_LINE_ITEM_NBR IN('062')
AND nvl(decode(litm_line_item_nbr, '062', REVISE_VAL_AMT),0) > 500000
and NVL(RTLNMS.REVISE_VAL_AMT,0) >( select NVL(RTLNMS2.REVISE_VAL_AMT,0)
FROM RETURN_LINE_ITEMS RTLNMS2
WHERE RTLNMS2.RTRN_ID=RTLNMS.RTRN_ID
AND RTLNMS2.LITM_LINE_ITEM_NBR = '066'
AND SCHED_NBR='000'
UNION
SELECT r1.id, r1.entp_abn, r1.acct_id, r1.prog_program_cd, r1.period_start_date, r1.period_end_Date, r1.amend_ind, r1.return_status, r1.status_date, r1.loctr_nbr,
rtlnms.sched_nbr, rtlnms.litm_line_item_nbr,
decode(rtlnms.litm_line_item_nbr, '062', RTLNMS.REVISE_VAL_AMT)AB_TAXABLE_INCOME,
decode(rtlnms.litm_line_item_nbr, '066', RTLNMS.REVISE_VAL_AMT)AMT_TAXABLE_IN_AB
from returns r1, return_line_items rtlnms
where r1.id = rtlnms.rtrn_id
AND r1.prog_program_cd = rtlnms.prog_program_cd
AND r1.entp_abn = rtlnms.entp_abn
AND r1.id > 3600000 AND r1.prog_program_cd = '01'
AND r1.return_status in ('ASSESSED', 'DU')
and r1.period_end_Date between to_date('01-01-2009','DD-mm-YYYY') and to_date ('31-12-2009', 'DD-mm-YYYY')
and r1.status_date = (select max (status_date) from returns r2 where r2. acct_id= r1.acct_id and r2.period_end_date = r1.period_end_date)
and rtlnms.sched_nbr = '000'
and rtlnms.active_ind = 'Y'
and r1.id in (4117092,3715944,4382179,3691435)
and RTLNMS.LITM_LINE_ITEM_NBR IN('066')
and NVL(RTLNMS.REVISE_VAL_AMT,0) <( select NVL(RTLNMS2.REVISE_VAL_AMT,0)
FROM RETURN_LINE_ITEMS RTLNMS2
WHERE RTLNMS2.RTRN_ID=RTLNMS.RTRN_ID
AND RTLNMS2.LITM_LINE_ITEM_NBR = '062'
and NVL(RTLNMS2.REVISE_VAL_AMT,0)>500000
AND SCHED_NBR='000'
order by ID
This above query works fine. No worries.
One more question and that is:
I need to find out details of another condition. However what happens is using the same query above, when I try to add "and RTLNMS.LITM_LINE_ITEM_NBR IN('066' ,029')" (in the bold part),
it does give me another extra value for row 029 and that's something that I don't want. Based on the above results, I get 4 rows ; 2 each for 062 and 069.
The question asked by business is based on the above results, bring out even values for 029, so which in this case should be 2 rows, making it overall 6, but then I get 7, is there any way to get rid of extra row
or rather : is there any way to retrieve additional row based on results from a query? -
Xml to Oracle (Update more than one row)
Hi,
I want to update more than one row in table from .xml file. My xml file is as follows:
<ROOT>
<PROFILE PROFILEMASTER_PKEY="54" DB_MSTR_PKEY="2" PROFILE_NAME="Bhushans" DELIMETER="~" PRE_PROCESSOR="1" POST_PROCESSOR="10" PRE_PROCESSOR_TYPE="1" POST_PROCESSOR_TYPE="2" GROUPID="2" />
<PROFILEDETAILS PROFILEMASTER_PKEY="54" TARGET_SOURCE_TABLE="FM_FEEDVALIDATION_LU" COLUMN_NAME="FEEDVALIDATION_ID" DATA_TYPE="NUMBER" DATA_SIZE="22" START_POSITION="12" END_POSITION="22" COLUMNORDER="1" PROFILEDETAILS_PKEY="399"/>
<PROFILEDETAILS PROFILEMASTER_PKEY="54" TARGET_SOURCE_TABLE="FM_FEEDVALIDATION_LU" COLUMN_NAME="CHANGE_TYPE" DATA_TYPE="VARCHAR2" DATA_SIZE="1" START_POSITION="12" END_POSITION="144" COLUMNORDER="5" PROFILEDETAILS_PKEY="403"/>
<OPTIONS PROFILEMASTER_PKEY ="54" LDR_SYNTX_DTLS_PKEY ="19" OPTIONVALUE="@" PROFILE_CFILE_PKEY="337" />
<OPTIONS PROFILEMASTER_PKEY ="54" LDR_SYNTX_DTLS_PKEY ="19" OPTIONVALUE="~" PROFILE_CFILE_PKEY="336" />
</ROOT>
To update according to xml file, I have written following procedure. My procedure updates the table if u r updating 1 row. If you try to update more than 1 row, I mean .xml file contains more than 1 row then my procedure doesn't work. Please help to solve this problem.
Procedure:
create or replace procedure fm_prc_xml_dup_up
as
f utl_file.file_type;
s varchar2(2000);
v varchar2(3000);
xml XMLType;
v_pmpk number;
v_sdtl_pk number;
chng_typ VARCHAR2(20);
type r1 is ref cursor;
rcur r1;
v1 varchar2(120);
v2 number;
begin
f := utl_file.fopen('CITI', 'S.XML', 'R');
loop
utl_file.get_line(f, s);
v := v || ' ' || s;
end loop;
exception
when no_data_found then
utl_file.fclose(f);
xml := xmltype(v);
SELECT extract(xml, 'ROOT/CHANGE/@CHANGETYPE').getstringval()
INTO CHNG_TYP
FROM DUAL;
UPDATE FM_PROFILEMAST
set db_mstr_pkey = extract(xml, 'ROOT/PROFILE/@DB_MSTR_PKEY').getnumberval(),
profile_name = extract(xml, 'ROOT/PROFILE/@PROFILE_NAME').getstringval(),
file_type = extract(xml, 'ROOT/PROFILE/@FILE_TYPE').getstringval(),
delimiter = extract(xml, 'ROOT/PROFILE/@DELIMETER').getstringval(),
pre_processor = extract(xml, 'ROOT/PROFILE/@PRE_PROCESSOR').getstringval(),
post_processor = extract(xml, 'ROOT/PROFILE/@POST_PROCESSOR').getstringval(),
pre_processor_type = extract(xml, 'ROOT/PROFILE/@PRE_PROCESSOR_TYPE').getstringval(),
post_processor_type = extract(xml, 'ROOT/PROFILE/@POST_PROCESSOR_TYPE').getstringval(),
groupid = extract(xml, 'ROOT/PROFILE/@GROUPID').getstringval(),
change_type = 'U',
change_by = chng_typ,
change_dt = default,
active_flag = default
WHERE profilemaster_pkey = extract(xml, 'ROOT/PROFILE/@PROFILEMASTER_PKEY').getnumberval();
UPDATE FM_PROFILEDET
SET target_source_table = extract(xml, 'ROOT/PROFILEDETAILS/@TARGET_SOURCE_TABLE').getstringval(),
column_name = extract(xml, 'ROOT/PROFILEDETAILS/@COLUMN_NAME').getstringval(),
data_type = extract(xml, 'ROOT/PROFILEDETAILS/@DATA_TYPE').getstringval(),
data_size = extract(xml, 'ROOT/PROFILEDETAILS/@DATA_SIZE').getnumberval(),
start_position = extract(xml, 'ROOT/PROFILEDETAILS/@START_POSITION').getnumberval(),
end_position = extract(xml, 'ROOT/PROFILEDETAILS/@END_POSITION').getnumberval(),
change_by = chng_typ,
change_dt = default,
columnorder = extract(xml, 'ROOT/PROFILEDETAILS/@COLUMNORDER').getstringval(),
column_format = extract(xml, 'ROOT/PROFILEDETAILS/@COLUMN_FORMAT').getstringval(),
nullable = extract(xml, 'ROOT/PROFILEDETAILS/@NULLABLE').getstringval(),
change_type ='U',
active_flag = default
WHERE profiledetails_pkey = extract(xml, 'ROOT/PROFILEDETAILS/@PROFILEDETAILS_PKEY').getstringval();
UPDATE FM_PROFILE_CFILE
SET profilemaster_pkey = extract(xml, 'ROOT/PROFILE/@PROFILEMASTER_PKEY').getnumberval(),
ldr_syntx_dtls_pkey = extract(xml, 'ROOT/OPTIONS/@LDR_SYNTX_DTLS_PKEY').getstringval(),
val = extract(xml, 'ROOT/OPTIONS/@OPTIONVALUE').getstringval(),
change_by = chng_typ,
change_dt = default,
sub_line_seq = extract(xml, 'ROOT/OPTIONS/@SUB_LINE_SEQ').getstringval(),
change_type = 'U',
active_flag = default
where profile_cfile_pkey = extract(xml, 'ROOT/OPTIONS/@PROFILE_CFILE_PKEY').getnumberval();
END;Hi Bhushan,
one where clause is missing in the main update.
update fm_profiledet
set (....)
=(select ....)
where id in (select your profiledetails_pkey from the xml). <--this where clause were missing.
if xml extracting is too slow(xml very large) then you can create a procedure where exract your data from the xml and then update rows in for loop.
something like this
create procedure up_xmls(p_xml xmltype) is
cursor cur_xml(p_xml xmltype) is
select ......<--here you extract your xml
begin
for r_row in cur_xml(p_xml) loop
update fm_profiledet set target_source_table=r_row.target_source_table
where profiledetails_pkey=r_row.profiledetails_pkey;
end loop;
end;this should work:
SQL> drop table fm_profiledet;
Table dropped.
SQL> create table fm_profiledet(
2 profiledetails_pkey number
3 ,target_source_table varchar2(100)
4 ,column_name varchar2(100)
5 ,data_type varchar2(100)
6 ,data_size number
7 ,start_position number
8 ,change_type varchar2(100)
9 )
10 /
Table created.
SQL>
SQL>
SQL> insert into fm_profiledet
2 values(399,'test','test1','test2',1,2,'A')
3 /
1 row created.
SQL>
SQL>
SQL> insert into fm_profiledet
2 values(403,'test3','test4','test5',3,4,'B')
3 /
1 row created.
SQL> insert into fm_profiledet
2 values(443,'test3','test4','test5',3,7,'B')
3 /
1 row created.
SQL>
SQL>
SQL> select * from fm_profiledet;
PROFILEDETAILS_PKEY TARGET_SOU COLUMN_NAM DATA_TYPE DATA_SIZE START_POSITION CHANGE_TYP
399 test test1 test2 1 2 A
403 test3 test4 test5 3 4 B
443 test3 test4 test5 3 7 B
SQL>
SQL> create or replace directory xmldir as '/home/ants';
Directory created.
SQL>
SQL>
SQL>
SQL> update fm_profiledet fm
2 set (target_source_table,column_name, data_type, data_size, start_position,change_type)
3 =(
4 select target_source_table
5 , column_name
6 , data_type
7 , data_size
8 , start_position
9 , change_type
10 from(
11 select
12 extractValue(value(x),'/PROFILEDETAILS/@PROFILEDETAILS_PKEY') profiledetails_pkey
13 , extractValue(value(x),'/PROFILEDETAILS/@TARGET_SOURCE_TABLE') target_source_table
14 , extractValue(value(x),'/PROFILEDETAILS/@COLUMN_NAME') column_name
15 , extractValue(value(x),'/PROFILEDETAILS/@DATA_TYPE') data_type
16 , extractValue(value(x),'/PROFILEDETAILS/@DATA_SIZE') data_size
17 , extractValue(value(x),'/PROFILEDETAILS/@START_POSITION') start_position
18 ,'U' change_type
19 from
20 table(xmlsequence(extract(xmltype(bfilename('XMLDIR','prof.xml')
21 ,nls_charset_id('AL32UTF8'))
22 , '/ROOT/PROFILEDETAILS'))) x
23 ) s
24 where s.profiledetails_pkey=fm.profiledetails_pkey)
25 where
26 fm.profiledetails_pkey in (select
27 extractValue(value(x),'/PROFILEDETAILS/@PROFILEDETAILS_PKEY') profiledetails_pkey
28 from
29 table(xmlsequence(extract(xmltype(bfilename('XMLDIR','prof.xml')
30 ,nls_charset_id('AL32UTF8'))
31 , '/ROOT/PROFILEDETAILS'))) x
32 );
2 rows updated.
SQL>
SQL>
SQL> select * from fm_profiledet;
PROFILEDETAILS_PKEY TARGET_SOU COLUMN_NAM DATA_TYPE DATA_SIZE START_POSITION CHANGE_TYP
399 FM_FEEDVAL FEEDVALIDA NUMBER 22 12 U
IDATION_LU TION_ID
403 FM_FEEDVAL CHANGE_TYP VARCHAR2 1 12 U
IDATION_LU E
443 test3 test4 test5 3 7 B
SQL> spool off;Ants
Message was edited by:
Ants Hindpere -
Refining SQL Replacement for Oracle's WM_CONCAT Function (Pivoting Rows to column)
Greetings,
I am moving a query from Oracle SQL to Microsoft SQL and am having some difficulty with the transition. Part of my code (listed here) used to pivot the data and display RESULT_VALUE
by the CPI_SEQ . In Oracle this was easy to do by using the function: WM_CONCAT.
I have been ‘Googling’ for the non-Oracle way to achieve this and stumbled on to the “STUFF((SELECT…)”
method. This almost works for me except that it places everything into one cell, whereas
I need to concatenate RESULT_VALUE by CPI_SEQ (the CPI_SEQ is the unique ID). The current code gives me this:
RESULTS
Anxiety, Depression, Diabetes,
COPD, ARDS
Whereas I want my code to present it this way instead
CPI_SEQ
RESULTS
22
Anxiety, Depression
44
Diabetes
46
COPD, ARDS
SELECT (STUFF((SELECT ',' + RESULT_VALUE
FROM
SELECT DISTINCT
C1.CPI_Seq AS CPI_SEQ,C1.Result_Value AS RESULT_VALUE
,count(FCurrent.Field_Name) "Current"
,count(FPast.Field_Name) "Past"
,Count(*) Count
,CASE
When count(FCurrent.Field_Name) > 0 and count(FPast.Field_Name) >0 and count(Fcurrent.Field_Name)+ count(FPast.Field_Name) = Count(C1.PF_RESULT_SEQ) Then CONCAT(C1.Result_Value,'(C/P)')
When count(FCurrent.Field_Name) > 0 and count(FPast.Field_Name) =0 and count(Fcurrent.Field_Name)+ count(FPast.Field_Name) = Count(C1.PF_RESULT_SEQ) Then CONCAT (C1.Result_Value,'(C)')
When count(FCurrent.Field_Name) = 0 and count(FPast.Field_Name) >0 and count(Fcurrent.Field_Name)+ count(FPast.Field_Name) = Count(C1.PF_RESULT_SEQ) Then CONCAT(C1.Result_Value,'(P)')
End Result
From
[AnalyticsDW].[dbo].[rr_stag_PF_Results] A1
join [AnalyticsDW].[dbo].[rr_stag_PF_Results] C1 on A1.PF_Result_Seq = C1.PF_Result_Seq
join [AnalyticsDW].[dbo].[rr_PF_Fields_Dept] FCurrent on A1.PF_Result_Seq = FCurrent.RES_SEQ
AND FCurrent.Field_Name = 'Current'
AND A1.Label_Seq in('187582', '187576','187612','187600','187618','187612')
left join [AnalyticsDW].[dbo].rr_PF_Fields_Dept FPast on A1.PF_Result_Seq = FPast.Res_Seq
AND FPast.Field_Name = 'Past'
AND A1.Label_Seq in('187583', '187577','187613','187601','187619','187613')
WHERE
A1.Result_Value ='Yes'
AND (C1.Result_Value in ('Dyspnea', 'Confusion','Pressure Ulcer', 'Stasis Ulcer','Depression','Anxiety'))
GROUP BY
C1.CPI_Seq,
C1.Result_Value
) L1
FOR XML PATH('')),1,2,'')) RESULTS;With CTE
AS
SELECT
C1.CPI_Seq AS CPI_SEQ,
C1.Result_Value AS RESULT_VALUE
From
[AnalyticsDW].[dbo].[rr_stag_PF_Results] A1
join [AnalyticsDW].[dbo].[rr_stag_PF_Results] C1 on A1.PF_Result_Seq = C1.PF_Result_Seq
join [AnalyticsDW].[dbo].[rr_PF_Fields_Dept] FCurrent on A1.PF_Result_Seq = FCurrent.RES_SEQ
AND FCurrent.Field_Name = 'Current'
AND A1.Label_Seq in('187582', '187576','187612','187600','187618','187612')
left join [AnalyticsDW].[dbo].rr_PF_Fields_Dept FPast on A1.PF_Result_Seq = FPast.Res_Seq
AND FPast.Field_Name = 'Past'
AND A1.Label_Seq in('187583', '187577','187613','187601','187619','187613')
WHERE
A1.Result_Value ='Yes'
AND (C1.Result_Value in ('Dyspnea', 'Confusion','Pressure Ulcer', 'Stasis Ulcer','Depression','Anxiety'))
GROUP BY
C1.CPI_Seq,
C1.Result_Value
SELECT CPI_Seq,
STUFF((SELECT ',' + Result_Value
FROM CTE
WHERE CPI_Seq = c.CPI_Seq
FOR XML PATH(''),TYPE).value('.','varchar(max)'),1,1,'') AS Results
FROM (SELECT DISTINCT CPI_Seq FROM CTE)c
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Hi Experts,
I've a scenario like the below -
Input data:
STORE
QUARTER1
QUARTER2
QUARTER3
QUARTER4
shop1
100
300
500
700
shop2
250
450
650
850
Expected Output:
Quarter
Shop-1
Shop-2
1
100
250
2
300
450
3
500
650
4
700
850
I guess (but not sure) - will UNPIVOT function help in achieving this.
I'm refering this - http://www.oracle-base.com/articles/11g/pivot-and-unpivot-operators-11gr1.php#unpivot but not able to figure out its exact usage.
Could you please help me with this?
Help much appreciated.
-- Ranit
(Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)ranitB wrote:
Thanks a lot Ramin. The output got is as expected.
Could you please explain the working of your query?
Just formatted your query:
select * from (
select store, q, val from t
UNPIVOT(
val for q in(q1, q2, q3, q4)
PIVOT( max(val) for store in('shop1' sh1, 'shop2' sh2)
first we are unpivoting your data :
select store, q, val from t
UNPIVOT(
val for q in(q1, q2, q3, q4)
val is the virtual column name for unpivoted data (you can gave any name)
shop1
Q1
100
shop1
Q2
300
shop1
Q3
500
shop1
Q4
700
shop2
Q1
250
shop2
Q2
450
shop2
Q3
650
shop2
Q4
850
Then we need pivot data for column store and for this in inline view we pivot data :
select * from (
select store, q, val from t
UNPIVOT( val for q in(q1, q2, q3, q4)
PIVOT( max(val) for store in('shop1' sh1, 'shop2' sh2));
Ramin Hashimzade -
Oracle bi delivers - Show relevant rows only (under Recipients) not working
Hi,
My requirement is to send a report to multipel users and each user should get only relevant information mapped to his email id. If I uncheck option "Show relevant rows only", iBot is working and delivering report but our requirement is to send data related to user. For the I checked "Show relevant rows only" but after that iBot is not sending email. I checked the log at "product/OBIEE/OBIHome/server/Log/iBots", but there is no error.
If someone has faced this issue and has solution please let me know.
Thanks a lot.
MukulYou need to set "Data Visilibity" as "Personalized" in the General tab. That means that the iBot will run for each user as each user therefore you need to make sure that each user can read the iBot and the requests that it uses.
Maybe you are looking for
-
Please help me with the jsp page
Hi, I have a parent jsp page. I have a button in that page. If I click the button in the parent page, a child page will be opened which consists of huge data. I have set an option such that if I click the jsp page it asks to open directly or save so
-
HI I updated iphone 5 to ios 8.1 but now there is many problems and i want to turn back to ios 7 . How can i do it?
-
How to make website fit any screen size?
Hello all! I am trying to make my website fits any screen size (desktop, tablet, mobile) In Dreamweaver cs6, I go to file -multiscreen preview – Media Queries- make a CSS file for (site-wide) and click on the Default Presets and
-
I'm trying to update my software . But I forgot my pass code how do I get my password so my software could be updated ?
-
Finance Reports - General Ledger - Revaluation
Dear all What is the use of Revaluation button in General Ledger Report,Give me some example for understand this. By Prasanna.s