CROSS TABLE in APEX

Hello!
I have to develop student attendance application in Oracle APEX.
I have 2 databases. First contain personal info of all the students and class ID (of each of them).
Second contains column for student_ID from first table (which is foreign key), the date and the comment, when combination of student_ID and date is set as unique, so no one can be attended at lecture twice a day.
(Of course both tables have their own ID primary key).
For example:
first table
ID | Name | Address | Class ID
1 | Alex | USA | Group A
2 | John | Canada | Group A
3 | Peter | France | Group B
second table
ID | first_table_ID | date | comment
1 | 1 | 1-aug-09 | attended
2 | 2 | 1-aug-09 | skipped
3 | 3 | 1-aug-09 | lateness
4 | 1 | 3-aug-09 | attended
5 | 2 | 3-aug-09 | attended
6 | 3 | 3-aug-09 | attended
So, what I need, is build report table for each of classes, i.e. lecturers choose the class (from list of values for example), and see table like this (for class A, in this case):
***** | 1-aug-09 | 3-aug-09
Alex | attended | attended
John | skipped | attended
How can I do it?
I experimented with PIVOT command and other stuff, but every time i get different errors in query builder.
Do I need build some data view or some new table from existing ones?
What will be query commands?
THANKS.
Edited by: mindhunter on Aug 9, 2009 4:32 AM
Edited by: mindhunter on Aug 9, 2009 4:34 AM

Hi Mindhunter - and, welcome!
I actually found the new PIVOT functionality annoying - as (A) you have to hardcode the column headings and (B) you have to use an aggregate function to populate the columns.
However, it is possible to handle this by using a "SQL Query (PL/SQL function body returning SQL query)" report. In this way, you can build up a SQL query as a string and then get Apex to run it for you.
To create this type of report, create a normal SQL Query report using SELECT 1 FROM DUAL. When the report has been created, edit it and change the type from "SQL Query" to "SQL Query (PL/SQL function body returning SQL query)".
Then, in the Region Source, you can enter in the PL/SQL that you need to construct the SQL statement. Here is an example using the DEPT and EMP tables:
DECLARE
vSQL VARCHAR2(1000);
vDEPT VARCHAR2(1000);
vSEP VARCHAR2(2);
BEGIN
vDEPT := '';
vSEP := '';
FOR d IN (SELECT DEPTNO, DNAME FROM DEPT ORDER BY DNAME)
LOOP
  vDEPT := vDEPT || vSEP || d.DEPTNO || ' as "' || d.DNAME || '"';
  vSEP := ', ';
