SQL Query hierarchical select 2 level parent over sheet.

Here, we use Oracle 11 g R1. Here is a sample of our Tables of the employee.

I want you select all managers managers above them (which we call the Site Manager) and direct (that we call the Service Manager)

Here is the example for the base table.

SET DEFINE OFF;
CREATE TABLE EMP_SAMPLE 
(
  AGENT_ID VARCHAR2(100 BYTE) 
, FULL_NAME VARCHAR2(100 BYTE) 
, AGENT_MANAGER VARCHAR2(100 BYTE) 
) ;

Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('JS001','JOHN SMITH',null);
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('AL001','ANN LEE','JS001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('JD001','JOHN DOE','AL001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('MB002','MARY BAKER','AL001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('HM003','HOWARD MONROE','MB002');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('RM001','ROBYN MILLER','MB002');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('DJ002','DAVID JONES','RM001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('WW001','WENDY WONG','MB002');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('PB001','PETER RABBIT','JS001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('BB002','BEN BUNNY','PB001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('TM001','TONY MILLER','BB002');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('PP002','PETER PARKER','RM001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('PP003','PEPPA PIG','PB001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('DB002','daniel baker','HM003');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('TL001','Tom Lee','WW001');
Insert into EMP_SAMPLE (AGENT_ID,FULL_NAME,AGENT_MANAGER) values ('MS001','Mary Smith',null);

With the example like this data, I would like to that the result looks similar to

Name of the Manager

MARY BAKER - Manager of the Site

HOWARD MONROE - Service Manager

ROBYN MILLER - Service Manager

WENDY WOND - Service Manager

PETER RABBIT Site Manager

BEN BUNNY - Service Manager

I guess I should use the hierarchical query to achieve this. I googled to see all the solutions, I tried this under request

SELECT agent_id, agent_manager, RPAD('.', (level-1)*2, '.') || full_name AS tree,
       level, CONNECT_BY_ROOT agent_id as root_id
       ,CONNECT_BY_ISLEAF AS is_leaf

FROM EMP_SAMPLE
START WITH agent_manager IS NULL
CONNECT BY agent_manager = PRIOR agent_id
ORDER SIBLINGS BY agent_id;

But it seems that the level always starts from the root at the top of the page. I wonder, is it possible to identify even just the level two above the sheet.

Here is some basic information. We are working on our oracle APEX application. One of the reports can be filtered by the Manager. The list currently shows a little all managers, regardless of what they are 1 senior as general manager, or the first line as a Service Manager Manager. Now, users want to be able to select only Service Manager and Site Manager.

There is a DB work for updating the table Employee of LDAP. And the LDAP structure is not tidy this (we have some staff members who have no Manager, they are not even CEO). The Administrator told us that it is too busy to store it.

We have about 20,000 employees in total including 800 East of managers.

Thanks in advance.

Ann

Hi, Ann.

Ann586341 wrote:

Here, we use Oracle 11 g R1. Here is a sample of our Tables of the employee.

I want you select all managers managers above them (which we call the Site Manager) and direct (that we call the Service Manager)

Here is the example for the base table.

  1. TOGETHER TO DEFINE
  2. CREATE TABLE EMP_SAMPLE
  3. (
  4. AGENT_ID VARCHAR2 (100 BYTE)
  5. FULL_NAME VARCHAR2 (100 BYTE)
  6. AGENT_MANAGER VARCHAR2 (100 BYTE)
  7. ) ;
  8. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('JS001', 'JOHN SMITH', null);
  9. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('AL001', "ANN LEE", "JS001");
  10. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('JD001', 'JOHN DOE', "AL001");
  11. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('MB002', "MARY BAKER", "AL001");
  12. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('HM003', 'HOWARD MONROE', 'MB002');
  13. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('RM001", 'ROBYN MILLER', 'MB002');
  14. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('DJ002', 'DAVID JONES', "RM001");
  15. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('WW001', "WENDY WONG", "MB002");
  16. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('PB001', 'PETER RABBIT', "JS001");
  17. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('BB002', "BEN BUNNY", "PB001");
  18. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('TM001', 'TONY MILLER', "BB002");
  19. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('PP002","PETER PARKER","RM001");
  20. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('PP003', 'PEPPA PIG', "PB001");
  21. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('DB002', "daniel baker", "HM003");
  22. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('TL001', "Tom Lee", "WW001");
  23. Insert into EMP_SAMPLE (AGENT_ID, FULL_NAME, AGENT_MANAGER) values ('MS001', 'Mary Smith', null);

With the example like this data, I would like to that the result looks similar to

Name of the Manager

MARY BAKER - Manager of the Site

HOWARD MONROE - Service Manager

ROBYN MILLER - Service Manager

WENDY WOND - Service Manager

PETER RABBIT Site Manager

BEN BUNNY - Service Manager

I guess I should use the hierarchical query to achieve this. I googled to see all the solutions, I tried this under request

  1. SELECT agent_id, agent_manager, RPAD ('.) (', (level 1) * 2, '.') || full_name LIKE tree,
  2. level, agent_id CONNECT_BY_ROOT as root_id
  3. CONNECT_BY_ISLEAF AS is_leaf
  4. OF EMP_SAMPLE
  5. START WITH agent_manager IS NULL
  6. CONNECT BY PRIOR agent_id = agent_manager
  7. Brothers and SŒURS of ORDER BY agent_id;

But it seems that the level always starts from the root at the top of the page. I wonder, is it possible to identify even just the level two above the sheet.

Here is some basic information. We are working on our oracle APEX application. One of the reports can be filtered by the Manager. The list currently shows a little all managers, regardless of what they are 1 senior as general manager, or the first line as a Service Manager Manager. Now, users want to be able to select only Service Manager and Site Manager.

There is a DB work for updating the table Employee of LDAP. And the LDAP structure is not tidy this (we have some staff members who have no Manager, they are not even CEO). The Administrator told us that it is too busy to store it.

We have about 20,000 employees in total including 800 East of managers.

Thanks in advance.

Ann

Here's one way:

WITH leaves LIKE

(

SELECT agent_id

Of emp_sample

LESS

SELECT agent_manager

Of emp_sample

)

got_lvl AS

(

SELECT-full_name agent_id

LEVEL AS lvl

Of emp_sample

START WITH agent_id IN)

SELECT agent_id

Sheets

)

CONNECTION BY agent_id = agent_manager PRIOR

)

SELECT full_name

CASE

WHEN MAX (lvl) = 3

THEN 'Site Manager'

ANOTHER "Service Manager"

END AS title

OF got_lvl

GROUP BY full_name-, agent_id

WITH MIN (lvl) > = 2

AND MAX (lvl)<=>

ORDER BY full_name

;

Output:

FULL_NAME TITLE

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

BEN BUNNY Service Manager

MONROE HOWARD Service Manager

MARY BAKER Site Manager

PETER RABBIT Site Manager

ROBYN MILLER Service Manager

WENDY WONG Service Manager

Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

LEVEL does not always begin with the root; It starts with the lines that meet the condition to START WITH.  If you have a START WITH condition that only roots meet (as in the query you posted) then, Yes, LEVEL will start with the roots.  If you have a condition START WITH answering the criteria only the leaves (as in the query I posted), then LEVEL will start with the leaves.

I guess just some of your needs.  If seems that a 'Site Manager' is the grandparent of a leaf, but "John Smith" (which is the grandmother of "John Doe", a sheet) is not considered to be a 'Site Manager'.  Similarly, it seems that a 'Service Manager' is the parent (but not the grand-parent) of the leaf, but "Ann Lee" (the mother of "John Doe") is not considered to be a 'Service Manager' for a reason any.

I guess that full_name is unique.  If full_name is not unique, but agent_id is, then you will need a comment a few line above ends.  (I guess that agent_id is unique and not NULL).

Tags: Database

Similar Questions

  • You have no lines for the SQL query to select

    Dear Sir.

    I don't want to choose these lines in the second query, please guide me how to do.

    Request-> 1

    (SELECT ID_NO, ATTND_DATE
        FROM ATTND_REGISTER 
        WHERE ATTND_DATE BETWEEN :FD AND :TD
        ORDER BY ID_NO, ATTND_DATE
    )AT
    

    A query result.

    ID_NOATTND_DATE
    E1FEBRUARY 1, 14
    E1FEBRUARY 2, 14
    E13 FEBRUARY 14
    E14 FEBRUARY 14
    E1FEBRUARY 5, 14
    E1FEBRUARY 6, 14
    E1FEBRUARY 7, 14
    E1FEBRUARY 8, 14
    E1FEBRUARY 9, 14
    E110 FEBRUARY 14
    E1FEBRUARY 11, 14
    E1FEBRUARY 12, 14
    E1FEBRUARY 13, 14
    E114 FEBRUARY 14
    E115 FEBRUARY 14
    E116 FEBRUARY 14
    E117 FEBRUARY 14
    E118 FEBRUARY 14
    E119 FEBRUARY 14
    E120 FEBRUARY 14
    E4FEBRUARY 1, 14
    E4FEBRUARY 2, 14
    E43 FEBRUARY 14
    E44 FEBRUARY 14
    E4FEBRUARY 5, 14

    Request-> 2

    : VALUE OF THE VARIABLE FD = 1 FEBRUARY 14

    : VALUE OF THE VARIABLE TD = FEBRUARY 28, 14 '

    SELECT A.ID_NO,B.DATES,A.EMP_NAME, A.DESG_NAME
    FROM
      (
        SELECT  ROWNUM - 1 + TO_DATE(:FD, 'DD/MM/RR') DATES
        FROM ALL_OBJECTS
        WHERE ROWNUM < TO_DATE(:TD, 'DD/MM/RR') - TO_DATE(:FD, 'DD/MM/RR') + 2
      )B,
    
    
      (
        SELECT ID_NO, INITCAP(FL_NAME) AS EMP_NAME, INITCAP(UBN.DESG_NAME(DESG_ID)) AS DESG_NAME
        FROM PERSONAL
        WHERE (STATUS = 'A')
        AND (COMPANY_CODE = :COMPANY_CODE)---COMPANY CODE=6
        AND (ID_NO = :ID_NO OR :ID_NO IS NULL)
      )A
    ORDER BY A.ID_NO,B.DATES;
    


    Solved

    I changed in the second query with using the first query.

    in Where Clause

    WHERE B.DATES | A.ID_NO NOT IN (SELECT ATTND_DATE |) NBI ID_NO. ATTND_REGISTER

    WHERE ATTND_DATE BETWEEN: FD AND: TD)

    Thank you Allah (SWT).

  • SQL query to select pairs

    Hi team,

    I have a table like the below,

    Column A column B

    1               123| ABCS

    2               456| BELL

    3               789| ABCS

    4               233| OLIVIER

    5               123| ABCS

    Now, I need to select all the lines that have a same character after ' |' in column B (in this case, all lines that have ABC after ' |'). I tried with joins and contains, but it does not work.

    If someone could help

    Thank you

    Balls

    Hello

    Try this:

    with test_data as
    (
    Select 1A, 123 | The ABC's of all B the double union
    Select 2A, 456. BELL ' B of all the double union
    Select 3A, 789 | The ABC's of all B the double union
    Select option 4 A, 233. OLIVIER ' B of all the double union
    Select 5, 123 | The ABC's of the double B
    )
    more_than_once as
    (
    Select
    substr (b, InStr(b,'|') + 1) c
    count (*) NTC
    Of
    test_data

    Group
    substr (b, InStr(b,'|') + 1)

    view count (*) > 1
    )
    Select
    *
    Of
    test_data
    where
    substr (b, InStr(b,'|') + 1) (select from more_than_once c)
    ;

    A AND B

    - --------

    1 123 | ABCS

    3 789 | ABCS

    5 123 | ABCS

    Kind regards

    Peter

  • Passing the value of the SQL query select list

    Hello

    In my application users have in their homepage to a region which has two simple things, a part of LIST SLECT lov function and a BUTTON

    There is also another page which has a normal life to report which shows the employees.


    Homepage the user can select certain number of Department in its 'SLECT-LIST' and click 'open '.


    For example: If the user has selected a DEP_NUM_5 and click on the BUTTON it will be redirected to the page of a report and gets only showed the employees belonging to the Department 5.


    The report page contains a simple SQL query, and I understand that somehow I must pass the value in the SELECT LIST, where I now have the '?


    How can I do this, where should I start?

    Of course I would really appreciate an example of code, if anyone has time to do a.

    
    select "EMP_ID", 
    "EMP_FORNAME",
    "EMP_SURNAME",
    "DEP_NUMBER"
    from EMP E
    where E.DEP_NUMBER = ????????
    
    

    Hi Sozua,

    1. create an item hidden on the page where you have the report.

    I say P2_DEPT_NO

    2 assign to that in your sql query

    select "EMP_ID",
        "EMP_FORNAME",
        "EMP_SURNAME",
        "DEP_NUMBER"
        from EMP E
        where E.DEP_NUMBER = :P2_DEPT_NO
    

    below the area source ther is also an option

    Elements of page to submit-> put this element in this.

    for example;

    Page to submit items: P2_DEPT_NO

    3. change your button

    Action: Redirecting to page of this application

    Page: 2 / / assuming that page 2 is the report page

    Place these items: P2_DEPT_NO

    with these values: & P1_SELECT_LIST.  assuming that selection list is on page 1

    Hope this helps you,

    Kind regards

    Jitendra

  • Need help in the sql query

    Hi all

    Here is the sql query,

    Select papf.employee_number,

    -papf.full_name, ppa.effective_date, pp.payroll_name,

    PET.element_name,

    PIV. Name input_value,

    prrv.result_value

    -, ppa.payroll_action_id, ppa.time_period_id

    Of

    Apps.pay_payroll_actions App,

    pay_assignment_actions AAP,

    pay_payrolls_f pp,

    pay_run_results prr,

    prrv pay_run_result_values,

    pay_input_values_f piv,

    animal pay_element_types_f,

    Apps.per_all_assignments_f ADP,

    Apps.per_all_people_f women's wear

    -where ppa.payroll_action_id =: payroll_action_id - give your payroll_action_id

    where ppa.payroll_id =: payroll_id

    and ppa.payroll_action_id =: payroll_action_id

    - and paa.assignment_action_id =: assignment_action_id

    and ppa.payroll_action_id = paa.payroll_action_id

    and ppa.payroll_id = pp.payroll_id

    and paa.assignment_action_id = prr.assignment_action_id

    and prr.run_result_id = prrv.run_result_id

    and prrv.input_value_id = piv.input_value_id

    and piv.element_type_id = pet.element_type_id

    and paaf.assignment_id = paa.assignment_id

    and paaf.person_id = papf.person_id

    and trunc (sysdate) between pp.effective_start_date and pp.effective_end_date

    and trunc (sysdate) between pet.effective_start_date and pet.effective_end_date

    and trunc (sysdate) between piv.effective_start_date and piv.effective_end_date

    and trunc (sysdate) between paaf.effective_start_date and paaf.effective_end_date

    and trunc (sysdate) between papf.effective_start_date and papf.effective_end_date

    - and papf.employee_number = '1'

    - and ppa.effective_date = July 22, 2014"

    and pet.element_name in ('Local Mission allowance', "Compensation of Mission International")

    order by 1.3

    The result is:

    Employee_number Element_Name Input_Value Result_value

    1 compensation of Mission international day amount 1000

    1 compensation of international Mission Distance days 4

    1 value to pay compensation of 1200 International Mission

    1 International Mission allowance Start Date 01/01/2014

    1 compensation of Mission international day amount 800

    1 compensation of international Mission Distance days 10

    1 International Mission allowance pay value 2000

    1 International Mission allowance Start Date 01/02/2014

    1 compensation of Mission local day amount 500

    1 compensation of local Mission Distance days 10

    1 Mission allowance paid local value 1000

    1 compensation of local Mission Start Date 01/11/2014

    Desired output:

    Employee_number Element_Name Day_Amount Distance_Days Pay_Value Start_Date

    1 compensation of international Mission 1000, 1200 4 2014/01/01

    1

    International Mission allowance80010200001/02/2014
    1Mission local compensation50010100001/11/2014

    Please suggest.

    INSERT statement:

    TOGETHER TO DEFINE

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'Day amount', '1000');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'Day amount', '1000');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'number of orders', '196');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'number of orders', '195');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', ' Distance days, 4 ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', ' Distance days, 1 ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ("1', 'International Mission allowance', 'employee Category", "scale of employment medical cities");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ("1', 'International Mission allowance', 'employee Category", "scale of employment medical cities");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'Class level', 'G3');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'Class level', 'G3');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'class of employment, ' ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'class of employment, ' ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'Country of Mission', ' 3003 - Kuwait ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'Country of Mission', ' 2004 - Canada ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', ' Mission days, 4' ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', ' Mission days, 3' ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'compensation of Mission international","End of Mission Date"' 2014/07/10 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'compensation of Mission international","End of Mission Date"' 2014/07/19 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'compensation of Mission international", 'Mission Start Date', ' 2014/07/07 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'compensation of Mission international", 'Mission Start Date', ' 2014/07/17 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'value of pay', '3000');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('1', 'International Mission allowance', 'value of pay', '4000');

    00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'Local Mission allowance', 'number of orders', '45');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'Local Mission allowance', 'number of orders', "456789");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', 'local Mission allowance', ' away days '0' ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', 'local Mission allowance', ' Distance days, 1 ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', 'local Mission allowance', 'Provided food', 'Y');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'compensation of local Mission","Accommodation provided", 'Y');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'compensation of local Mission","Accommodation provided", 'Y');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', "local Mission allowance", "Mission City", "AL MEDINA");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', "local Mission allowance", "Mission City", "RIYADH");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', 'local Mission allowance', ' Mission days, 4' ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70 ', 'local Mission allowance', ' Mission days, 5' ");

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'Local Mission allowance', 'End of Mission Date' ' 2014/06/16 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'Local Mission allowance', 'End of Mission Date' ' 2014-06-14 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'Local Mission allowance', 'Mission Start Date', ' 2014/06/13 00:00:00 ');

    Insert into APPS. PER_ALL_PEOPLE_F

    (EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)

    Values

    ('70', 'Local Mission allowance', 'Mission Start Date', ' 2014/06/10 00:00:00 ');

    Thank you very much in advance.

    Kind regards

    Afzal.

    So then... something like this:

    SELECT employee_number

    element_name

    MAX (decode (input_value, 'Day amount', result_value)) AS day_amount

    MAX (decode (input_value, 'Days of Distance', result_value)) AS Distance_Days

    , MAX (decode (input_value, 'Value of pay', result_value)) AS Pay_Value

    MAX (decode (input_value, 'Start Date', result_value)) AS Start_Date

    from (SELECT papf.employee_number

    pet.element_name

    piv.NAME input_value

    prrv.result_value

    prrv.run_result_id

    OF apps.pay_payroll_actions App

    pay_assignment_actions PAA

    pay_payrolls_f pp

    pay_run_results prr

    pay_run_result_values prrv

    pay_input_values_f piv

    pay_element_types_f pet

    apps.per_all_assignments_f ADP

    apps.per_all_people_f women's wear

    -where ppa.payroll_action_id =: payroll_action_id - give your payroll_action_id

    WHERE ppa.payroll_id =: payroll_id

    AND ppa.payroll_action_id =: payroll_action_id

    - and paa.assignment_action_id =: assignment_action_id

    AND ppa.payroll_action_id = paa.payroll_action_id

    AND ppa.payroll_id = pp.payroll_id

    AND paa.assignment_action_id = prr.assignment_action_id

    AND prr.run_result_id = prrv.run_result_id

    AND prrv.input_value_id = piv.input_value_id

    AND piv.element_type_id = pet.element_type_id

    AND paaf.assignment_id = paa.assignment_id

    AND paaf.person_id = papf.person_id

    AND trunc (sysdate) BETWEEN pp.effective_start_date AND pp.effective_end_date

    AND trunc (sysdate) BETWEEN pet.effective_start_date AND pet.effective_end_date

    AND trunc (sysdate) BETWEEN piv.effective_start_date AND piv.effective_end_date

    AND trunc (sysdate) BETWEEN paaf.effective_start_date AND paaf.effective_end_date

    AND trunc (sysdate) BETWEEN papf.effective_start_date AND papf.effective_end_date

    AND pet.element_name IN ('local Mission allowance', 'International Mission'))

    GROUP BY employee_number

    element_name

    run_result_id

    ;

    You should get your desired result.

    Roger

  • How to do a validation based on the SQL query?

    Hello

    I have a requirement to perform a validation on a field (messageTextinput) in my page OAF.

    When I click the button apply, the value in this field is validated based on a SQL query (for example, the value in the field NOT IN (value1 select from table1).)

    Help, please.

    Best regards

    Joe

    1. create a SQL query based VO, XXVO. For example:-SQL query is select xx_table;

    2. Enter the "Apply" button click event in the controller and run the AM method passing the value entered by the user in the given field, for example:-value is VAL1

    3. in the method of the AM, get a handle of the VO, the whereClause and run.

    OAViewObjectImpl vo = findViewObject ("XXVO1"); XXVO1 is the name of the instance of the VO above, XXVO

    vo.executeEmptyRowSet ();

    vo.setWhereClause (null);

    vo.setWhereClause ("value =" + VAL1 + "'");

    vo.executeQuery ();

    If (VO. GetRowCount() > 0)

    A record is with the value of VAL1. Perform the required action

    I hope this helps.

  • How to pass the values separated by commas in SQL query

    Hi all

    I use Oracle APEX 4.2

    I've created a report of iterative with condition 1 ITEM IS NOT NULL.

    This is the SQL query

    SELECT MY. ACCT_ID,

    JAI DETAILS

    The ACCT MA, ACCT_hist EB

    WHERE MY. ACCT_IK = EB. ACCT_IK

    AND MY. ACCT_ID IN (: P3_IN_MRN);

    A P3_IN_MRN element is a text field. The thing is that it works if I give a value, but its does not work if I have several values with comma separated as 123,345,543.

    What could be the solution for multiple values in the SELECT query.

    Really appreciate your help.

    I made use of this on pretty much every project I've worked on:

    https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:210612357425

    Hope that helps.

    Duncs

  • SQL query + html

    Hello

    I have a test_table (col1, col2, col3) on apex.oracle.com.

    First of all:

    I would like to create report as the type of SQL query:

    Select col1, col2, col3 from test_table;

    I want to change the properties of the col2 for example the font or color during the generation.

    I have to write in the report source code (this is only an example?):

    Select col1,

    "< span style =" ' make-weight: bold; ' > ' col2 "</span >", "

    COL3

    from test_table;

    I think it's wrong, but I would like to know what are the first principles of the connection between sql and html.

    Second:

    I create the report in the body of type SQL query return PLSQL function:

    Start

    return "select col1.

    || "< span style =" ' make-weight: bold; ">" | 'col2' | ' </span >', "

    ||' COL3

    from test_table;';

    end;

    What is the problem in the two examples? I can't find it in the documentation. Could you tell me something about the principles.

    Concerning

    Ziut

    Hello

    One way is to query as

    select col1,
    col2,
    col3,
    case when col1 = 'XXX' then
     'bold'
    else
     'normal'
    end as fontweight
    from test_table;
    

    Column of FONTWEIGHT set as hidden.

    Then place the COL2 HTML expression

    #COL2#
    

    Kind regards

    Jari

  • Use the DECODE and RIGHTEOUS in the sql query

    Friends...

    Could someone help with DECODE and sql RIGHT or similar function?

    I'm doing below in the SQL query

    1. DECODE any process with s.process = 1234 to replace with JAVA
    2. RIGHT: Removes all characters after ' @' sign

    SQL query:

    SELECT s.osuser, s.machine, DECODE(s.process, '1234', 'JAVA', right(s.process,charindex('@',s.process)-1)) s.process FROM v$session; 

    for example

    EXAMPLES of data

    User, machine, process

    John, mac1, 1234

    Mike, mac2, 567@mac2

    Julie, mac3, 890


    The result of the SAMPLE:

    User, machine, process

    John, mac1, JAVA

    Mike, mac2, 567

    Julie, mac3, 890

    Thanks in advance

    Thanks guys... I am overwhelmed with all these answers and support on this forum, I received...

    I have combined Solomon and Frank response to achieve accurate result...

    with the answers of Solomon he displayed empty process when there is ' @' sign

    Frank's response showed it process with sign @ the end... so I added '-1' in the end.»

    SELECT s.osuser,

    s.machine,

    DECODE)

    s.Process,

    "1234", "JAVA",

    substr)

    s.Process,

    1,

    InStr)

    s.Process | '@',

    '@'

    ) - 1

    )

    ) process

    V $ session s

    /

  • SQL query problem - (internal has not managed to the outer query)

    Hi all:

    Here is my SQL query:
    SELECT RD.SITE,
      ROUND(
      (SELECT COUNT (DISTINCT PB.EMP_ID)
      FROM BOOK PB
      WHERE PB.EMP_ID IN
        (SELECT PB.EMP_ID FROM BOOK PB
        )
      ) /
      (SELECT COUNT (DISTINCT PB.EMP_ID)
      FROM BOOK PB
      WHERE PB.EMP_ID IN
        (SELECT PB.EMP_ID FROM BOOK PB
    WHERE MO.QUALIFIER > 4
        )
      )* 100, 2) AS PERCENTAGE
    FROM BOOK PB
    LEFT JOIN POSITION MO
    ON PB.EMP_ID = PO.EMP_ID
    INNER JOIN PHYS_LOCATION RD
    ON MO.HOUSED         = RD.SITE_ID
    WHERE MO.ACTUAL_END IS NULL
    GROUP BY RD.SITE;
    Why am I the overall percentage of all Sites as opposed to each percentage calculation for each site. I've grouped by Rd. SITE, so I assume he would calculate the percentages for each site. What I've done wrong?

    Thank you for your help.

    AquaNX4 wrote:
    Hi all:

    Here is my SQL query:

    SELECT RD.SITE,
    ROUND(
    (SELECT COUNT (DISTINCT PB.EMP_ID)
    FROM BOOK PB
    WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    )
    ) /
    (SELECT COUNT (DISTINCT PB.EMP_ID)
    FROM BOOK PB
    WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    WHERE MO.QUALIFIER > 4
    )
    )* 100, 2) AS PERCENTAGE
    FROM BOOK PB
    LEFT JOIN POSITION MO
    ON PB.EMP_ID = PO.EMP_ID
    INNER JOIN PHYS_LOCATION RD
    ON MO.HOUSED         = RD.SITE_ID
    WHERE MO.ACTUAL_END IS NULL
    GROUP BY RD.SITE;
    

    Why am I the overall percentage of all Sites as opposed to each percentage calculation for each site. I've grouped by Rd. SITE, so I assume he would calculate the percentages for each site. What I've done wrong?

    It's what you're asking. Your subquery scalar to get the percentage is not restricted by the current site. Add columns to filter to restrict the values selected for the calculation

    Published by: riedelme on May 8, 2013 07:26

  • SQL Query to retrieve records for all after the Max Dates.

    Hello everyone,

    I am trying to retrieve the record more recent, based on the date field ( nextDate ).

    Currently, there are only 4 records in the MC_Maintenance table and two in the Machine table.

    Machine table

    MC_id             EquipID          

    1                      0227

    MC_id EquipID

    2                     0228

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

    MC_Maintenance table

    Maint_id MC_id Next_maint

    1                      2                      08/25/2010     

    2                      2                      07/01/2010

    3                      1                      2010-11-06

    4                      1                      07/11/2010

    I have am trying to accomplish is,.

    the list of the two machines of the table of the Machine with the MAX (Next_maint) control the list of MC_Maintenance results

    These are the records I want to display.

    Maint_id MC_id Next_maint

    1                      2                      08/25/2010

    4                      1                      07/11/2010                 

    Here is the SQL query

    SELECT

           MC. MC_ID as ID,

    MC.complete_Date completed.

    MC.next_maint as nextDate,.

    MC.maint_notes as noted,.

    MC.facility Facility.

    M.EquipId,.

    $m.name as the name.

    M.SerialNumber SN.

    M.dept as dept.

    M.Freq as freq

    Of MC_Maintenance MC, Machine M

            where  MC. MC_ID = M.MC_ID

    '           Using MAX (nextDate)

    Any ideas would be useful.

    TJ

    I thought it was a simple group of problem?

    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID
    
  • IF NEW VARIABLE in SQL QUERY, DISPLAYS as the LAST COLUMN + rpad does not

    Hello all and thanks in advance.


    (1) if I add a new variable to my sql query to select a column, which was already on the table, it shows it in the report of the table as the last column on the right. In other words, if I add "the street" to

    something like city, postal code, street, store, Manager, etc., instead of placing the Street between CP and the Bank, the place like I said as the last column on the right.


    (2) when the values entered in the cells of the tables, Yes, they extend to their length, but, only if it is a Word. If it is two, as when I enter the value of 'very good '.

    then two lines as well as by a newline within the cell, for example, which in fact too high the rank. I tried sdap spaces with rpad but this did not work. something like rpad (stock, 20,' ')

    I have to say that the table is in the same page where there is a form, as the table grows in length it's actually squeezing the form on the left.


    (3) rpad did not work with the simpler syntax, but less would be with what I need, because it turns out that I am using DECODE to perform a conversion between the displayed value and

    value returned in my select list of values, something like: DECODE (TO_CHAR (stock), '1', 'Black', '2', 'Average', '3', 'good', '4', 'Very good', null) AS stock

    so, I tried to put the rpad there in several places, but either he gave the parse error or it has left empty do not pick up all the values in the column.


    Thank you very much

    Alvaro

    Alvaro

    (1) this is the standard behavior of the constructor of the apex. You can change the order of display with arrows in the report column attributes.

    (2) you have to play with the style of the column attributes to accomplice this. For the style of the instance = "" white-space: pre; ' in the attributes of the element column attributes. " White-space: normal would be put on several space (' ') 1. So no matter how you add with rpad, they will display as 1.
    Set a width or as attribute in a class style for this column.

    Nicolette

  • How can I find out whether a patch applied to the sql query

    How can I find out whether a patch applied to the sql query

    Select * from ad_bugs where numero_de_bogue = '';

    HTH
    Srini

  • Eliminate the duplicate based on the condtion in Select of SQL query.

    Hi all

    I write the SQL query where I have to select values based on the condition in the column.

    Lets say I have 3 columns position, description, used, there are different values in the position but for some positions of the column description of the lines is the same and if column Description is the same and employee is null then that there should be only one row returned and if the description is the same but the employee column is not null then it should be several lines.

    I can't use Group by that we have around 35 columns in the select query.

    Please suggest any Solution.

    Hi Michael,

    I adds a column to the t2 to get the good understanding of my needs.

    Level
    Employee From Date to_date
    1 Test2 21.03.2014 21.04.2014
    2 Test4 21.02.2014 20.03.2014
    2 Test1 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    3 MgrTest 21.03.2014

    Now, the result should look like this.

    Level
    Employee From Date TO Date
    1 Test2 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    2 Test1 21.03.2014 21.04.2014
    3 Mgrtes 21.03.2014
    4

    There was an addition more as if this day is not null for the given level, then the query must return a single line of balnk more with the same position, I am reached using any Union and works very well I'm stuck with the point above.

  • Select SQL query

    Hello

    I have a table named demo with two columns (name brands), as shown below

    Name brands
    A 80
    B 100
    C 96
    I need a Select SQL query that returns the result as shown below

    Name brands
    A 276
    B 276
    C 276

    Brands of column must contain the sum of all the brands of the table against each of the name of the table. (Not necessarily with the same columns as the demo table names) This result should not be stored in the table and I need it just for display purpose.

    Published by: 944160 on May 30, 2013 05:28

    Try this

    select
    name,
    sum(marks) over () marks
    from
    demo
    

