Tables and SQL query

Hello

I post this question for clarification. I have a report that is based on a SQL query area.

Place automatically APEX sql in the tables, all THE results of a query if it is in a region of report? Or y at - it a step that the developer must do to retrieve the columns of the sql query in a table.

I'm working with checkboxes, and I read up on top of the api APEX_APPLICATION. This part is still unclear.

Your comments would be appreciated!

Keisha

Hi Keisha,

You should have a read of: [http://download-uk.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/check_box.htm#CHDHFACG] that explains the use of checkboxes on the reports.

I guess the 'picture' you refer to are APEX_APPLICATION. G_F01 up APEX_APPLICATION. Paintings of G_F50? If so, they are built when you submit the page and are based on elements with attributes of 'name' of 'f01' up to 'f50' in the HTML tags. You don't need to do anything beforehand to create these, which is done automatically for you by the Apex. But, notes, however, that only the checked boxes are presented with a page - so if your username is checked, say, 3 of the 10 boxes, table will contain only 3 points not 10 (with each element of the table that contains the attribute 'value' of a checkbox).

Andy

Tags: Database

Similar Questions

  • merge 2 tables (from sql query)

    Ahoj!

    I have 4-sql queries, each with the same structure, but it is not possible to do in a single query. for example:
    Query 1: extension, County a-> table 1 report
    Query 2: extension, County b-> report table 2
    Query 3: extension, County-> report table 3 c
    Question 4: extension, County d-> report table 4

    the result in the apex is now, I have 4 different tables. is it possible to merge these 4 tables table 1 apex?
    extension, number a, b number, County c County d-> report table

    I use the standard sql-report, non-interactive.

    THX,
    Christian

    You can try something like this (not a not test it):

    SELECT A.EXTENSION, $A.COUNT, C.COUNT, B.COUNT, D.COUNT
    Of
    (SELECT the extension, County)
    A
    ) a
    ,
    (SELECT the extension, County)
    B
    ) b
    ,
    (SELECT the extension, County)
    C
    ) c
    ,
    (SELECT the extension, County)
    D
    ) d
    WHERE a.extension = b.extension
    AND b.extension = c.extension
    AND c.extension = d.extension

    Concerning
    Roel

  • Difference between external tables and sql * loader

    Hello

    Could you please tell me the difference between
    tables external and sql * loader

    I have serached on the net but did ' get correct idea

    Please help me

    1 SQL LOADER can be run on the network (from any client computer), external tables can't

    2. return to the Oracle 9, external Tables could not load CLOB/BLOB (Oracle10 changed it)

    3 oracle 11 external tables have preprocessor, which is pretty dam characteristic cool - running essentially any OS command e.g. decompress before external table run. What's even better is the fact that the result of the operating system command is the source of the outer table, which means that there are no required temporary file (unzip the tracks and the output is the source of the external table). There are several ways to great use this - look at my blog for samples rare http://jiri.wordpress.com/2010/01/19/no-more-unix-scripts-in-11-2/

    4. as long as the 009 stressed, filed external load anything, they show just. Think of it more as load on request - it's great if you have old files archived and one or two users what to see content once a while

    5. external tables require no user access to the operating system, it is oracle environment pure - this may seem minor but for me it's huge. The fact that the ETL needs no special unix, no control file command and uses the simple SQL and DDL is nice and important

    6. external tables can load more text files, Oracle export dump files can be loaded, perhaps in the future more formats will be supported (hopefully all right excel format?)

    now the same thing to kill the myth - the TWO are EXACTLY the same when it comes to speed, I would actually drive of the external tables before will be faster because sql loader is old technology oracle doesn't really develops more

  • Lock on a table and SQL * Net more data from client

    Hello

    I have a problem loading data through Php in Oracle: web page of Php open an xml file, create a .csv, then begins to Oracle using an external table to process the data.

    The problem is that, the second time that PHP is trying to run the following query:

    INSERT INTO table1 T (Field1, Field2, field3, field4, sphere5, case field6) VALUES ('Aaa1E63819707', SYSDATE, 'KO', 'error', 'L', 'file_name.xml') POLL INTO Field1: id

    on the Oracle sessions, I have an exclusive lock on table1 and wait for SQL * Net more data from client.

    Where is the problem?

    Thank you

    Igor

    Finally I found the problem: a DBA changed the cursor sharing EXACT force! I restored the CORRECT setting and now everything is fine.

    Thank you

    Bye,.

    Igor

  • SQL Analysis: Extract column expression and SQL query tags

    Hi all

    I have a requirement and posted earlier reg. this.
    An SQL statement must be parsed and column names must be extracted separately.
    I can't use dbms_sql. I need to extract the names of columns through manipulating strings in PL/SQL only.
    I don't have to validate the SQL code.

    for example.
    SELECT EMPNO, Upper (ENAME), DEPTNO Emp_Name, DECODE (Deptno, 10, 'ACCOUNTING', 20, 'HR', 'OTHER') Dept_Name OF double

    Output should be,.

    Column names
    --------------------
    (1) EMPNO
    (2) Emp_Name Upper (ENAME)
    (3) DEPTNO
    (4) Dept_Name DECODE(Deptno,10,'ACCOUNTING', 20,'HR','OTHERS')

    How can I retrieve the names of columns using PL/SQL for the above format?
    Pls help.

    Kind regards
    Sam

    If the requirement is to have them come forward...

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_sql VARCHAR2(4000) := q'[SELECT EMPNO, Upper(ENAME) Emp_Name, DEPTNO, DECODE(Deptno,10,'ACCOUNTING', 20,'HR','OTHERS') Dept_Name FROM Dual]';
      3    v_cols VARCHAR2(4000) := regexp_replace(v_sql, 'SELECT (.*) FROM .*', '\1');
      4    PROCEDURE parse_col(p_cols IN VARCHAR2, lvl NUMBER) IS
      5      v_str VARCHAR2(4000);
      6      v_br  NUMBER := 0;
      7      v_pos NUMBER := 1;
      8    begin
      9      LOOP
     10        EXIT WHEN v_pos > length(p_cols);
     11        CASE SUBSTR(p_cols,v_pos,1)
     12          WHEN '(' THEN
     13            v_br := v_br + 1;
     14          WHEN ')' THEN
     15            v_br := v_br - 1;
     16          WHEN ',' THEN
     17            IF v_br = 0 THEN
     18              DBMS_OUTPUT.PUT_LINE(to_char(lvl,'fm99')||': '||trim(v_str));
     19              parse_col(SUBSTR(p_cols,v_pos+1),lvl+1);
     20              v_str := NULL;
     21              EXIT;
     22            END IF;
     23          ELSE NULL;
     24        END CASE;
     25        v_str := v_str || SUBSTR(p_cols,v_pos,1);
     26        v_pos := v_pos + 1;
     27      END LOOP;
     28      IF v_str IS NOT NULL THEN
     29        DBMS_OUTPUT.PUT_LINE(to_char(lvl,'fm99')||': '||trim(v_str));
     30      END IF;
     31    end;
     32  begin
     33    parse_col(v_cols,1);
     34* end;
    SQL> /
    1: EMPNO
    2: Upper(ENAME) Emp_Name
    3: DEPTNO
    4: DECODE(Deptno,10,'ACCOUNTING', 20,'HR','OTHERS') Dept_Name
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • Newb question: SQL query on an imported table

    Hi all. I'm a newb, that this issue will probably tell you!
    But I am very interested to familiarize themselves with the Oracle environment.

    I installed 10g Express.
    I was able to set up a new user (schema) profile?

    I created a new table, by importing an Excel file, saved as a CSV file. It has a PK.

    When I log in as an administrator, I can see the table 'discovers' the content.
    However, I can't run a SQL command with the new table.
    It is said Table or view does not exist.

    The table is called "Customers" and contains a column called "City" and I type City Select From Customers.

    Like the Adminisistrator, I have "given" all the rights for the new table to my profile newly created (schema).
    When I connect as long as this new person, I can't see the new table imported into the list of tables, yet alone to run an application or a SQL to it. What did I miss?

    Any tips will be appreciated. Glyn gray...

    Published by: user12501005 on February 7, 2010 11:26

    Hello

    You wrote:
    The original table is still visible to the diagram of the system, but he reports yet again as saying that the table does not exist when I try SQL.
    So is there a reason why a table imported is visible to the user DBA, but SQL does not exist?
    The other imported tables, those the DBA can run SQL still aren't visible to other users (schemas).
    The DBA has "tuned" EVERYTHING to the default HR schema.
    When I connect like HR, I'm unable to find the given table and SQL reports that the table does not exist.

    If I understand that you have created a Table in the schema of the SYSTEM, and you cannot question him by SQL.

    For example, if you then create a table A in the diagram of SYSTEM, you can view the table A if you connect to the database
    SYSTEM or any intended user he has the privilege to CHOOSE ANY TABLE.

    If you are connected to a user (for example, HR), which does not have this privilege, you can not query the Table.

    If you have a privilege to HR as follows:

    connect system/
    grant select on A to HR;
    

    Then you can query the Table has to HR:

    connect HR/
    select * from system.A;
    

    Hope this helps.
    Best regards
    Jean Valentine

  • DA on updatable report items Sql query using the class

    Request Express 4.2.5.00.08

    10-11 g Oracle

    I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.


    However, I've now added some complex things.

    for example. My region is based on the query of SQL Type (editable report).

    SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;

    I can also add a new line of course.

    My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.

    for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.

    And now, I created the DA.

    1. event: change

    Selection type: jQuery Selector

    jQuery Selector: .st_tm

    Condition: No.

    1. action: set value

    Set type: Expression Javascript

    The JavaScript Expression: $(this.triggeringElement) .val ();

    The element affected: P10_X1 (it is a hidden item)

    2. action: Plsql Code

    Code: start to null; end;

    Page items to submit: P10_X1

    3. action: Plsql Code

    Code: start

    If: P10_X1 between '03' AND '11' then

    : P10_X1: = 'EARLIES ';

    elsif: P10_X1 then '12' and '18'

    : P10_X1: = 'LATES ';

    on the other

    : P10_X1: = 'NIGHTS';

    end if;

    end;

    Page items to submit: P10_X1

    NOW another DA

    Event: change

    Article (s) P10_X1

    Condition (in list)

    value (HASTY, LATES, NIGHTS)

    Action:

    Set type: Expression Javascript

    The JavaScript Expression: $(this.triggeringElement) .val ();

    Affected item:

    Selection type: jQuery Selector

    jQuery Selector:. Shift_time

    Well, I look forward all the above work well, but I'm having a problem.

    If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.

    I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?

    Help, please!

    Kind regards

    RI

    I found the solution me thank you.

    I removed all the DA mentioned above and created a new.

    1. event: change

    Selection type: jQuery Selector

    jQuery Selector: .st_tm

    Condition: No.

    Scope of the event: dynamic and light on page load.

    Action (Javascript code)

    ROW_ID = $(this.triggeringElement).attr('id').substr (4);

    If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">

    .Val ('EARLIES') $(«#f11_» + row_id);

    }

    ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">

    .Val ('LATES') $(«#f11_» + row_id);

    }

    ElseIf (. val() > $19 (this.triggeringElement)) {}

    .Val ('NIGHTS') $(«#f11_» + row_id);

    }

    also created another DA because I have a disabled report items.

    Event: before the page is sent.

    $('_:_disabled').removeAttr ("disabled");

    and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).

    Kind regards.

  • SQL Query - store the result for optimization?

    Good day experts,

    I'm looking for advice on a report. I did a lot of analytical functions to get the basic data that I have to do my report and its takes about 50 min for SQL finish. Now, with these data, I need to create 3 different reports and I can't use the SQL even since there are a lot of aggregation (example would be product group in one case and by customer in 2nd). For each of these different group garages I need another report.

    So how to create 3 reports of 1 SQL query without running the query 3 times?

    First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.

    Best regards

    Igor

    So how to create 3 reports of 1 SQL query without running the query 3 times?

    You already know the obvious answer - store data 'somewhere '.

    If any 'somewhere' depends on your needs and you have not provided ALL the.

    MV - if the query is always the same, you might use a MV and make a complete refresh when you want that new data. The data are permanent and can be queried by other sessions, but the query that accesses the data is frozen in the definition of MV.

    GTT (global temporary table) - If a NEW charge of data AND three reports will be ALWAYS executed by a single session and then data are no longer necessary so a TWG may work. The application that loads the TWG can be different for each race, but the data won't be available for a single session and ONLY for the duration of this session. So if something goes wrong and the session ends the data are missing.

    First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.

    Which is commonly called a "table of REPORT-READY." Those that are useful when data must be permanent and available for multiple sessions/users. Generally, there is a batch (for example the package procedure) that periodically refreshes / updates the data during a window of failure. Or the table can have a column (for example AS_OF) that allows it to contain multiple data sets and the update process let alone the existing data and creates a new set of data.

    If your database is about 300 lines you can consider a table report and even use it to contain multiple data sets. Then, the reports can be written to query the data by using a value AS_OF that wraps and returns the appropriate data. You don't need a window of failure since the oldest data are still available (but can be removed when you no longer need.

    If you need a set of data, you can use a partitioned table work (with only one partition) to collect the new set of data, then a SWAP PARTITION to 'swap' in the new data. Only, this "Exchange" takes a fraction of a second and avoids a window of failure. Once the swap done no matter what user query will get new data.

  • How to add a column to a specific location within a table using Sql developer.

    Hello

    I need to add a column to a table in a specific location, how to proceed?
    I tried following
    clicked on a right-> Edit table then I got a screen with all the columns in the table
    where move column up and down column options are disabled.
    can someone help me with this.


    Thank you
    Harry

    Its not supported. In the database to insert a column in a specific location, you must re-create the table and SQL Developer team have, decided quite rightly, it is a step away.

    Remember in connection with the database column order is not serious.

  • (Updated report) SQL query - may not know how to make one

    Hi people,

    Can someone tell me how to make a report where the data can be updated? Not an interactive report, SQL report that selects a single row. The only options in the menu dropdown I see are "SQL query" and 'SQL Query (body of function from PL/SQL returning SQL query)', but I have a report elsewhere that says: this type are "SQL Query (updated report)", but I do not remember how :(

    Thank you very much

    -Adam

    Hi Adam,.

    An updated report is a 'tabular form' - see: http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10497/frm_tabular.htm#CHDFBHDB

    Andy

  • To loop through the table and use the values returned in another query

    Hello

    I tried to do something very simple, but still can not.

    I am trying to iterate on a table and use each line of a column in a where clause to display a query clause.

    For example:

    I want to retrieve all users of dba_users pass it to a clause where clause in a query to show for example account_status and profile of each user. But I want to do it in a way if I can turn the result in an html table.

    I tried too much really, so I'll post something that does not work, but which I think will show the problem I have,

    BEGIN
     FOR i IN (SELECT username from dba_users order by 1)
     LOOP
     EXECUTE IMMEDIATE 'select account_status from dba_users where username like ''||i.username||''';
     END LOOP;
     END;
     /
    

    Example of what I want to achieve:

    Suppose that there are two users, SYS, and SCOTT:

    USERNAME                       PROFILE                        ACCOUNT_STATUS
    ------------------------------ ------------------------------ --------------------------------
    SYS                            DEFAULT                        OPEN
    
    
    USERNAME                       PROFILE                        ACCOUNT_STATUS
    ------------------------------ ------------------------------ --------------------------------
    SCOTT                            DEFAULT                        OPEN
    

    Thanks in advance for your time,

    OD

    Hi Bill,

    Bill Citad kirjoitti:

    What a join or a sub query going to help me? honestly

    -- join
    select
      s.sql_id,
      h.loads_total
    from dba_hist_sqlstat h join v$sql s on (
      h.sql_id = s.sql_id
    )
    where rownum < 3
    ;
    
    -- subquery
    select
      sql_id,
      loads_total
    from dba_hist_sqlstat
    where sql_id in (
      select sql_id from v$sql where rownum < 3
    )
    ;
    
    -- correlated subquery
    select
      sql_id,
      loads_total
    from dba_hist_sqlstat
    where exists (
      select null from v$sql where sql_id = dba_hist_sqlstat.sql_id
    )
    and rownum < 3
    ;
    
    -- lateral inline view (12c)
    select
      s.sql_id,
      h.loads_total
    from dba_hist_sqlstat, lateral(
      select sql_id from v$sql where sql_id = h.sql_id
    ) s
    where rownum < 3
    ;
    
  • Single SQL query for the analysis of the date of customs declaration under the table of Stock codes

    Dear all,


    Please tell us a single SQL query for the below,

    We have a Table of Stock as shown below,

    STOCK_TABLE

     

    ITEM_CODE

    (item code)

    BAT_NO

    (lot no.)

    TXN_CODE

    (transaction code)

    DOC_NO

    (number)

    BOE_DT

    (date of the customs declaration)

    I1

    B1

    I1

    I2

    I3

    B70

    I4

    B80

    I5

    B90

    T102

    1234

    JULY 2, 2015

    I6

    B100

    We have to find the date of customs declaration (i.e. the date when the items have come under this particular table) for items that are not attached to any document (that is, who have TXN_CODE, DOC_NO and BOE_DT fields with a NULL value).

    For each item in the table of actions, which is not attached to any document, the customs declaration date is calculated as follows.

    1. If (code section, lot number) combination is present under HISTORY_TABLE, the date of customs declaration will receive the UPDT_DT, the transaction code (TXN_CODE) is an IN or transactions (which can be analyzed from the TRANSACTIONS table).

    2. If (code section, lot number) combination is NOT currently at the HISTORY_TABLE (or) the transaction code respective to item - batch number combination code is an operation then customs declaration date will be the date of the document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD that contains the element of that particular lot.

  • If the case 1 and case 2 fails, our customs declaration date will be the last date of document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD containing that particular item and the BAT_NO in expected results will be that corresponding to this document, as appropriate, to another NULL.

  • If the case 1 or case 2 is successful, the value of the last field (in the output expected, shown further below) BATCH_YN will be 'Y', because it fits the lot. Otherwise it will be 'n'.
  • HISTORY_TABLE

     

    ITEM_CODE

    BAT_NO

    TXN_CODE

    DOC_NO

    UPDT_DT

    I1

    B1

    T1

    1234

    JANUARY 3, 2015

    I1

    B20

    T20

    4567

    MARCH 3, 2015

    I1

    B30

    T30

    7890

    FEBRUARY 5, 2015

    I2

    B40

    T20

    1234

    JANUARY 1, 2015

    TRANSACTION

     

    TXN_CODE

    TXN_TYPE

    T1

    IN

    T20

    OFF

    T30

    ALL THE

    T50

    IN

    T80

    IN

    T90

    IN

    T60

    ALL THE

    T70

    ALL THE

    T40

    ALL THE

    IN_TABLE_HEAD_1

     

    H1_SYS_ID

    (primary key)

    TXN_CODE

    DOC_NO

    DOC_DATE

    H1ID1

    T1

    1234

    JANUARY 1, 2015

    H1ID2

    T70

    1234

    FEBRUARY 1, 2015

    IN_TABLE_ITEM_1

     

    I1_SYS_ID

    H1_SYS_ID

    (foreign key referencing H1_SYS_ID in IN_TABLE_HEAD_1)

    ITEM_CODE

    I1ID1

    H1ID1

    I1

    I1ID2

    H1ID1

    I100

    I1ID3

    H1ID2

    I3

    IN_TABLE_BATCH_1

     

    B1_SYS_ID

    TXN_CODE                DOC_NO

    (now in IN_TABLE_HEAD_1)

    BAT_NO

    B1ID1

    T1

    1234

    B1 / can be empty

    B1ID2

    T70

    1234

    B70

    IN_TABLE_HEAD_2

     

    H2_SYS_ID

    (primary key)

    TXN_CODE

    DOC_NO

    DOC_DATE

    H2ID1

    T30

    4567

    FEBRUARY 3, 2015

    H2ID2

    T60

    1234

    JANUARY 3, 2015

    IN_TABLE_ITEM_2

     

    I2_SYS_ID

    H2_SYS_ID

    (foreign key referencing H2_SYS_ID in IN_TABLE_HEAD_2)

    ITEM_CODE

    I2ID1

    H2ID1

    I1

    I2ID2

    H2ID1

    I200

    I2ID3

    H2ID2

    I2

    IN_TABLE_BATCH_2

     

    B2_SYS_ID

    I2_SYS_ID

    (foreign key referencing I2_SYS_ID in IN_TABLE_ITEM_2)

    BAT_NO

    B2ID1

    I2ID1

    B30 / null

    B2ID2

    I2ID2

    B90

    B2ID2

    I2ID3

    B60

    IN_TABLE_HEAD_3

     

    H3_SYS_ID

    (primary key)

    TXN_CODE

    DOC_NO

    DOC_DATE

    H3ID1

    T50

    1234

    JANUARY 2, 2015

    H3ID2

    T80

    1234

    JANUARY 3, 2015

    H3ID3

    T90

    1234

    JANUARY 4, 2015

    H3ID4

    T40

    1234

    AUGUST 5, 2015

    IN_TABLE_ITEM_3

     

    I3_SYS_ID

    H3_SYS_ID

    (foreign key referencing H3_SYS_ID in IN_TABLE_HEAD_3)

    ITEM_CODE

    BAT_NO

    I3ID1

    H31D1

    I2

    B50

    I3ID2

    H3ID2

    I4

    B40

    I3ID3

    H3ID3

    I4

    I3ID4

    H3ID4

    I6

    There is no IN_TABLE_BATCH_3

    Please find below the expected results.

    OUTPUT

     

    ITEM_CODE

    BAT_NO

    TXN_CODE

    DOC_NO

    BOE_DT

    BATCH_YN

    I1

    B1

    T1

    1234

    JANUARY 3, 2015

    THERE

    I1

    B30

    T30

    7890

    FEBRUARY 5, 2015

    N

    I2

    B60

    T60

    1234

    JANUARY 3, 2015

    N

    I3

    B70

    T70

    1234

    FEBRUARY 1, 2015

    THERE

    I4

    T90

    1234

    JANUARY 4, 2015

    N

    I6

    T40

    1234

    AUGUST 5, 2015

    N

    Controls database to create the tables above and insert the records.

    CREATE TABLE stock_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), boe_dt DATE );

    INSERT EN stock_table

       VALUES ('I1', 'B1', '', '', '');

    INSERT EN stock_table

       VALUES ('I1', '', '', '', '');

    INSERT IN stock_table

       VALUES ('I2', '', '', '', '');

    INSERT EN stock_table

       VALUES ('I3', 'B70', '', '', '');

    INSERT EN stock_table

       VALUES ('I4', 'B80', '', '', '');

    INSERT EN stock_table

       VALUES ('I5', 'B90', 'T102', '1234', '02-JUL-2015');

    INSERT EN stock_table

       VALUES ('I6', 'B100', '', '', '');

    SELECT *

    FROM stock_table




     

    CREATE TABLE history_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), updt_dt DATE );

    INSERT IN history_table

       VALUES ('I1', 'B1', 'T1', '1234', '03-JAN-2015');

    INSERT IN history_table

       VALUES ('I1', 'B20', 'T20', '4567', '03-MAR-2015');

    INSERT IN history_table

       VALUES ('I1', 'B30', 'T30', '7890', '05-FEB-2015');

    INSERT IN history_table

       VALUES ('I2', 'B40', 'T20', '1234', '01-JAN-2015');

    SELECT *

    FROM history_table




     

    CREATE TABLE transaction1()txn_code VARCHAR()80),txn_type VARCHAR()80));


    INSERT INTO transaction1

       VALUES ('T1', 'IN');


    INSERT INTO transaction1

       VALUES ('T20', 'OUT');

    INSERT INTO transaction1

       VALUES ('T30', 'ALL');

    INSERT INTO transaction1

       VALUES ('T40', 'ALL');

    INSERT INTO transaction1

       VALUES ('T50', 'IN');

    INSERT INTO transaction1

       VALUES ('T60', 'ALL');

    INSERT INTO transaction1

       VALUES ('T70', 'ALL');

    INSERT INTO transaction1

       VALUES ('T80', 'IN');

    INSERT INTO transaction1

       VALUES ('T90', 'IN');

    SELECT *

    FROM transaction1




     

    CREATE TABLE in_table_head_1()h1_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), doc_dt DATE );

    CREATE TABLE in_table_head_2()h2_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), doc_dt DATE );

    CREATE TABLE in_table_head_3()h3_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), doc_dt DATE );

     

    INSERT IN in_table_head_1

       VALUES ('H1ID1', 'T1', '1234', '01-JAN-2015');

    INSERT IN in_table_head_1

       VALUES ('H1ID2', 'T70', '1234', '01-FEB-2015');

    INSERT IN in_table_head_2

       VALUES ('H2ID1', 'T30', '4567', '03-FEB-2015');

    INSERT IN in_table_head_2

       VALUES ('H2ID2', 'T60', '1234', '03-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID1', 'T50', '1234', '02-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID2', 'T80', '1234', '03-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID3', 'T90', '1234', '05-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID4', 'T40', '1234', '05-AUG-2015');




     

    CREATE TABLE in_table_item_1()i1_sys_id VARCHAR2()80) PRIMARY KEY,

    h1_sys_id VARCHAR2 (80) REFERENCES in_table_head_1()h1_sys_id),item_code VARCHAR2()80));

    CREATE TABLE in_table_item_2()i2_sys_id VARCHAR2()80) PRIMARY KEY,

    h2_sys_id VARCHAR2 (80) REFERENCES in_table_head_2()h2_sys_id),item_code VARCHAR2()80));

    CREATE TABLE in_table_item_3(i3_sys_id VARCHAR2(80) PRIMARY KEY,

    h3_sys_id VARCHAR2 (80) REFERENCES in_table_head_3()h3_sys_id),item_code VARCHAR2()80),

    bat_no VARCHAR2 (80));

     

    INSERT IN in_table_item_1

       VALUES ('I1ID1', 'H1ID1', 'I1');

    INSERT IN in_table_item_1

       VALUES ('I1ID2', 'H1ID1', 'I100');

    INSERT IN in_table_item_1

       VALUES ('I1ID3', 'H1ID2', 'I3');

    INSERT IN in_table_item_2

       VALUES ('I2ID1', 'H2ID1', 'I1');

    INSERT IN in_table_item_2

       VALUES ('I2ID2', 'H2ID1', 'I200');

    INSERT IN in_table_item_2

       VALUES ('I2ID3', 'H2ID2', 'I2');

    INSERT IN in_table_item_3

       VALUES ('I3ID1', 'H3ID1', 'I2','B50');

    INSERT IN in_table_item_3

       VALUES ('I3ID2', 'H3ID2', 'I4','B40');

    INSERT IN in_table_item_3

       VALUES ('I3ID3', 'H3ID3', 'I4','');

    INSERT IN in_table_item_3

       VALUES ('I3ID4', 'H3ID4', 'I6','');

    SELECT *

    FROM in_table_item_1

    SELECT *

    FROM in_table_item_2

    SELECT *

    FROM in_table_item_3




     

    CREATE TABLE in_table_batch_1()b1_sys_id VARCHAR2()80) PRIMARY KEY,

    txn_code VARCHAR2 (80), doc_no VARCHAR2 (80), bat_no VARCHAR2 (80));

    CREATE TABLE in_table_batch_2()b2_sys_id VARCHAR2()80) PRIMARY KEY,

    i2_sys_id VARCHAR2 (80) REFERENCES in_table_item_2()i2_sys_id),bat_no VARCHAR2()80));

     

    INSERT IN in_table_batch_1

       VALUES ('B1ID1', 'T1', '1234', 'B1');

    INSERT IN in_table_batch_1

       VALUES ('B1ID2', 'T70', '1234', 'B70');

    INSERT IN in_table_batch_2

       VALUES ('B2ID1', 'I2ID1', 'B30');

    INSERT IN in_table_batch_2

       VALUES ('B2ID2', 'I2ID2', 'B90');

    INSERT IN in_table_batch_2

       VALUES ('B2ID3', 'I2ID3', 'B60');

    Please advise a solution for the same.

    Thank you and best regards,

    Séverine Suresh

    very forced (question subfactoring used to allow easy testing/verification - could work with these test data only)

    with

    case_1 as

    (select s.item_code,

    s.bat_no,

    h.txn_code,

    h.doc_no,

    h.updt_dt boe_dt,

    cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.

    cases where h.txn_code is not null

    and h.doc_no is not null

    and h.updt_dt is not null

    then 'case 1' '.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, boe_dt

    of w_stock_table

    where bat_no is null

    or txn_code is null

    or doc_no is null

    or boe_dt is null

    ) s

    left outer join

    w_history_table h

    On s.item_code = h.item_code

    and s.bat_no = h.bat_no

    and exists (select null

    of w_transaction1

    where txn_code = nvl (s.txn_code, h.txn_code)

    and txn_type in ('IN', 'ALL')

    )

    ),

    case_2 as

    (select s.item_code,

    NVL (s.bat_no, h.bat_no) bat_no.

    NVL (s.txn_code, h.txn_code) txn_code.

    NVL (s.doc_no, h.doc_no) doc_no.

    NVL (s.boe_dt, h.updt_dt) updt_dt.

    cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.

    cases where h.txn_code is not null

    and h.doc_no is not null

    and h.updt_dt is not null

    then 'case 2'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, boe_dt

    of case_1

    where refers_to is null

    ) s

    left outer join

    w_history_table h

    On s.item_code = h.item_code

    and exists (select null

    of w_transaction1

    where txn_code = nvl (s.txn_code, h.txn_code)

    and txn_type in ('IN', 'ALL')

    )

    and not exists (select null

    of case_1

    where item_code = h.item_code

    and bat_no = h.bat_no

    and txn_code = h.txn_code

    and doc_no = h.doc_no

    and updt_dt = h.updt_dt

    )

    ),

    case_31 as

    (select s1.item_code,

    NVL (S1.bat_no, W1.bat_no) bat_no.

    NVL (S1.txn_code, W1.txn_code) txn_code.

    NVL (S1.doc_no, W1.doc_no) doc_no.

    NVL (S1.updt_dt, W1.doc_dt) updt_dt.

    cases where s1.bat_no = w1.bat_no then 'Y' else ' n end batch_yn.

    cases where w1.txn_code is not null

    and w1.doc_no is not null

    and w1.doc_dt is not null

    then "case 31'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to

    of case_2

    where refers_to is null

    ) s1

    left outer join

    (select i1.item_code, h1.txn_code, h1.doc_no, h1.doc_dt, b1.bat_no

    of w_in_table_item_1 i1

    inner join

    w_in_table_head_1 h1

    On i1.h1_sys_id = h1.h1_sys_id

    inner join

    w_in_table_batch_1 b1

    On h1.txn_code = b1.txn_code

    and h1.doc_no = b1.doc_no

    ) w1

    On s1.item_code = w1.item_code

    ),

    case_32 as

    (select s2.item_code,

    NVL (S2.bat_no, W2.bat_no) bat_no.

    NVL (S2.txn_code, W2.txn_code) txn_code.

    NVL (S2.doc_no, W2.doc_no) doc_no.

    NVL (S2.updt_dt, W2.doc_dt) updt_dt.

    cases where s2.bat_no = w2.bat_no then 'Y' else ' n end batch_yn.

    cases where w2.txn_code is not null

    and w2.doc_no is not null

    and w2.doc_dt is not null

    then "case 32'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to

    of case_2

    where refers_to is null

    ) s2

    left outer join

    (select i2.item_code, h2.txn_code, h2.doc_no, h2.doc_dt, b2.bat_no

    of w_in_table_item_2 i2

    inner join

    w_in_table_head_2 h2

    On i2.h2_sys_id = h2.h2_sys_id

    inner join

    w_in_table_batch_2 b2

    On i2.i2_sys_id = b2.i2_sys_id

    ) w2

    On s2.item_code = w2.item_code

    ),

    case_33 as

    (select s3.item_code,

    w3.bat_no,

    NVL (S3.txn_code, w3.txn_code) txn_code.

    NVL (S3.doc_no, w3.doc_no) doc_no.

    NVL (S3.updt_dt, w3.doc_dt) updt_dt.

    cases where s3.bat_no = w3.bat_no then 'Y' else ' n end batch_yn.

    cases where w3.txn_code is not null

    and w3.doc_no is not null

    and w3.doc_dt is not null

    then "case 33'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to

    of case_2

    where refers_to is null

    ) s3

    left outer join

    (select i3.item_code, h3.txn_code, h3.doc_no, h3.doc_dt, i3.bat_no

    of w_in_table_item_3 i3

    inner join

    w_in_table_head_3 h3

    On i3.h3_sys_id = h3.h3_sys_id

    ) w3

    On s3.item_code = w3.item_code

    )

    Select item_code, bat_no, txn_code, doc_no, boe_dt, batch_yn

    of case_1

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_2

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn,

    ROW_NUMBER() over (partition by item_code of updt_dt desc order) rn

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_31

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_32

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_33

    where refers_to is not null

    )

    )

    where rn = 1

    ITEM_CODE BAT_NO TXN_CODE DOC_NO BOE_DT BATCH_YN
    I1 B1 T1 1234 JANUARY 3, 2015 THERE
    I1 B30 T30 7890 FEBRUARY 5, 2015 N
    I2 B60 T60 1234 JANUARY 3, 2015 N
    I3 B70 T70 1234 FEBRUARY 1, 2015 THERE
    I4 - T90 1234 JANUARY 5, 2015 N
    I6 - T40 1234 AUGUST 5, 2015 N

    Concerning

    Etbin

  • SQL query to display the sum of the values of each June and December

    Hello having problems of construction of a query to the list SQL query to display the sum of the values of each June and December each year.

    My Table;

    TABLE name: MONTH_TERM

    Fields with values:

    TERM_KEYMONTH_ACTUALMONTH_DATE
    8250001/11/2015 0:00
    8245001/12/2015 0:00
    8240501/01/2016 0:00
    8240001/02/2016 0:00
    8245001/03/2016 0:00
    8242501/04/2016 0:00
    8243501/05/2016 0:00
    8241006/01/2016 0:00
    8240901/07/2016 0:00
    8241501/08/2016 0:00
    8242009/01/2016 0:00
    8242210/01/2016 0:00
    8243611/01/2016 0:00
    8255601/12/2016 0:00
    8256801/01/2017 0:00
    8262402/01/2017 0:00

    What I would like to see in a query result:

    TERM_KEYMONTH_ACTUALMONTH_DATETotal of 6 months
    8250001/11/2015 0:00
    8245001/12/2015 0:00950
    8240501/01/2016 0:00
    8240001/02/2016 0:00
    8245001/03/2016 0:00
    8242501/04/2016 0:00
    8243501/05/2016 0:00
    8241006/01/2016 0:002525
    8240901/07/2016 0:00
    8241501/08/2016 0:00
    8242009/01/2016 0:00
    8242210/01/2016 0:00
    8243611/01/2016 0:00
    8255601/12/2016 0:002658
    8256801/01/2017 0:00
    8262402/01/2017 0:00

    ---

    Here's my query:

    Select

    "TERM_KEY,"

    "MONTH_ACTUAL,"

    to_char(MONTH_DATE,'MM/YYYY') MONTH_DATE,

    DEAL to_char (MONTH_DATE, 'MM')

    WHEN '06' THEN (SELECT SUM (MONTH_ACTUAL)

    OF MONTH_TERM

    WHERE the to_char (MONTH_DATE, 'MM') between 1 and 6

    AND term_key = 82)

    WHEN '12' THEN (SELECT SUM (MONTH_ACTUAL)

    OF MONTH_TERM

    WHERE the to_char (MONTH_DATE, 'MM') between 7 and 12

    AND term_key = 82)

    ELSE null

    END as SIX_MO_CUMM,

    of MONTH_TERM

    where term_key = 82

    It's my results:

    TERM_KEYMONTH_ACTUALMONTH_DATETotal of 6 months
    8250001/11/15 0:00
    8245001/12/15 0:003608
    8240501/01/16 0:00
    8240001/02/16 0:00
    8245001/03/16 0:00
    8242501/04/16 0:00
    8243501/05/16 0:00
    8241001/06/16 0:003717
    8240901/07/16 0:00
    8241501/08/16 0:00
    8242001/09/16 0:00
    8242210/01/16 0:00
    8243601/11/16 0:00
    8255601/12/16 0:003608
    8256801/01/17 0:00
    8262401/02/17 0:00

    Any ideas on how to fix would be great

    Select term_key,

    month_actual,

    month_date,

    case mod (to_char (month_date, 'mm'), 6)

    When 0 then sum (month_actual)

    During)

    term_key partition

    order of month_date

    between the previous month '5' interval and the current line

    )

    end '6 MONTHS in TOTAL'

    from tbl

    order of term_key,

    month_date

    /

    TERM_KEY MONTH_ACTUAL MONTH_DAT 6 MONTHS TOTAL
    ---------- ------------ --------- --------------
    82 500 NOVEMBER 1ST, 15TH
    82 450 1 DECEMBER 15 950
    82 405 1 JANUARY 16
    82 400 1 FEBRUARY 16
    82 450 1ST MARCH 16
    82 425 1ST APRIL 16
    82 435 1 MAY 16
    82 410 2525 1 JUNE 16
    82 409 1 JULY 16
    82 415 1ST AUGUST 16
    82 420 16 - SEP - 01

    TERM_KEY MONTH_ACTUAL MONTH_DAT 6 MONTHS TOTAL
    ---------- ------------ --------- --------------
    82 422 1 OCTOBER 16
    82-436 NOVEMBER 1, 16
    82 556 2658 1 DECEMBER 16
    82 568 1 JANUARY 17
    82 624 1 FEBRUARY 17

    16 selected lines.

    SQL >

    SY.

  • SQL query to retrieve a single record for each employee of the following table?

    Hi all

    Help me on the writing of SQL query to retrieve a single record for each employee of the following table? preferably a standard SQL.

    CREATE TABLE xxc_contact)

    empnum NUMBER,

    alternatecontact VARCHAR2 (100),

    relationship VARCHAR2 (10),

    phtype VARCHAR2 (10),

    Phone NUMBER

    );

    insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Cell', 9999999999)

    insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Work', 8888888888)

    insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Work', 7777777777)

    insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Home', 3333333333)

    insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Cell', 9999999999)

    insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Home', 9999999999)

    expected result:

    EmpNum AlternateContact Relationship PhType Phone       

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    Thanks in advance.

    994122 wrote:

    Thank you all, that I got a result

    http://www.orafaq.com/Forum/m/620305/#msg_620305

    By Lalit Kumar B...

    Specifically, the two simple solutions provided were:

    1 using the row_number, entitled Oracle ranking based on descending order of the inside telephone each empnum group. And finally selects the lines which has least rank (of least since that order is descending for phone).

    SQL > column alternatecontact format A20;

    SQL >

    SQL > SELECT empnum, alternatecontact, relationship, phtype, phone

    2 from (SELECT a.*, row_number() over r (PARTITION BY empnum ORDER BY phone / / DESC))

    3 FROM xxc_contact one)

    4. WHEN r = 1

    /

    EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE

    ---------- -------------------- ---------- ---------- ----------

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    2. with the help of MAX, Oracle automatically assigns the maximum phone for all the rows in each group of empnum. And finally selects the rows with the maximum phone. Order by clause is omitted here intentionally. You can find out why.

    SQL > SELECT empnum, alternatecontact, relationship, phtype, phone

    2 (SELECT a.*, MAX (phone) over (PARTITION BY empnum) rn FROM xxc_contact one)

    3 WHERE phone = rn

    4.

    EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE

    ---------- -------------------- ---------- ---------- ----------

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    Kind regards

    Lalit

  • For the MONEY and to break on a column SQL query

    Hello

    I have a situation where the data in the table are as below

    AA

    BB

    1

    FG

    1

    FG

    1

    FG

    2

    SS

    1

    FG

    I need to write a sql query that would give output like below. Basically, it must break BB of the column and the value of the sum up to what it breaks.

    AA

    BB

    3

    FG

    2

    SS

    1

    FG

    Please suggest.

    Thank you

    Shankar

    Hello

    770914 wrote:

    Hello

    I have a situation where the data in the table are as below

    AA

    BB

    1

    FG

    1

    FG

    1

    FG

    2

    SS

    1

    FG

    I need to write a sql query that would give output like below. Basically, it must break BB of the column and the value of the sum up to what it breaks.

    AA

    BB

    3

    FG

    2

    SS

    1

    FG

    Please suggest.

    Thank you

    Shankar

    Remember, there is no order integrated to the rows in a table.  The table you have posted is exactly the same as:

    AA bb

    --    --

    1 FG

    1 FG

    2 SS

    1 FG

    1 FG

    and both are exactly the same as:

    AA bb

    --    --

    2 SS

    1 FG

    1 FG

    1 FG

    1 FG

    If you use words like 'first', 'previous' or 'row' when it comes to lines, then we must define what these words mean.  This is usually done by making reference to a column in the table.  For example, if you had a column called r_num, like this:

    AA bb r_num

    --    --    -----

    1 FG 1

    1 FG 2

    1 FG 9

    2 SS 10

    1 FG 10.5

    Then, it would be wise to say things like 'the table starts with 3 lines consecutive "FG", followed by "SS".  After that there is another "FG", which is the last line in the table, WHEN TRIE BY R_NUM.   If the part about "WHEN SORTED BY R_NUM" is not known, the words 'begins '. "consecutive", 'followed', 'after' and 'last' have no meaning.

    If (and only if) you have somehting like r_num in your table. Then you can get the resutls you want like this:

    WITH got_group_num AS

    (

    SELECT aa, bb, r_num

    ROW_NUMBER () OVER (ORDER BY r_num)

    -ROW_NUMBER () OVER (PARTITION BY bb

    ORDER BY r_num

    ) AS group_num

    FROM table_x

    )

    SELECT SUM (aa) AS total_aa

    ,         bb

    OF got_group_num

    GROUP BY bb

    group_num

    ORDER OF MIN (r_num)

    ;

Maybe you are looking for