END LOOP;
vSQL := 'SELECT * FROM (SELECT ENAME, ENAME ENAME2, DEPTNO FROM EMP) PIVOT (MIN(ENAME2) FOR DEPTNO IN (' || vDEPT || '))';
RETURN vSQL;
END;In this example, I have to loop through all the departments on the DEPT table and make a list of the DEPTNO and DNAME values. The DEPTNO value is the one also used on the EMP table, and the DNAME value is the one that I want as column headings. When the PIVOT is being performed, the DEPTNO values are the ones that are used to determine what appears in each column. Also note that I've had to duplicate the ENAME column (giving the second instance of this a column alias of ENAME2) - I need to do this to get the ENAME value as the first column of the report and the ENAME2 value as an entry in the appropriate column.
Once I had done this, I selected the "Use Generic Column Names (parse query at runtime only)" underneath the Region Source so that I don't have to specify the column names to Apex. It also allows the first ENAME value to appear as the first column in the first. If I ticked the "Use Query-Specific Column Names and Validate Query" option, for some reason, the ENAME column appears last.
OK, that's an example using data that most users here would have. Now for your data. This is actually more complicate as you are using dates as these have to be sorted in order AND converted into strings (for the headings).
Firstly, I would recommend that you create a view over the two tables (if you haven't already done so). Something like:
CREATE OR REPLACE FORCE VIEW STUDENT_ATTENDANCE
  STUDENT_ID,
  STUDENT_NAME,
  CLASS_DATE,
  CLASS_COMMENT
AS
SELECT
  S.ID STUDENT_ID,
  S.NAME STUDENT_NAME,
  C.DATE CLASS_DATE,
  C.COMMENT CLASS_COMMENT
FROM
  STUDENTS S
  INNER JOIN COMMENTS C ON S.ID = C.STUDENT_IDNow we can create a PL/SQL code:
DECLARE
vSQL VARCHAR2(1000);
vDATES VARCHAR2(1000);
vSEP VARCHAR2(2);
BEGIN
vDATES := '';
vSEP := '';
FOR d IN (SELECT DISTINCT TO_CHAR(CLASS_DATE,'YYYYMMDD') DATEVALUE, TO_CHAR(CLASS_DATE,'DD-MON-YY') HEADING, CLASS_DATE FROM STUDENT_ATTENDANCE WHERE CLASS_DATE IS NOT NULL ORDER BY CLASS_DATE)
LOOP
  vDATES := vDATES || vSEP || d.DATEVALUE || ' AS "' || d.HEADING || '"';
  vSEP := ', ';
END LOOP;
vSQL := 'SELECT * FROM (SELECT STUDENT_NAME, CLASS_COMMENT, TO_CHAR(CLASS_DATE,''YYYYMMDD'') DATEVALUE FROM STUDENT_ATTENDANCE WHERE CLASS_DATE IS NOT NULL) PIVOT (MIN(CLASS_COMMENT) FOR DATEVALUE IN (' || vDATES || '))';
RETURN vSQL;
END;You will see that I have two versions of the dates - one in YYYYMMDD format and one in DD-MON-YY. The first is to allow me to create a number that can be used to identify the column (this is easier that trying to compare dates) and the second is for the column heading. As we have to use an aggregate function in the PIVOT, I've just used MIN(CLASS_COMMENT) - assuming that the student can only attend (or not!) one class per date, then this should be ok as this could only return one value.
As I do not have your tables and data, I have created a sample page with a similar statement for the HIREDATE values on the EMP table: [http://apex.oracle.com/pls/otn/f?p=267:138]
The PL/SQL for the top report is my example above. The PL/SQL for the bottom report is:
DECLARE
vSQL VARCHAR2(1000);
vDATES VARCHAR2(1000);
vSEP VARCHAR2(2);
BEGIN
vDATES := '';
vSEP := '';
FOR d IN (SELECT DISTINCT TO_CHAR(HIREDATE,'YYYYMMDD') DATEVALUE, TO_CHAR(HIREDATE,'DD/MM/YYYY') HEADING, HIREDATE FROM EMP WHERE HIREDATE IS NOT NULL ORDER BY HIREDATE)
LOOP
  vDATES := vDATES || vSEP || d.DATEVALUE || ' AS "' || d.HEADING || '"';
  vSEP := ', ';
END LOOP;
vSQL := 'SELECT * FROM (SELECT ENAME, ENAME ENAME2, TO_CHAR(HIREDATE,''YYYYMMDD'') DATEVALUE FROM EMP WHERE HIREDATE IS NOT NULL) PIVOT (MIN(ENAME2) FOR DATEVALUE IN (' || vDATES || '))';
RETURN vSQL;
END;Andy

Similar Messages

  • Print a report with a long cross table

    Hi experts,
    I try to explain..XD
    I have a large cross table, and when I print it, the report is cut on the write hand, because it's to large. Por example, the number 123.234.234 its part in :
    frist page 123.23
    second page 34234
    There is a solution to put a "Page Return" exactly where I want? I want for example a "Page Return" between cell 5 and cell 6.
    thanks a lot!

    I have not seen a page break, but youbcan size the columns so it breaks where you want
    Debi

  • Multiple dynamic column in cross table

    Hi all,
    I have a cross table which stored the sale's quantity and amount.
    The layout in view result likes below:
    saler     quantity1 quantity2 quantity3 quantitysummary amount1 amount2 amount3 amount4 amountsummary
    S3           100           20
    S2           50             30
    S1           300           40
    The layout in view structure likes below:
    saler     quantity quantitysummary amount amountsummary
    S3           100           20
    S2           50             30
    S1           300           40
    the quantity1...n and amount1...n columns is not fixed.the 2 columns is dynamic.
    It's easy that only one column is dynamic,but now there are two columns is dynamic,I don't know how to achieve it.
    Has anyone an idea how to accomplish this?
    Thank you trying to help me!

    You cant do this on BO , you can add static columns but if you put some dynamic column in the left or right i turns dynamic...
    Regards

  • Export and Import of Access DB tables in Apex

    Hi,
    i need help.
    I wanna export an MSACCESS DB Table into an ORACLE DB 10g2.
    but every time i get an error course my ODBC driver which isnt compatible to my tns service name.
    what could i do?
    i only want to export a table..not the whole database.
    if i want to export and import a Table over a XE Version, there are no errors and i could see the table in APEX.
    ...thx for help :)

    Hi Timo,
    If you open your table in Access, and click the "select all" (the empty grey box at the left of the header row), you can copy the entire table and paste it into Apex as though you were copying from Excel - the structure of the copied data is the same. The only thing is that you will be limited to 32,000 characters.
    Obviously, though, getting hold of, and setting up, the correct ODBC drivers is the more proper solution but the above may solve your immediate problem.
    Regards
    Andy

  • Full Export/Import Errors with Queue tables and ApEx

    I'm trying to take a full export of an existing database in order to build an identical copy in another database instance, but the import is failing each time and causing problems with queue tables and Apex tables.
    I have used both the export utility and Data Pump (both with partial and full exports) and the same problems are occurring.
    After import, queue tables in my schema are unstable. They cannot be dropped using the queue admin packages as they throw ORA-24002: QUEUE_TABLE <table> does not exist exceptions. Trying to drop the tables causes the ORA-24005: must use DBMS_AQADM.DROP_QUEUE_TABLE to drop queue tables error
    As a result, the schema cannot be dropped at all unless manual data dictionary clean up steps (as per metalink) are done.
    The Apex import fails when creating foreign keys to WWV_FLOW_FILE_OBJECTS$PART. It creates the table ok, but for some reason the characters after the $ are missing so the referencing tables try to refer to WWV_FLOW_FILE_OBJECTS$ only.
    I am exporting from Enterprise Edition 10.2.0.1 and importing into Standard edition 10.2.0.1, but we are not using any of the features not available in standard, and I doubt this would cause the issues I'm getting.
    Can anyone offer any advice on how I can resolve these problems so a full import will work reliably?

    Thanks for the lead!
    After digging around MetaLink some more, it sounds like I'm running into Bug 5875568 (MetaLink Note:5875568.8) which is in fact related to the multibyte character set. The bug is fixed in the server patch set 10.2.0.4 or release 11.1.0.6.

  • BI Web Serivice on cross table created in WebI Rich Client has no result

    Hi experts,
    I'm actually trying to build some BI Web Services based on cross tables in Web Intelligence. The aim is to use them in Xcelsius for dashboarding. Unfortunately sometimes the web services do not deliver any result. I think the problem only occurs, if the underlying Web Intelligence tables have been created in the Web Intelligence rich client.
    If I rebuild the tables using the InfoView Java Editor Panel of Web Intelligence, everything works properly. Of course this is a very annoying tasks.
    I receive no error message or feedback from the system. Is there a way to enable that? Does anybody know that problem? Any comment and suggestions will be appreciated...
    Best regards,
    Sebastian

    Hello Sebastian,
    It seems you are raising an issue that we need to investigate.
    BI Services were designed with the idea that there should not be any restriction with table publication (I mean, no restrictions in terms of table format or layout) nor with consumption of such BI Services (except from the consumer itself).
    Could you get in touch with the technical support with your table & further details about your issue so we can investigate and deliver a fix, if this makes sense? I'd suggest you also provide these details to me directly in parallel, so I can forward this quicker to the dev team (+ get me the support reference id so I can close the loop), you can contact me offline for this.
    Besides, error messages raised from the WebI Processing Server should be submitted to the consumer via the message output field (along with other metadata provided through web service output).
    Hope that helps,
    David.

  • Hiding rows in  cross table

    Hi,
    How to hide the rows in cross table..
    Re gads,
    G

    Consider this cross table :
    [Lines] could be your X and [Categories] your Y
    In case you need to delete  rows from [City] with [Sales revenues]=0, you just need to filter [Sales revenue]on cross tab from values > 0
    In case X and Y has differents mesures, create a variable:
    Imagine X is [Sales revenue] and Y [Quantity Sold]
    and then create a filter on the crosstab with the variable "Condition" greater than 0

  • Temporary Tables in APEX

    Hello All,
    How can a user refresh a temporary table using APEX. I created 2 temp tables. How can I be sure that the temp tables have been updated when the user runs the report. Is there a button or procedure that I need to create to refresh the temp tables?

    Hello,
    I'd advise using temporary tables in APEX, since you cannot guarantee you will get the same database session within the mod_plsq session pool (or dbms_epg if you're using 11g or XE).
    Instead you will probably want to use a collection, there are details about collections in the documentation available here -
    http://download.oracle.com/docs/cd/B32472_01/doc/appdev.300/b32471/advnc.htm#BABFFJJJ
    Hope this helps,
    John.
    http://jes.blogs.shellprompt.net

  • Regarding the inbuilt log and audit tables for APEX 4.1

    Hi,
    When we acces the Administrator login then we can view various logs like the sql commands that have been recently fired,user list for a workspace,access to each application.Where are these data stored and fetched.Also could we get the inbuilt audit and log table for APEX 4.1 ?
    Thanks and Regards

    >
    Please update your forum profile with a real handle instead of "935203".
    When we acces the Administrator login then we can view various logs like the sql commands that have been recently fired,user list for a workspace,access to each application.Where are these data stored and fetched.Also could we get the inbuilt audit and log table for APEX 4.1 ? This information is available through APEX views. See:
    <li>APEX views: Home > Application Builder > Application > Utilities > Application Express Views
    <li>Monitoring Activity Within a Workspace
    <li>Creating Custom Activity Reports Using APEX_ACTIVITY_LOG
    Note that the underlying logs are purged on a regular basis, so for the long term you need to copy the data to your own tables, as Martin handily suggests here.

  • Calling procedures from table and apex

    Hi
    I have a stored procedures and I want to put my stored procedures in table and I want to call store procedure from table in apex. how can I do this?
    For example
    I have stored procedures like Students(year number,birimno number) 
    GPA(birimno number,studentno number ) Student Procedure and GPA proecdure retrieve name and lastname
    and I want to create a table
    table has
        Id            Package                 Procedurename                                   Arguments                              Header
          1                                                GPA                                 birimno, studentno                      name, lastname
          2                                                Students                          year, birimno                                name,lastnameSo how can I do like this ? I want to call storeprocedures on APEX with selectlist. Selectlist will has a storeprocedures .
    Edited by: esra aktas on 06.May.2011 01:48
    Edited by: esra aktas on 06.May.2011 01:48
    Edited by: esra aktas on 06.May.2011 04:08

    I am beginner pl/sql .
    I had searched execute immediate for helping my problem.
    My purpose is that I want to collect all of procedures in one table. And I must retrived which I select procedure on APEX Selectlist.
    So I started to create a table which name is procedures and I put my procedures names on it.
    Now how can I execute to procedures that name is in table?
    create or replace
    procedure "ISINIF_BASARI"(normalyariyil number,birimno number )
    IS
    ogrenci_no  VARCHAR2(12);
    ders_kodu  VARCHAR2(12);
    ders_adi   VARCHAR2(50);
    harf_kodu  VARCHAR2(4);
    CURSOR c_basari IS
    select  dk.ogrenci_no,da.ders_kodu,da.ders_adi,dk.harf_kodu
    into ogrenci_no,ders_kodu,ders_adi,harf_kodu
    from ders_aktif da,ders_tanim dt, ders_kayit dk
    where da.ders_kodu like  birimno ||'%'
    and (dt.normal_yariyili=normalyariyil
    OR dt.normal_yariyili=normalyariyil+1)
    and (da.acildigi_donem='1' or da.acildigi_donem='2')
    and dt.ders_kodu = da.ders_kodu
    and dk.acilan_ders_no = da.acilan_ders_no
    BEGIN
    FOR I IN c_basari LOOP
    dbms_output.put_line(' OGRENCI NO '||I.OGRENCI_NO||'  DERS KODU  '|| I.DERS_KODU||'  DERS ADI  '||I.DERS_ADI||' HARF KODU '||I.HARF_KODU);
    end loop;
    end;I have procedure like that.
    and I have a procedures table. And I put the procedure's name in table.
    procedure
    id procname
    1 ISINIF_BASARI
    Now I want to call procedure using this table .
    When I call yhe procedures from table I wrote like this. But it has faults.
    create or replace
    PROCEDURE CALLSPFROMTABLE  as
    v_sql_exp VARCHAR2(100);
    BEGIN
    v_sql_exp :='begin'||'select p.procname from procedure p where id=1'||'end;';
    end;Edited by: esra aktas on 07.May.2011 02:19

  • Trying to  get values from a table in apex item.. form.. not sucessfulll

    I have a form and have 3 fields.. .i need the value to be fetched from some other table... at the start...
    Note if the values are present in the fields it donot need to be fetched...
    Now how can i accomplish this..
    I tried using ...onload event.. but data is not visible in the required field..
    I tried dynaic item.. for even on page load ..it does fire..But i will like it to fire only one time..
    Does any one have any idea how can this be accomplished
    In oracle forms we will have done ..soemting like when new form instance trigger - select name into :mname from table where empno = :xyz;
    How do we accomplish this in apex..any info will be usefull..
    Thanks
    Paul j

    Yes i did try the same ..
    BEGIN
    select PROD_tYPE into :P185_OFF_CITY from
    magcrm_setup where atype = 'CITY' ;
    :p185_OFF_CITY := 'XXX';
    insert into mtest values ('inside foolter');
    END;
    When i checked the mtest table it shos me the row inserted...
    inside foolter .. Now this means everything did get execute properly
    But still the vallue of off_city is null or emtpy...
    i check the filed and still its empty..
    while mtest had those records..seems like some process is cleaining the values...but cant see such process...
    a bit confused..here..I tried on Load after footer...
    tried chaning the squence number of process ..but still it doesnt help
    some how the session variables gets changed...and it is changed to empty
    Edited by: pauljohny on Jan 3, 2012 2:01 AM
    Edited by: pauljohny on Jan 3, 2012 2:03 AM

  • How to see all the list of tables in APEX

    Hi
    COuld anyone of you help me find out how to see all the tables present in APEX ?
    I can see all the list of tables when i give the command : select * from tab
    But apart from finding like this , is there any way to find out all the list of tables ?
    Regards,
    Tasha

    Hi Tasha,
    For Apex 3.2 ;
    select * from dba_tables where owner in
    (select workspace from APEX_030200.APEX_WORKSPACES)
    tab is a synonym for user_tables
    http://www.oreillynet.com/pub/a/network/2002/10/28/data_dictionary.html
    hope this helps you
    regards
    mozkavra

  • Upload multiple excel files into tables using APEX

    Hi folks,
    I'm wondering if anyone has ever uploaded multiple .csv files simultaniously and store the data into the database using APEX XE before.
    I can browse for a single file, and execute that okay and a good example of doing that can be found at http://advait.wordpress.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
    This works fine when the user browses to a specific file on their network and then uploads the data from that one file.
    However I need the ability to 'grab' every file in a specific directory one after the other to process rather than having to specify which one to load everytime, and wondered if anyone has come across this before.
    Many thanks
    Graham.

    Just for completeness ...
    Got this to work, but it's a pl/sql issue as opposed to an APEX issue.
    Anyway, if anyone needs to have the ability to read multiple files then a quick easy way to do it (as lomg as they know the file names that will be read), is to create a directory on the database which points to the actual harddrive on your PC, then create a table (called an external table) and read from that external table as if it was an actual database table ...
    1 - Log on as sys and grant CREATE ANY DIRECTORY to whatever user you are logging in as (assuming you are not using sys to create apps)
    2 - Create a directory e.g....CREATE OR REPLACE DIRECTORY GB_TEST AS 'c:\gbtest';
    3 - Create an external table as ...
    CREATE TABLE gb_test
    (file_name varchar2(10),
    rec_date date
    rec_name VARCHAR2(20),
    rec_age number,
    ORGANIZATION EXTERNAL
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY GB_TEST
    ACCESS PARAMETERS
    RECORDS DELIMITED BY NEWLINE
    FIELDS TERMINATED BY ','
    LOCATION ('data1.csv','data2.csv','data3.csv','data4.csv')
    PARALLEL 5
    REJECT LIMIT 20000;
    That's it then ...
    select * from gb_test
    where file_name = 'xxx'
    will return all the data where the file_name = 'xxx'
    very easy to use.

  • 10g Nested Tables and APEX

    Trying to use the following within Apex:
    CREATE TYPE location_typ AS OBJECT (
    location_id NUMBER(4),
    street_address VARCHAR2(40),
    postal_code VARCHAR2(12),
    city VARCHAR2(30),
    state_province VARCHAR2(25));
    CREATE TYPE nt_location_typ AS TABLE OF location_typ;
    CREATE TYPE country_typ AS OBJECT (
    country_id CHAR(2),
    country_name VARCHAR2(40),
    locations nt_location_typ);
    CREATE TYPE nt_country_typ AS TABLE OF country_typ;
    CREATE TABLE region_tab (
    region_id NUMBER,
    region_name VARCHAR2(25),
    countries nt_country_typ)
    NESTED TABLE countries STORE AS nt_countries_tab (
    (PRIMARY KEY (NESTED_TABLE_ID, country_id))
    ORGANIZATION INDEX COMPRESS
    NESTED TABLE locations STORE AS nt_locations_tab);
    Can get Apex to function in the Tabular Report mode by modifying the query to use the correct syntax:
    select "REGION_ID",
    "REGION_NAME",
    c.COUNTRY_ID,
    c.COUNTRY_NAME,
    l.LOCATION_ID,
    l.STREET_ADDRESS, l.POSTAL_CODE,
    l.CITY,
    l.STATE_PROVINCE
    from "#OWNER#"."REGION_TAB", TABLE(COUNTRIES) C, TABLE(LOCATIONS) L
    Built a 'Maintenance' form. Put the Region base column on it. Then built a tabular form (with an updateable query) on the same page to access the first level Nest ( countries). Haven't figured out how to actually edit the values yet, but feel comfortable I will.
    But - trying to provide editing to the 2nd level nested table elements creates a problem. First, only 1 updateable query can be on a page. Hmmm - so to get around this I guess I have to build a new page that the calling updateable query will access when selecting one of the tabular form elements. Not elegant by any means. Was hoping to provide a blank form on the right side that would be populated by the Location Nested Table values when a select was made on the first level nest. Oh well.
    Just curious how anyone has handled this? I could pass stack between pages for sure, but was hoping page regions would be sufficient to handle this.
    Any white papers on this? Anything in the DEMO area to use as a template? The default Demo doesn't provide this based on querying user objects.
    Thanks,
    Dwight Taylor

    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> CREATE OR REPLACE TYPE table_type AS TABLE OF VARCHAR2 (8);
      2  /
    Type created.
    SQL> CREATE TABLE r(
      2    a INTEGER,
      3    b table_type)
      4    NESTED TABLE b STORE as b_1;
    Table created.
    SQL> CREATE TABLE s(
      2    a INTEGER,
      3    b table_type)
      4    NESTED TABLE b STORE as b_2;
    Table created.
    SQL> INSERT INTO r VALUES (1, table_type ('a', 'b'));
    1 row created.
    SQL> INSERT INTO s VALUES (1, table_type ('b', 'c'));
    1 row created.
    SQL> COLUMN c FORMAT A10;
    SQL> SELECT r.a, r.b MULTISET UNION DISTINCT s.b c
      2  FROM   r, s
      3  WHERE  r.a = s.a;
             A C
             1 TABLE_TYPE('a', 'b', 'c')
    SQL>

  • How to get data of Oracle Applications tables in APEX

    Hi all,
    My requirement is to Develop Oracle apps Order Management Reports in APEX.
    But when i am trying to query the table or view i am unable to get data in APEX.
    Ex: If i query the Sales order form view OE_ORDER_HEADERS_V in toad i am able to get data as i am running this
    begin
    dbms_application_info.set_client_info('204');
    end;
    i.e for particular org_id. i am able to get data.
    But in apex how do i get data. Are there any settings to be done. Please let me know if anyone have worked on the same.
    Regards.
    Chandu

    My Query is like this :
    SELECT DECODE (ship_loc.city, NULL, NULL, ship_loc.city || ', ')
    || DECODE (ship_loc.state, NULL, NULL, ship_loc.state ) Destination,
         party.party_name "Sold To",
         l.ordered_item Product,
         l.ACTUAL_SHIPMENT_DATE "Ship Date",
         Nvl(l.ordered_quantity,0) "Act. Tons",
         '$'||Nvl(l.ordered_quantity,0)* l.unit_selling_price||'.00' "Price"
    FROM mtl_parameters ship_from_org,
         oe_order_lines_all l,
    hz_cust_site_uses_all ship_su,
    hz_party_sites ship_ps,
    hz_locations ship_loc,
    hz_cust_acct_sites_all ship_cas,
    hz_cust_site_uses_all bill_su,
    hz_party_sites bill_ps,
    hz_locations bill_loc,
    hz_cust_acct_sites_all bill_cas,
    hz_parties party,
    hz_cust_accounts cust_acct,
    ra_terms_tl term,
    oe_order_headers h,
    hz_cust_account_roles sold_roles,
    hz_parties sold_party,
    hz_org_contacts sold_cont,
    hz_party_relationships sold_rel,
    ar_lookups sold_arl,
    hz_cust_account_roles ship_roles,
    hz_parties ship_party,
    hz_org_contacts ship_cont,
    hz_party_relationships ship_rel,
    ar_lookups ship_arl,
    hz_cust_account_roles invoice_roles,
    hz_parties invoice_party,
    hz_org_contacts invoice_cont,
    hz_party_relationships invoice_rel,
    ar_lookups invoice_arl,
    fnd_currencies fndcur,
    oe_transaction_types_tl ot,
    qp_list_headers_tl pl,
    ra_rules invrule,
    ra_rules accrule
    WHERE h.order_type_id = ot.transaction_type_id
    AND ot.LANGUAGE = USERENV ('LANG')
    AND h.price_list_id = pl.list_header_id(+)
    AND pl.LANGUAGE(+) = USERENV ('LANG')
    AND h.invoicing_rule_id = invrule.rule_id(+)
    AND h.accounting_rule_id = accrule.rule_id(+)
    AND h.payment_term_id = term.term_id(+)
    AND term.LANGUAGE(+) = USERENV ('LANG')
    AND h.transactional_curr_code = fndcur.currency_code
    AND h.sold_to_org_id = cust_acct.cust_account_id(+)
    AND cust_acct.party_id = party.party_id(+)
    AND h.ship_from_org_id = ship_from_org.organization_id(+)
    AND h.ship_to_org_id = ship_su.site_use_id(+)
    AND ship_su.cust_acct_site_id = ship_cas.cust_acct_site_id(+)
    AND ship_cas.party_site_id = ship_ps.party_site_id(+)
    AND ship_loc.location_id(+) = ship_ps.location_id
    AND h.invoice_to_org_id = bill_su.site_use_id(+)
    AND bill_su.cust_acct_site_id = bill_cas.cust_acct_site_id(+)
    AND bill_cas.party_site_id = bill_ps.party_site_id(+)
    AND bill_loc.location_id(+) = bill_ps.location_id
    AND h.sold_to_contact_id = sold_roles.cust_account_role_id(+)
    AND sold_roles.party_id = sold_rel.party_id(+)
    AND sold_roles.role_type(+) = 'CONTACT'
    AND sold_cont.party_relationship_id(+) = sold_rel.party_relationship_id
    AND sold_rel.subject_id = sold_party.party_id(+)
    AND sold_arl.lookup_type(+) = 'CONTACT_TITLE'
    AND sold_arl.lookup_code(+) = sold_cont.title
    AND h.ship_to_contact_id = ship_roles.cust_account_role_id(+)
    AND ship_roles.party_id = ship_rel.party_id(+)
    AND ship_roles.role_type(+) = 'CONTACT'
    AND ship_cont.party_relationship_id(+) = ship_rel.party_relationship_id
    AND ship_rel.subject_id = ship_party.party_id(+)
    AND ship_arl.lookup_type(+) = 'CONTACT_TITLE'
    AND ship_arl.lookup_code(+) = ship_cont.title
    AND h.invoice_to_contact_id = invoice_roles.cust_account_role_id(+)
    AND invoice_roles.party_id = invoice_rel.party_id(+)
    AND invoice_roles.role_type(+) = 'CONTACT'
    AND invoice_cont.party_relationship_id(+) = invoice_rel.party_relationship_id
    AND invoice_rel.subject_id = invoice_party.party_id(+)
    AND invoice_arl.lookup_type(+) = 'CONTACT_TITLE'
    AND invoice_arl.lookup_code(+) = invoice_cont.title
    AND h.header_id = l.header_id

Maybe you are looking for