Maybe you are looking for

  • Camileo Pro Max resolution D1 or VGA?

    Hello I'm confused with the specs of the resolution of the Camileo Pro. All the specifications of product, description and announcements like max resolution VGA (640 x 480). However, the manual claims resolution (720 x 480) D1 max. Which is correct?

  • Satellite A300 - 1 9 PSAJ4E unable to use 2 multimedia keys

    Hello After that I reinstalled win7 64 bit on my SSD I'm unable to use my 2 first multimedia buttons (mute, cd/DVD).I am also unable to save them because there are not not in the program of buttonsupport! Here is a picture of the problem http://img20

  • Pavilion g7-2323 mot_passe_administrateur

    I have a pavilion g7-2323 his request for administrator or power on password

  • 360 WRT54G wireless game adapter and xbox

    First post here and I have a problem. The WRT54G has disabled wirlelss. It is connected to a WAP11B wireless access point that is connected in 802. 11B mode for a laptop, Wii, xbox 360, iPhone. The router is connected to a dsl modem. Three wired ethe

  • Free alternative IDE for development Playbook?

    Hello does anyone know any good alternative IDEs for development of Blackberry Playbook? I guess the requirements I'm looking for is the following: + Support ActionScript 3 + Easy run to the device (via IP address) + Blackberry Playbook SDK support?