Help in the Sql query

Hi all

I have a requirement to get all the items contained in the link of the item for the two States of 2 payroll.

I also want to recover what elements exist only in unique payroll.

Case 1: Item exists in both States to pay.

Case 2: Item exists in only one of the payroll.

Item: XX_ELEMENT

Element_id = 140

Payroll_id 1 = 40

payroll_id 2 = 50

Example table:

element_id Payroll_id

140                    40

140                    50

140                    60

141                    40

Desired output:

Element on the payroll

140 40,50 (or ' the two States of payroll)

141                    40

Here is the code I am trying.

SELECT DISTINCT

LINK. PAYROLL_ID,

PAF. PAYROLL_NAME,

ELEMENT_LINK_ID,

PF. ELEMENT_TYPE_ID,

LINK. LINK_TO_ALL_PAYROLLS_FLAG,--IN('Y','N')

PTL. ELEMENT_NAME ARABIC,

PF. ELEMENT_NAME ENGLISH

LINK PAY_ELEMENT_LINKS_F,

PAY_ELEMENT_TYPES_F_TL PTL,

PAY_ELEMENT_TYPES_F PF,

PAF PAY_ALL_PAYROLLS_F

WHERE PF. ELEMENT_TYPE_ID = 140 AND

PAF. PAYROLL_ID (+) IS LINK. PAYROLL_ID

AND PF. ELEMENT_TYPE_ID = PTL. ELEMENT_TYPE_ID

AND PF. ELEMENT_TYPE_ID (+) IS LINK. ELEMENT_TYPE_ID

AND THE PTL. LANGUAGE = "AR".

AND TRUNC (SYSDATE) BETWEEN PF. EFFECTIVE_START_DATE AND PF. EFFECTIVE_END_DATE

AND (TRUNC (SYSDATE) BETWEEN PAF. EFFECTIVE_START_DATE AND OF THE PAF. EFFECTIVE_END_DATE OR LINK. PAYROLL_ID IS NULL)

AND TRUNC (SYSDATE) BETWEEN LINK. EFFECTIVE_START_DATE AND LINK. EFFECTIVE_END_DATE

AND THE LINK. PAYROLL_ID IN (40,50)

Kind regards

Afzal.

Once you have your set of element_id and payroll_id you can use count (distinct) to get the number of different values of payroll_id by element_id. Something like

Select element_id, count (distinct payroll_id) cnt, max (payroll_id) max_pr the subquery by element_id group

You can then use a decoding against the column of the cnt to display 'two' or max_pr.

You haven't posted your version of Oracle, but if you are on at least 11.2.0.1 then you can also use listagg on the separate set of element_id and payroll_id

Tags: Database

Similar Questions

  • 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

  • Help of the SQL query.

    Hello

    It's my first table REPORT

    report as)
    Select 'vendor_1' vendor, to_date('1/1/2012','DD/MM/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 110 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 120 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 130 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/4/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 140 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/10/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" element, 200as cost of double union all
    Select 'vendor_1' vendor, to_date('1/23/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" as point 0 as the cost of dual union all
    Select 'vendor_1' vendor, to_date('1/6/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 160 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/7/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 170 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/8/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 180 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/9/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 190 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/20/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 300 as cost of double)






    IT'S MY SECOND TABLE: TEMP_WEEK

    WITH temp_week (s)
    SELECT January 1, 2012 to 07/01/2012 ' AS the week of all the double union
    SELECT August 1, 2012 to 14/01/2012 ' AS the week of all the double union
    January 15, 2012 to 21/01/2012 ' AS the week of all the double union
    SELECT January 22, 2012 to 28/01/2012 ' AS the week of all the double union
    (SELECT 29 January 2012 to 31/01/2012 ' WEEK of double)


    To find weekly sales that I wrote query below:

    SELECT week, supplier, customer, SUM (cost)
    (SELECT week, supplier, customer, TOTAL costs (cost)
    FROM (SELECT BOX
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
    January 1, 2012 to 07/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
    14/01/2012, 1 August 2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    January 15, 2012 to 21/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
    January 22, 2012 to 28/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
    29 January 2012 to 31/01/2012 '
    END
    week, supplier, customer, cost
    REPORT)
    GROUP BY week, supplier, customer
    UNION ALL
    SELECT tw.week, vendor, customer or 0
    (SELECT week, supplier, customer, TOTAL costs (cost)
    FROM (SELECT BOX
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
    January 1, 2012 to 07/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
    14/01/2012, 1 August 2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    January 15, 2012 to 21/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
    January 22, 2012 to 28/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
    29 January 2012 to 31/01/2012 '
    END
    week, supplier, customer, cost
    REPORT)
    GROUP BY week, supplier, customer), temp_week tw)
    GROUP BY week, supplier, customer
    ORDER BY supplier, customer, week;


    with above query I get below output:


    with output voltage)
    Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 500 as cost of double union all
    Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 200 as cost of double union all
    Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
    Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
    Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
    Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 330 as costs of double union all
    Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 370 as cost of double union all
    Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 300 as cost of double union all
    Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 0 as the cost of dual union all
    Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, double cost of 0)

    Clearly, I used cross join. But I want to get the same result with another way. I don't want to use cross join and Union

    Please help me in this.

    What you desire can be accomplished using the outer join partitioned.
    The documentation shows an example of [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2177515] this way to fill the gaps in the data.

    Here's how you can use it in your case:

    SQL> with report as (
      2     select 'vendor_1' as vendor,to_date('1/1/2012','DD/MM/YYYY') supply_date, 'customer_1'as customer,'item_1' as item1, 110 as
    cost from dual union all
      3     select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,120 as c
    ost from dual union all
      4     select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item1,130 as
    cost from dual union all
      5     select 'vendor_1' as vendor,to_date('1/4/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,140 as c
    ost from dual union all
      6     select 'vendor_1' as vendor,to_date('1/10/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item ,200as
    cost from dual union all
      7     select 'vendor_1' as vendor,to_date('1/23/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item,0 as co
    st from dual union all
      8     select 'vendor_1' as vendor,to_date('1/6/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,160 as c
    ost from dual union all
      9     select 'vendor_1' as vendor,to_date('1/7/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,170 as c
    ost from dual union all
     10     select 'vendor_1' as vendor,to_date('1/8/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,180 as c
    ost from dual union all
     11     select 'vendor_1' as vendor,to_date('1/9/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,190 as co
    st from dual union all
     12     select 'vendor_1' as vendor,to_date('1/20/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,300 as c
    ost from dual
     13  ), weeks as (
     14     select to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 week_start
     15          , to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 + 6 week_end
     16          , level week_pseudo_id
     17       from dual
     18     connect by level <= 5 /* substitute desired number of weeks */
     19  )
     20  --
     21  -- end-of-test-data
     22  --
     23  select to_char(max(weeks.week_start),'DD/MM/YYYY')
     24         || ' to ' ||
     25         to_char(max(weeks.week_end),'DD/MM/YYYY') week
     26       , vendor
     27       , customer
     28       , nvl(sum(cost),0) cost
     29    from report
     30   partition by (vendor, customer)
     31   right outer join weeks
     32         on weeks.week_start <= report.supply_date
     33         and weeks.week_end >= report.supply_date
     34   group by
     35         vendor
     36       , customer
     37       , week_pseudo_id
     38   order by
     39         vendor
     40       , customer
     41       , week_pseudo_id
     42  /
    
    WEEK                     VENDOR   CUSTOMER         COST
    ------------------------ -------- ---------- ----------
    01/01/2012 to 07/01/2012 vendor_1 customer_1        500
    08/01/2012 to 14/01/2012 vendor_1 customer_1        200
    15/01/2012 to 21/01/2012 vendor_1 customer_1          0
    22/01/2012 to 28/01/2012 vendor_1 customer_1          0
    29/01/2012 to 04/02/2012 vendor_1 customer_1          0
    01/01/2012 to 07/01/2012 vendor_1 customer_2        330
    08/01/2012 to 14/01/2012 vendor_1 customer_2        370
    15/01/2012 to 21/01/2012 vendor_1 customer_2        300
    22/01/2012 to 28/01/2012 vendor_1 customer_2          0
    29/01/2012 to 04/02/2012 vendor_1 customer_2          0
    
    10 rows selected.
    

    I have redesigned weeks of date columns for the join which will probably perform better and can possibly use indexes.
    I assume that you have no time portion in your supply_date data? If you do, then week_end will need to be modified.

  • Help to the SQL query.

    I have a table 'departments' with the following fields:
    dep_id, parent_dep_id.
    1 5
    2
    3 4
    4
    5 2

    How can I write SQL to return the department (division) parent of higher level for each Department:
    dep_id, div_id
    1 2
    2 2
    3 4
    4 4
    5 2

    Thank you.
    SQL> create table t (dep_id,parent_dep_id)
      2  as
      3  select 1, 5 from dual union all
      4  select 2, null from dual union all
      5  select 3, 4 from dual union all
      6  select 4, null from dual union all
      7  select 5, 2 from dual
      8  /
    
    Tabel is aangemaakt.
    
    SQL>  select dep_id
      2        , max(connect_by_root dep_id) keep (dense_rank last order by level) div_id
      3     from t
      4  connect by prior dep_id = parent_dep_id
      5    group by dep_id
      6  /
    
        DEP_ID     DIV_ID
    ---------- ----------
             1          2
             2          2
             3          4
             4          4
             5          2
    
    5 rijen zijn geselecteerd.
    

    Kind regards
    Rob.

  • Help with making SQL query references to column aliases in the Case statement

    I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:


    SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,

    CASE
    WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
    WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
    WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
    WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
    WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
    WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
    WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
    WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
    WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
    WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
    END acg_elig_comm_code

    CASE
    WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
    WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
    WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
    END comm_code_description

    OF spriden, rcresar, rcrapp1

    WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')

    OR rcresar_comm_code_02 ('268 ', '269', ' 270')

    OR rcresar_comm_code_03 ('268 ', '269', ' 270')

    OR rcresar_comm_code_04 ('268 ', '269', ' 270')

    OR rcresar_comm_code_05 ('268 ', '269', ' 270')

    OR rcresar_comm_code_06 ('268 ', '269', ' 270')

    OR rcresar_comm_code_07 ('268 ', '269', ' 270')

    OR rcresar_comm_code_08 ('268 ', '269', ' 270')

    OR rcresar_comm_code_09 ('268 ', '269', ' 270')

    OR rcresar_comm_code_10 ('268 ', '269', ' 270'))


    Rcresar_aidy_code = & aidy_code

    AND rcrapp1_aidy_code = rcresar_aidy_code

    AND rcrapp1_curr_rec_ind = 'Y '.

    AND rcrapp1_seq_no = rcresar_seq_no


    AND spriden_pidm = rcresar_pidm

    AND rcrapp1_pidm = rcresar_pidm


    AND spriden_change_ind IS NULL

    ORDER BY name


    The second case statement is where I don't know exactly what it takes to get what I want.

    Output should be like:
    spriden_pidm name ID acg_elig_comm_code comm_code_description
    «0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»

    If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.

    Published by: blackhole82 on January 20, 2009 09:20

    Hello

    You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
    You can set the alias in a subquery and then use it in a great query, like this:

    WITH  sub_q  AS
    (
        SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name,
            CASE
                WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01
                WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02
                WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03
                WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04
                WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05
                WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06
                WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07
                WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08
                WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09
                WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10
            END acg_elig_comm_code   -- Originally posted with , here (error)
        FROM spriden, rcresar, rcrapp1
        WHERE (rcresar_comm_code_01 IN ('268','269','270')
                OR rcresar_comm_code_02 IN ('268','269','270')
                OR rcresar_comm_code_03 IN ('268','269','270')
                OR rcresar_comm_code_04 IN ('268','269','270')
                OR rcresar_comm_code_05 IN ('268','269','270')
                OR rcresar_comm_code_06 IN ('268','269','270')
                OR rcresar_comm_code_07 IN ('268','269','270')
                OR rcresar_comm_code_08 IN ('268','269','270')
                OR rcresar_comm_code_09 IN ('268','269','270')
                OR rcresar_comm_code_10 IN ('268','269','270'))
        AND rcresar_aidy_code = &aidy_code
        AND rcrapp1_aidy_code = rcresar_aidy_code
        AND rcrapp1_curr_rec_ind = 'Y'
        AND rcrapp1_seq_no = rcresar_seq_no
        AND spriden_pidm = rcresar_pidm
        AND rcrapp1_pidm = rcresar_pidm
        AND spriden_change_ind IS NULL
    )
    SELECT    sub_q.*,
              CASE
                  WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course'
                  WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB'
                  WHEN acg_elig_comm_code = '270' THEN 'ACG possible'
              END comm_code_description
    FROM      sub_q
    ORDER BY  name
    

    Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.

    Published by: Frank Kulash, January 20, 2009 11:35
    Syntax error has been corrected

  • Please help build a sql query

    Hello

    Please help build a sql query


    My Table Test2015 has given below

    Header_id Line_id Ordered_item       

    723887290 199925 MAIN1

    199925 723887291 MAIN2

    199926 723887292 SH-POS-NO-BR POS-INS

    199926 723887293 MAIN2

    199927 723887294 IC-ENV-NON-BR-ENV-PXY

    199927 723887295 MAIN1

    199927 723887297 MAIN2

    199927 723887298 PRCSS SH-FAIRY-ELEC DISTR.

    199927 723887299 SH-FAIRY-SUM PRO-DE-CONS-HOUSE

    I am trying to query my Test2015 table to obtain the records with ordered_item containing 'MAIN1' and 'MAIN2' only. I tried to write a query as below

    SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1', 'MAIN2');

    But it gives me all the data with the MAIN2 records found but MAIN1 is absent, I want to retrieve only records to both 'MAIN1' and 'MAIN2' present for Header_id.

    While the result below shows me header_id - 199926 and 199929 that he should assume back. I want to fetch documents only with 'MAIN1' and 'MAIN2' both present.

    Header_id Line_id Ordered_item            

    723887290 199925 MAIN1

    199925 723887291 MAIN2

    199926 723887293 MAIN2

    199927 723887295 MAIN1

    199927 723887297 MAIN2

    199929 723887299 MAIN1

    Please suggest.

    Thank you and best regards,

    Prasad.

    Hello

    Try like this...

    SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1") and in header_id (select test2015 WHERE ORDERED_ITEM in ('MAIN2') header_id)

  • Need help with a SQL query

    Hello

    I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)

    Primary_ID raj_id Raj_number Raj_format

    1                            raj                 rajvend                      1

    2                            raj                 rajvend                      1

    3                            raj                 rajvendor1                 2

    4                            raj                 rajvendor1                 2

    5                            raj                 rajvendor1                 2

    6                            raj                 rajvendor2                 3

    I used under SQL to get query output as below, but has not achieved the required result:

    Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)

    from raj_table by sl_no asc

    SL_NO raj_id raj_number raj_format primary_id

    1                   1                   raj              rajvendor                 1

    1                   2                  raj              rajvendor                 1

    2                   3                   raj              rajvendor1                2

    2                   4                   raj              rajvendor1                2

    2                   5                  raj               rajvendor1                2

    3                   6                    raj              rajvendor2                3

    I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.

    with t as)

    Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the

    Select option 2, 'raj', 'rajvend', 1 double Union all

    Select 3, 'raj', 'rajvendor1', 2 double Union all

    Select 4, 'raj', 'rajvendor1', 2 double Union all

    Select 5, 'raj', 'rajvendor1', 2 double Union all

    Select 6, 'raj', 'rajvendor2', 3 double

    )

    Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,

    t.*

    t

    order by primary_id

    /

    PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
    ---------- ---------- --- ---------- ----------
    1 1 raj rajvend 1
    1 2 raj rajvend 1
    2 3 raj rajvendor1 2
    2 4 raj rajvendor1 2
    2 5 raj rajvendor1 2
    3 6 raj rajvendor2 3

    6 selected lines.

    SQL >

    SY.

  • 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

    /

  • Cannot create the SQL query view object

    I'm having a lot of trouble to create a display of a SQL object.

    The query is as follows:

    Select CalBruker.BRUK_ID,
    CalBruker.EMAIL,
    CalBruker.ETTERNAVN,
    CalBruker.PASSORD,
    CalBruker.DATO_OPPRETTET,
    CalBruker.AKTIV,
    CalBruker.FORNAVN,
    CalBruker.ROLL_ROLL_ID,
    CalBruker.AVDE_AVDE_ID,
    CalRoller.NAVN,
    CalRoller.ROLL_ID,
    CalAvdelinger.NAVN AS NAVN1,
    CalAvdelinger.AVDE_ID,
    CalRoller.BESKRIVELSE,
    CalForlag.NAVN AS NAVN2,
    CalForlag.FORL_ID,
    CalAvdelinger.navn,
    CalForlag.navn AS BrukForlag,
    CalBruker.FRIEKS_PROSENT_GRENSE,
    CalBruker.LOGIN_NAVN
    Of CAL_BRUKER CalBruker, CAL_ROLLER CalRoller, CAL_AVDELINGER CalAvdelinger, CAL_FORLAG CalForlag
    Where CalBruker.ROLL_ROLL_ID = CalRoller.ROLL_ID AND CalBruker.AVDE_AVDE_ID = CalAvdelinger.AVDE_ID AND CalAvdelinger.FORL_FORL_ID = CalForlag.FORL_ID


    If I create a new view object and paste the SQL query in there, I get no automatic attribute mappings, and I can't understand how I'm supposed to map the attributes manually.

    Basically, I get a display without her attributes object.

    JDeveloper version 11.1.2.0

    Help if you give alias names in your columns?
    Something like:

    Select CalBruker.BRUK_ID BRUK_ID,
    EMAIL CalBruker.EMAIL,
    CalBruker.ETTERNAVN ETTERNAVN,
    ...

  • What can be the SQL query for this requirement?

    Hello
    I have a table with the fields like this:

    ID DESC PARENT
    01 02 ABC
    02 01 ABC1
    03 01 ABC2
    04 02 ABC4


    In the table above column PARENT refers to the column ID, but actually in the SQL query, I want to have ID DESC and PARENTDESC (i.e., desc ID value corresponding)

    Output real I need is

    SELECT ID, DESC? from table where ID = someValue. Now, if I provided ID = 01 then output should be like this:

    ID DESC PARDESC
    ABC1 ABC 01


    Can anyone help on what may be the required sql query?

    Published by: bootstrap on April 29, 2011 06:15

    SELECT T1.ID, T1. DESC, T2. / / DESC
    FROM TABLEA T1, T2 TABLEA
    WHERE T1.ID = '01'
    AND T2.ID = T1. PARENT;

  • Help me with SQL Query to retrieve data from a view

    Hello Guru,

    I need help in my sql query.
    I use SQL TeraData.
    I want an Oracle result in the following form-

    Open tickets
    Open months failure / Repair Service s/o improvement request Total general
    2009-01-2 4 4 5 15
    2009-02 1 0 2 3 6
    2009-03 4 1 2 2 9
    Grand Total 7 5 8 10 30


    I wrote the query as where - TIME_PERIOD, RQST_TYPE_DM and DEMAND_SUMMARY_FCT are the points of view and I extract the data from the views only.

    Select NVL (CA. TIME_PERIOD. PERIOD_CD, 'Total') THAT year.
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% of Break' THEN 1 END) as BreakFix
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'N/a', 1 END) by n/a
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'Improvement' THEN 1 END) accessories
    COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% Service' THEN 1 END) as ServiceRequests
    COUNT (CA. RQST_TYPE_DM. RQSTTYP_DESC) AS grand_total
    FROM CA. TIME_PERIOD, CA. RQST_TYPE_DM, CA. DEMAND_SUMMARY_FCT
    WHERE (CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = CA. RQST_TYPE_DM. RQSTTYP_ID)
    AND (CASE
    WHEN CA. DEMAND_SUMMARY_FCT. MONTH_ID = CA. TIME_PERIOD. PERIOD_ID, 1
    WHEN {fn concat ({fn concat (SUBSTR (CA. TIME_PERIOD. {(PERIOD_CD, 3, 4),'-')}, SUBSTR (CA. TIME_PERIOD. PERIOD_CD, 7, 2))} BETWEEN ' 2009-01' AND ' 2009-03' THEN 1
    WHEN CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = '1' then 1
    END) = 1
    GROUP BY ROLLUP (CA. TIME_PERIOD. PERIOD_CD)

    After executing the query, I get the following error:
    3076: syntax Error: Data Type 'Time' does not match a defined Type name.
    :( Kindly help me with this and let me know where I'm wrong... Please.

    Messages indicates something wrong with your data... It would seem that the data does not match your format mask.

    Thus, the data or the format mask.

  • Failed to parse the SQL query by user

    Hi all

    in my application, I have a piece of text with a button "submit". In this article, I type a name and a report after the element region show me the result (s). This works for all my users (> 2000) perfectly, but that users become an error in the area of the report:

    Failed to parse the SQL query:
    ORA-01403: no data found

    We try this with the same searchstring on the same computer/browser. If I connected the result is ok, if the logged on user, the error message appears. If I try this on the user's computer with me connected, ok result. If the user try this on another pc, error results.

    I have a production and a developer workspace. In the developer workspace the user can try this perfectly without errors. That in the space of productive work, clear the error.

    The SQL-Select in the ist verry simple reprirt:

    Select id
    name
    raum
    table
    where instr (upper (name), upper (:P60_SEARCH)) > 0

    However, all users can use this search box with report perfectly, only this one user has the error. There is no restrictions on this point or a State.

    Can someone help me?

    Hi Carsten,

    I don't think that there is a way to do it.

    Could you please mark the correct and useful answers in this thread? Otherwise I'll never get near Andy ;) :)

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • Classic report shows wrong "could not parse the SQL query: ORA-00942" error after migrating app to the new environment

    After migrating my APEX 4.1 application to a new environment, one classic report displays a "cannot parse the SQL query: ORA-00942: table or view does not exist" error when the page is displayed. Change the region to report SQL source to somehow (e.g., remove spaces, changing the order of the variables in the WHERE clause) immediately solves the problem, but by returning to the source of the region causes the report error again (the source region valid code without error, however).

    Throw the error message:

    Select v.id,

    v.Col1

    of view_vw v

    where (: P1_FILTER is null or)

    v.col2 = :P1_FILTER)

    Do not throw error:

    Select v.id,

    v.Col1

    of view_vw v

    where (:P1_FILTER is null or)

    v.col2 = :P1_FILTER)

    Changing the order of column in the report has the same effect; i.e. He arranges, but return back to the original column order causes the error to display.

    It's as if a cached result for the correct select statement used by the report is displayed. However, the application does not use the caching of page/region. Any ideas of what could be the cause?

    He solved. Ultimately, all that was necessary was to clear the DB cache using:

    alter system flush shared_pool;

  • Table error ' can not analyze the SQL query!

    Hi all

    I created a view on my database called VIEW_MEMBER_PARTIC_PROJECTS

    If I run a query showing the results of the view:

    SELECT * FROM VIEW_MEMBER_PARTIC_PROJECTS

    I get the following data

    ProjectsParticipants
    131 S
    241
    319
    43
    53
    61
    72

    Now, I wanted to represent this diagram in the APEX so I created a graphic region and entered the Source query generator and the manufacturer produces the following code

    Select null, label projects, value1 Participant link

    of "SCHEMANAME." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    With this code, I get an error:

    Cannot parse the SQL query!

    Select the link null, label projects, value1 "SCHEMANAME Participant." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    Some queries can be run when you run your application, if your query is syntactically correct, you can save your query without validation (see options below the source of the query).

    The code looks OK, but I do not see to save options as the error code is mentioned.

    No one knows how to fix this?

    Thank you

    JaReg wrote:

    I finally found the problem.

    I looked at the code for the view and changed the start of:

    CREATE OR REPLACE FORCE EDITIONABLE VIEW "SCHEMANAME." "" VIEW_MEMBER_PARTIC_PROJECTS "("Participant","Projects")

    AS

    TO

    CREATE OR REPLACE VIEW "SCHEMANAME." "" VIEW_REPEAT_PARATIC ".

    AS

    And that seemed to fix it. I'm not entirely sure why though.

    The view was created using the quoted identifiers for column names. This makes them sensitive and means that they must always be referenced using double quotes. In the absence of quotation marks, Oracle is not case insensitive and automatically converts all uppercase identifiers. The application of graph:

    Select the link null, label projects, value1 "SCHEMANAME Participant." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    has therefore been interpreted by Oracle:

    SELECT THE LINK NULL, LABEL, VALUE1 "SCHEMANAME PARTICIPANT PROJECTS." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    and PROJECTS and PARTICIPANT columns were not recognized because the columns defined for the view have been 'Participant' and 'projects '. The graphic request should have been:

    Select the link null, the label of "Projects", "Participant" value1 "SCHEMANAME." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    As you have now discovered, quoted identifiers are a source of nothing but obscure bugs and should never be used for database objects. He also pointed out the reason why you should always use a standardized, form tiny, coding style as it is faster to type, easy to read and less prone to errors.

  • Export as .xls. Classic report type: SQL (body of function from PL/SQL returning the SQL) query

    Hey guys,.

    I'm using version 4.2.6 apex. The theme is 26.

    IM also using Listener Oracle APEX.

    I can print my classic report in PDF or CSV format.

    But I need to export it as a .xls extension.

    Report type: SQL (body of function from PL/SQL returning the SQL) query

    I need is like this cause my 'where' clause type is dynamic.

    Look at using this method: Tom's Blog: a non-standard export excel 2010 (.xlsx)

    I do something similar for downloads to excel in my projects...

    Thank you

    Tony Miller
    Software LuvMuffin
    Ruckersville, WILL

Maybe you are looking for