Help in the Search Condition in the SQL query

Hi gurus,

I had the table with 3 columns
col1           col2             col3
123        johns123     edwin321s
seenu       janu      satya123reset
3456       kris         123stest

In single SQL query i want to print the value based on the '123' is  

123,john123,
satya123reset,
123test

or to print the records starts with 's' like 
s123
seenu,satya123reset
stest
Thanks in advance

Published by: SeenuGuddu on October 15, 2009 21:55

Published by: SeenuGuddu on October 15, 2009 21:55

Published by: SeenuGuddu on October 15, 2009 22:07

Hello

Not sure you mean exactly, but maybe you could do something like:

MHO%xe> with t as ( -- generating your sample data:
  2  select '123' col1, 'johns123' col2, 'edwin321s' col3 from dual union all
  3  select 'seenu', 'janu', 'satya123reset' from dual union all
  4  select '3456', 'kris', '123stest' from dual
  5  )
  6  --
  7  -- actual query:
  8  --
  9  select rtrim ( case when col1 like '%123%' or col1 like 's%' then col1||', '  end
 10         ||      case when col2 like '%123%' or col2 like 's%' then col2||', '  end
 11         ||      case when col3 like '%123%' or col3 like 's%' then col3||', '  end
 12         , ', ')
 13  from   t;

RTRIM(CASEWHENCOL1LIKE'%123%'ORC
--------------------------------
123, johns123
seenu, satya123reset
123stest

You mention:

or print the records begins by a ' as

However the output desired is not begin with s for 's123' and "stest"... you can adjust your specification or your output...

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 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

  • Clarification of the SQL query in 2 day + Guide APEX

    I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).

    The code is:

    SELECT d.DEPARTMENT_ID,

    d.DEPARTMENT_NAME,

    (select count (*) from oehr_employees where department_id = d.department_id)

    "Number of employees", he said.

    substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',

    c.COUNTRY_NAME 'place '.

    OEHR_DEPARTMENTS d,

    E OEHR_EMPLOYEES

    OEHR_LOCATIONS l,

    C OEHR_COUNTRIES

    WHERE d.LOCATION_ID = l.LOCATION_ID

    AND l.COUNTRY_ID = c.COUNTRY_ID

    AND e.department_id = d.DEPARTMENT_ID

    AND d.manager_id = e.employee_id

    AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)

    I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.

    What does this string? This code simply checking that d.department_name isn't NA?

    I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.

    Thank you.

    2899145 wrote:

    Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.

    In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report

    page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.

    for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.

    However, given that the document is a guide for the development of the APEX, I guess the command:

    AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0

    done something valuable, and I do not recognize what is exactly the value.

    From a practical point of view why would I need to include this conditional statement?  Which only added to the application?

    Looking at the guide in question, it is clear that the

    AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
    

    the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.

    If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...

  • 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
    ------------------------------------------------------------------------------

  • 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;

  • Report with the sql query area

    Hello

    I have a region in relation to the sql query. There are two regions in the page. Top of page, the user enters data and after that second data enterd to see the region, which is related region
    based on a sql query.

    Now, when this page is opned, because the user has not entered anything, region report shows the message "no data found". Is it possible to remove this message or
    may I have conditionally disaply region report IE if data are inserted only region report is dispalyed.

    Thank you

    Hello

    You can use conditions for example "Exists (SQL query returns at least one row).

    Kind regards
    Jari

  • date picker default value appears only not in the sql query

    Hello

    I have a page as a table with a query similar to the following:

    Select emp_name, salary of emp_table where (hire_date) trunc = trunc (to_date (:P42_START_DATE))

    where P42_START_DATE is the name of a date picker.

    I put the date picker, "only when the current value in session state is null" and the value of being "select trunc (next_day(sysdate,'MON')-7) from dual;"-essentially the Monday of the current week, the type of source. I updated the date to 5 selector and the sequence of the region 10. Now, when I opened this page, no data gets pulled. I checked the source of the page and the value of the entry date picker is used to "November 17, 2008", but is not somehow reflected in the sql query.

    Data get retrieved if I put manually the date in the date picker, but I would like that it by default on Monday of this week. What I am doing wrong?

    Thank you

    Hello

    >
    "Article 1 of the Expression value is NULL" where is expression 1
    P42_START_DATE
    >

    Yes, that's correct - No. colon is required here as we don't not using the item as a variable binding, just name for the condition. In my tests, I put the calculation for:

    Name of article: P31_HIREDATE (put your P42_START_DATE here instead)
    Type: SQL query
    Point calculation: before header
    Calculation: SELECT TO_CHAR (TRUNC (SYSDATE, 'DAY'), 'DD-MON-RR') FROM DUAL

    My report SQL statement is:

    SELECT EMPNO,
    ENAME,
    HIREDATE
    FROM EMP
    WHERE NVL(HIREDATE, TRUNC(SYSDATE)) < TO_DATE(:P31_HIREDATE,'DD-MON-RR')
    

    My datepicker object has no special parameters - so:

    Name: P31_HIREDATE
    Display: Date Picker (DD-MON-RR)
    Source: Only when...
    Source type: static...
    The source value or expression: (empty)
    Default: (empty)

    And that's what I did to get: http://htmldb.oracle.com/pls/otn/f?p=55041:31

    Change the date that you like or click Reset to clear the cache (the calculation will be then reset the date to the current date and refiltrer the report)

    Andy

  • 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

  • How to select only the part by using the sql query

    Hello

    I have the task to retrieve only the integral of the input text by using the sql query.

    The entry is as follows

    Entry for the price setting

    $12.5 (FYI without space)

    $ 12.5 (FYI single space)

    $ 12.5 (double space FYI)

    $12.5 (FYI multiple space)

    $12.5 (FYI multiple space)

    Output expected of 12.5

    The price is the type varchar2 column in the store_price table.

    Please let me know how to achieve this.

    Thanks in advance.

    If this is always the case that you get a $ followed by a number of places, you can use something like:

    Select to_number (ltrim ('$ 12.5',' $')) DOUBLE

    or

    SELECT ltrim ('$ 12.5',' $') OF double

    but take care of your nls_numeric_character settings if they are defined so that, for example, a comma is the decimal separator, you will have a problem.

    HTH

Maybe you are looking for