SQL query to get the desired result

I have the array with the following values

Account Functional currency Billing currency Amount Header 5
101USDUSD10 h 00
101USDCAD12 h 00
102JPYUSD9 h 00
102JPYCAD3.00
102JPYSGD2.00

If the account has one different inv_currencypar that the functional currency and then

I have to summarize the amount in this account by viewing the billing currency

If the account has more than one other inv_currencypar that the functional currency and then

I have to summarize the amount in this account showing the functional currency as the currency of invoicing

I need output like this:

Account

Functional currency Billing currency Total amount Header 5101USDCAD10:00 pm102JPYJPY2:00 pm

Can we get over output in sql without writing pl/sql program?

Hello

According to your specific needs, here's a way:

SELECT account

functional_currency

CASE

WHEN 1 = COUNT (DISTINCT NULLIF (invoice_currency

functional_currency

)

)

THEN MAX (NULLIF (invoice_currency

functional_currency

)

)

Of OTHER functional_currency

END AS invoice_currency

The SUM of (amount) AS total_amount

header5

FROM table_x

GROUP BY account

functional_currency

header5

;

If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

Is it possible to have 2 (or more) of different functional_currencies in the same account?

Tags: Database

Similar Questions

  • SQL query to get the given result

    Hi friends

    My data in the table are given below

    user transaction_date transaction_type
    1 1st August 2011
    August 2, 2011 1 c
    1 3 August 2011
    1 b 3 August 2011
    1 August 4, 2011 a
    1 b 4 August 2011
    2 3 August 2011
    2 b 3 August 2011
    August 4, 2011 2 c
    2 b 4 August 2011
    2 August 5, 2011 a
    2 b August 5, 2011
    2 August 7, 2011 a
    2 b 7 August 2011

    I want the count for each user as, how many times he made a transaction type transaction immediately after 'b' type?

    As the output of above data should be

    number of users
    1 2
    2 3

    Thanks in advance :)

    Maybe (NOT TESTED).

    select "user",
           count(criteria) "count"
      from (select "user",
                   transaction_date,
                   transaction_type,
                   case when transaction_type = 'b'
                         and lag(transaction_type,1) over (partition by "user",transaction_date
                                                               order by transaction_date,transaction_type) = 'a'
                        then 1
                   end criteria
              from the_table
           )
     group by "user"
     order by "user"
    

    Concerning

    Etbin

  • SQL query to get the NULL records after the last matching flag

    I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).

    SQL > create table xx1

    2 (identification number,

    3 flag varchar2 (10));

    Table created.

    SQL > insert into xx1 values (1, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (2, null);

    1 line of creation.

    SQL > insert into values xx1 (3, null);

    1 line of creation.

    SQL > insert into xx1 values (4, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (5, null);

    1 line of creation.

    SQL > insert into xx1 values (6, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (7, null);

    1 line of creation.

    SQL > insert into values xx1 (8, null);

    1 line of creation.

    SQL > insert into values xx1 (9, null);

    1 line of creation.

    SQL > select * from xx1.

    FLAG OF THE ID

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

    1. IS

    2

    3

    4. IS

    5

    6. IS

    7

    8

    9

    9 selected lines.

    SQL >

    Hello

    user11164339 wrote:

    Hi Frank - when I run the query, I don't see the results data.

    I get

    FLAG OF THE ID

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

    7

    8

    9

    What you do differently?

  • IOM sql Query to get the status of the failed task

    Hello world

    We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.

    Thanks in advance.

    Kind regards
    MKN

    Hello
    Use this query to get the status of the task, also check the cooments

    SELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
    OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
    WHERE OSI.MIL_KEY = MIL.MIL_KEY
    AND ANN. SCH_KEY = OSI. SCH_KEY
    AND STA. STA_STATUS = SCH. SCH_STATUS
    AND TOS. PKG_KEY = PKG. PKG_KEY
    AND MIL. TOS_KEY = TOS. TOS_KEY
    AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
    AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
    AND OST. OBJ_KEY = OBJ. OBJ_KEY
    AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
    AND OBJ. OBJ_NAME = "User AD".
    AND OST. OST_STATUS = "Provisioning" - filter accordinglly
    AND STA. STA_BUCKET = 'pending' - filter accordinglly
    AND PKG. PKG_NAME = "AD User" - filter accordinglly
    AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
    ;
    Thank you
    Kuldeep

  • SQL query to get the numbers from 0 to 99

    How can we write a sql query to get values from 0 to 99... This should not come from any table
    SELECT LEVEL - 1
      FROM  DUAL
      CONNECT BY LEVEL <= 100
    /
    

    SY.

  • Need for SQL query to get the result.

    Region

    MonthTrx typeSummary of the resolution
    AMERICAS-13 mayAdjustmentsFix
    EMEA-13 mayAdjustmentsIncorrect
    AMERICAS-13 mayCredit memoIncorrect
    EMEA-13 mayInvoiceFix
    AMERICAS-13 mayCredit memoFix
    OFD-13 mayAdjustmentsFix
    AMERICAS-13 mayInvoiceIncorrect
    DVL-13 mayAdjustmentsFix
    DVL-13 mayAdjustmentsFix
    OFD-13 mayAdjustmentsFix

    Above my Table and here is the result required. Similarly for other regions as well. Can someone help me with the SQL query?

    RegionSummary of the resolutionSettingCredit memoInvoiceTotal general
    AMERICASFix112
    Incorrect0112

    Like this?

    SQL > select * from transaction_audit;

    MTH TRX_TYPE REGION BOARD
    -------- ------ ----------- ---------
    AMERICAS-13 may SETTINGS CORRECT
    EMEA-13 may INCORRECT ADJUSTMENT
    AMERICAS-13 may CREDIT MEMO INCORRECT
    EMEA-13 may INVOICE CORRECT
    AMERICAS-13 may CREDIT MEMO CORRECT
    OFD-13 may SETTINGS CORRECT
    AMERICAS-13 may INVOICE INCORRECTE
    LAD-13 may SETTINGS CORRECT
    LAD-13 may SETTINGS CORRECT
    OFD-13 may SETTINGS CORRECT

    10 selected lines.

    SQL > select region
    2, resolution_summary
    3, count (decode (trx_type, "ADJUSTMENTS", trx_type)) adjustments
    4, County (decode (trx_type, 'HAVING', trx_type)) credit_memo
    5, County (decode (trx_type, "BILL", trx_type)) Bill
    transaction_audit 6
    Group 7
    8 by region
    9, resolution_summary
    10 Decree
    11 by region
    12, resolution_summary
    13.

    REGION TAKE ADJUSTMENTS CREDIT_MEMO INVOICE
    -------- --------- ----------- ----------- ----------
    CORRECT THE AMERICAS 1 1 0
    0 1 1 INCORRECT AMERICAS
    EMEA CORRECT 0 0 1
    INCORRECT EMEA 1 0 0
    DAL ADDRESS 2 0 0
    OFD CORRECT 2 0 0

    6 selected lines.

    SQL >

  • SQL query to get the number of days monthwise

    Hello
    I'm new to sql, can someone please tell me query to find the number of days between the two dates months wise.
    say
    FIRSTDATE last date
    21/03/2011-25/06/2011

    March April May June
    9 22 23 18

    Hello

    Welcome to the forum!

    Here's one way:

    WITH     all_dates     AS
    (
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT     TO_DATE ('21/03/2011', 'DD/MM/YYYY')     AS start_date
                   ,     TO_DATE ('25/06/2011', 'DD/MM/YYYY')     AS end_date
                   FROM     dual
              )
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    )
    SELECT       TO_CHAR ( TRUNC (a_date, 'MONTH')
                , 'fmMonth YYYY'
                )               AS month
    ,       COUNT (*)               AS num_days
    FROM       all_dates
    WHERE       a_date - TRUNC (a_date, 'IW')     < 5
    GROUP BY  TRUNC (a_date, 'MONTH')
    ORDER BY  TRUNC (a_date, 'MONTH')
    ;
    

    What is a 'working day '? I guess you mean every day except Saturday or Sunday, but the query aboveare sometimes figures less than you have asked:

    MONTH             NUM_DAYS
    --------------- ----------
    March 2011               9
    April 2011              21
    May 2011                22
    June 2011               18
    

    Are a few days working on Saturday or Sunday? How do you get the 22 working days in April 2011 and 23 in may?

    SQL is good at obtaining results with a variable number of rows, but you have to say exactly the desired number of columns when you write the query.
    If you really need the output of the way you said, with any number of columns, then watch in swing or a grouping of the chain . See the FAQ forum
    https://forums.Oracle.com/forums/Ann.jspa?annID=1535
    "4. How can I convert rows to columns.

  • Dynamic SQL query to get the unique value of list in a column

    I have two tables: tblWorkers and tblSkills. tblWorkers has a column, skills, which is populated by a field of multiple-checkbox with one or more skill_IDs of tblSkills, so each tblWorkers.Skills consists of a list of one or more comma-delimited values. For any Skill_ID, I need to generate a list of all workers with the appropriate skills, so I tried to do something in the direction of SELECT WorkerName FROM tblWorkers WHERE IN of skills (skills, #FORM. Skill_ID #)... or WHERE skills (ListFind (skills, #FORM. Skill_ID #))... etc.? My results (once I have had data type mismatches of the road) return all workers, not just those with the desired skills. There must be an easy way to do... How people with a little more experience CF/SQL I do this?

    > each tblWorkers.Skills consists of a list of one or more comma-delimited values

    This is your problem. You store a list of values that you want to access power/query separately in a single column. You will have to burst in a separate table.
    TblWorkers

    TblSkills

    TblWorkerSkills
    mapping table of many workers with skills.

    If you do not change your data model now, you will constantly be butting your head against that.

  • SQL query to get the items for which transactions have not been saved

    Hi people,

    Have a small doubt I want to compile a SQL query in the inventory where I get these items for what transactions do not have been recorded during a period of at least one specified number of days.

    The days might be 30 days or 2 months depends on. If I want to get those items for which no transactions were reported for lets say 30 days. Could someone give me an idea of how to go about this thing? I use r12. I came up with the following query, but it gives a lot of records. The commented parts of this query is only commented on


    SELECT DISTINCT msi.segment1,

    MSI. Description,

    MSI.primary_uom_code,

    MSI.inventory_item_id

    MSI mtl_system_items_b / *,.

    mtl_material_transactions mmt * /.

    WHERE / * msi.inventory_item_id = mmt.inventory_item_id

    AND msi.organization_id = mmt.organization_id

    AND NVL ((SELECT SUM (transaction_quantity)

    OF mtl_onhand_quantities

    WHERE inventory_item_id = msi.inventory_item_id),

    0) = 0

    AND TRUNC (mmt.transaction_date) < = SYSDATE - & D

    AND * / NOT EXISTS (SELECT *)

    OF mtl_material_transactions mmt

    WHERE msi.inventory_item_id = mmt.inventory_item_id

    AND msi.organization_id = mmt.organization_id

    AND TRUNC (mmt.transaction_date) < SYSDATE - & D);

    Hi fatimakhellil

    Try the following code and mark it as correct if your problem be resolved.

    SELECT DISTINCT msi.segment1,

    MSI. Description,

    MSI.primary_uom_code,

    MSI.inventory_item_id,

    MSI.organization_id,

    Ms.secondary_inventory_name,

    (select max (transaction_date) in the mtl_material_transactions where msi.inventory_item_id = inventory_item_id

    AND msi.organization_id = organization_id) last_transaction_date

    OF mtl_system_items_b msi.

    Ms. mtl_secondary_inventories

    WHERE ms.organization_id (+) = msi.organization_id

    AND msi.source_subinventory = ms.secondary_inventory_name (+)

    AND NOT EXISTS (SELECT *)

    OF mtl_material_transactions mmt

    WHERE msi.inventory_item_id = mmt.inventory_item_id

    AND msi.organization_id = mmt.organization_id

    AND mmt.subinventory_code = ms.secondary_inventory_name

    AND mmt.organization_id = ms.organization_id

    AND TRUNC (mmt.transaction_date) BETWEEN TRUNC (SYSDATE - & d) AND TRUNC (SYSDATE))

  • How to get the desired result when subsequent month is not available

    WITH T1
         AS (SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-Jan-2015' DT,
                    10 QTY
               FROM DUAL
             UNION
             SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-feb-2015' DT,
                    20 QTY
               FROM DUAL
             UNION
             SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-mar-2015' DT,
                    30 QTY
               FROM DUAL
             UNION
             SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-may-2015' DT,
                    40 QTY
               FROM DUAL
             UNION
             SELECT 'A1' COL1,
                    'B1' COL2,
                    'C1' COL3,
                    '01-mar-2015' DT,
                    40 QTY
               FROM DUAL
             UNION
             SELECT 'A1' COL1,
                    'B1' COL2,
                    'C1' COL3,
                    '01-may-2015' DT,
                    40 QTY
               FROM DUAL)
    SELECT *
      FROM t1
    
    

    Current output:

    COL1COL2COL3DTQTY.
    ABCJanuary 1, 201510
    ABCFebruary 1, 201520
    ABC01-mar-201530
    ABC01-may-201540
    A1B1C101-mar-201540
    A1B1C101-may-201540

    Expected results

    COL1COL2COL3DTQTY.DTREQ_VAL
    ABC01/01/20151001/01/201520
    ABC01/02/20152001/02/201530
    ABC01/03/20153001/03/20150
    ABC01/05/20154001/05/20150
    A1B1C101/03/20154001/03/20150
    A1B1C101/05/20154001/05/20150

    Logic:

    If we COL1, COL2, COL3 combination for A, B, C, we have the quantity for 1 January, 1 February, 1 March, 1 may, and we don't have quantity for April 1 and June 1. I need following QUANTITY value as another column. If I use the lead, I'll get the value from May 1st to March 1st, but I want to value 0 because it is after March either.

    What I've tried so far:

    SELECT *
      FROM (WITH T1
    AS (SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-Jan-2015' DT,
    10 QTY
    FROM DUAL
    UNION
    SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-feb-2015' DT,
    20 QTY
    FROM DUAL
    UNION
    SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-mar-2015' DT,
    30 QTY
    FROM DUAL
    UNION
    SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-may-2015' DT,
    40 QTY
    FROM DUAL)
            SELECT COL1,
     COL2,
     COL3,
    TO_DATE (T1.DT) DT,
    NVL (QTY, 0) QTY,
     MONTHS.DT ALL_DATES,
     LEAD (NVL (QTY, 0), 1, 0) OVER (ORDER BY MONTHS.DT) REQ_VAL
              FROM T1,
    (    SELECT ADD_MONTHS (TO_DATE ('01-jun-2015'), LEVEL - 6) DT
    FROM DUAL
    CONNECT BY LEVEL <= 12) MONTHS
             WHERE MONTHS.DT = T1.DT(+))
    WHERE DT ISNOTNULL;
    
    
    
    
    
    

    My query works for a set of COL1, COL2, COL3, am looking how we can achieve multiple COL1, COL2, COL3 (or) otherwise better query writing.

    Thanks for your suggestions in advance.

    Thank you

    Now, to understand your condition: your additional column must indicate the amount of the next month, or zero if it is not a record for the month. How about this?

    WITH T1

    AS (SELECT 'A' COL1,)

    'B' COL2,

    COL3 'C ',.

    To_date('01-Jan-2015','dd-mon-yyyy') DT,

    QTY 10

    OF THE DOUBLE

    UNION

    SELECT 'A' COL1,

    'B' COL2,

    COL3 'C ',.

    To_date('01-Feb-2015','dd-mon-yyyy') DT,

    QTY. 20

    OF THE DOUBLE

    UNION

    SELECT 'A' COL1,

    'B' COL2,

    COL3 'C ',.

    To_date('01-Mar-2015','dd-mon-yyyy') DT,

    QTY 30

    OF THE DOUBLE

    UNION

    SELECT 'A' COL1,

    'B' COL2,

    COL3 'C ',.

    To_date('01-May-2015','dd-mon-yyyy') DT,

    QUANTITY 40

    OF THE DOUBLE

    UNION

    SELECT 'A1' COL1,

    COL2 "B1."

    COL3 "C1"

    To_date('01-Mar-2015','dd-mon-yyyy') DT,

    QUANTITY 40

    OF THE DOUBLE

    UNION

    SELECT 'A1' COL1,

    COL2 "B1."

    COL3 "C1"

    To_date('01-May-2015','dd-mon-yyyy') DT,

    QUANTITY 40

    THE DOUBLE)

    X.Col1, x.col2, x.col3, x.dt, x.qty, NVL(y.qty,0) SELECT req_val

    THE t1 x

    LEFT OUTER JOIN t1 y

    ON y.col1 = x.col1

    AND y.col2 = x.col2

    AND y.col3 = x.col3

    AND y.dt = add_months(x.dt,1)

    ORDER BY 1,2,3,4

    My query works for a DFU, am looking how we can achieve multiple UTD

    What is a DFU?

  • Failed to get the desired result

    Hi gurus

    Don't know why I get the following output:

    Query

    SOME jobs,

    COUNT (*),

    COUNT (CASE job WHEN 'CLERK' THEN 1 ELSE 0 END) cnt

    WCP

    Working GROUP;

    The query result

    WORK, COUNT (*), CNT

    3 3 CLERKS

    4 4 SELLER

    THE PRESIDENT 1 1

    MANAGER 3 3

    1 1 ANALYST

    According to my understanding, the result should be as below:

    Result must be

    WORK, COUNT (*), CNT

    3 3 CLERKS

    SELLER 4 0

    THE PRESIDENT 1 0

    MANAGER 3 0

    ANALYST 1 0

    Thanks in advance.

    Concerning

    Shu

    Hello

    Shuumail wrote:

    Hi gurus

    Don't know why I get the following output:

    Query

    SOME jobs,

    COUNT (*),

    COUNT (CASE job WHEN 'CLERK' THEN 1 ELSE 0 END) cnt

    WCP

    Working GROUP;

    The query result

    WORK, COUNT (*), CNT

    3 3 CLERKS

    4 4 SELLER

    THE PRESIDENT 1 1

    MANAGER 3 3

    1 1 ANALYST

    According to my understanding, the result should be as below:

    Result must be

    WORK, COUNT (*), CNT

    3 3 CLERKS

    SELLER 4 0

    THE PRESIDENT 1 0

    MANAGER 3 0

    ANALYST 1 0

    Thanks in advance.

    Concerning

    Shu

    COUNT (*) tells you how many lines there are.

    COUNT (exp) tells you how many lines have a value not NULL in exp

    Your CASE expression never returns null; It always returns a value of 0 or 1, but never NULL.  So, if exp is never NULL, so each line has a value not NULL and if COUNT (*) and COUNTY (exp) are always the same.

  • How to rewrite this query to get the correct results?

    Friends,

    DB: 9iR2

    I need to get the name of the employee and the employee number that are not in the table of presence.
    but this query is not the right answer.
    select e.eno,e.ename from empl e
    where e.eno not in (select a.eno from attendance a)
    Thank you

    Depending on your data

    SQL> create table attendance(
      2  ENO   VARCHAR2(5),
      3   TDATE VARCHAR2(10),
      4   IN_TIME  VARCHAR2(6),
      5   OUT_TIME VARCHAR2(6),
      6   SHIFT_NO  NUMBER(1));
    
    Table created.
    
    SQL>  create table empl(
      2   ENO VARCHAR2(5),
      3   ENAME  VARCHAR2(75));
    
    Table created.
    
    SQL> insert into empl values('11','AA');
    
    1 row created.
    
    SQL>   insert into empl values('12','AB');
    
    1 row created.
    
    SQL>    insert into empl values('13','AC');
    
    1 row created.
    
    SQL>     insert into empl values('14','AD');
    
    1 row created.
    
    SQL>   insert into empl values('15','AF');
    
    1 row created.
    
    SQL>  insert into attendance values('11','23-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('14','24-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('11','25-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('13','23-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('15','23-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    select e.eno,e.ename
    from empl e
    where not exists(select 1 from attendance a where a.eno=e.eno);
    
    ENO     ENAME
    
    12     AB
    

    Twinkle

  • Query to achieve the desired result

    Hi all

    Am happy to post my first question in this Forum. Please guide me to get the output as shown below using oracle - sql.

    C1 c2 c3 c4 OF THE amt

    a d c b 50 exp

    a, b, c and d nonmed 60

    The data above should be modified as shown below.

    C1 C2 C3 C4 OF THE amt OF THE amt

    a d c 50-60 nonmed b exp

    How can achieve us this, Pls Help.

    Thank you

    Harish

    PIVOT is the way to go.

    But just for fun, while relying on the input you provided, there may be another approach like that... (questionable solution because of the ambiguous order by clause)

    -------

    WITH dataset (c1,c2, c3, c4,DES,amt)
         AS (SELECT 'a', 'b', 'c', 'd', 'exp', '50' FROM DUAL
             UNION ALL
             SELECT 'a', 'b', 'c', 'd', 'nonmed', '60' FROM DUAL)
    select * from (SELECT c1,c2,c3,c4,des,amt,lead(des) over(partition by 1,2,3,4 order by null) col3,lead(amt) over(partition by 1,2,3,4 order by null) col4
      FROM dataset)
      where col3 is not null and col4 is not null;
    

    Output:

    C1 C2 C3 C4 THE AMT COL3 COL4
    one b c d exp 50 nonmed 60

    See you soon,.

    Manik.

  • SQL query to get the first four characters of an address

    Hi gurus,


    Can you please help me with the below quries on how to achieve this. Could be really helpful if you could provide a sample sql on your side.


    Req:

    I have a requriement where I should display the first four characters other than a space to address, for example: becomes R, DISH etc. F. in passing in a ROOM address a DISH 1 FLORIAN AVENUE would therefore "RAF1", while a CORNER, 23 STREET address would be "23CO".


    Words such as c/o, co, rear should be ignored, if any.

    Thanks in advance.


    Kind regards

    Peoples

    Hi John,.

    Here is an implementation of a pl/sql function that suggested a franc. It uses two lists, one with the words which are replaced with the first character and a second with words to ignore.

    create or replace function first_four (p_input in varchar2) return varchar2 is

    type t_words is table of the varchar2 (100);

    p_replace t_words: = t_words ('ROOM', 'FIELD', 'FLAT', 'FLT', 'BLOCK', 'UNIT', 'STUDIOS', 'CARAVAN', 'APARTMENT');

    p_ignore t_words: = t_words ("C/o ', 'CO', 'BACK TO'");

    v_input varchar2 (100);

    Start

    -Put the entry in a local-variable he

    v_input: = upper (p_input);

    -delete the words contained in the ignore list

    because me in 1.p_ignore.count

    loop

    v_input: = replace (v_input, p_ignore (i));

    end loop;

    -Replace the words by first character in the replacement list

    for r in 1.p_replace.count

    loop

    v_input: = replace (v_input, p_replace (r), substr (p_replace (r), 1, 1));

    end loop;

    -remove the spaces and return only the first 4 characters

    Return substr (replace (v_input, ' '), 1, 4);

    end;

    /

    It returns the expected results for the four examples you gave:

    SQL > with t as)

    2 select address 'FLAT 3 a 12 LILLYHAM ROAD' of all the double union

    3 select ' GREE LANE GLOSONTH 45' across Union double

    4 Select "FLAT 3 221 b Baker Street," of all the double union

    5. Select "C/o CARAVAN 32 STREET BLOK 6 RICHMOOND' of the double)

    6. Select ff first_four (address) of t;

    FF

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

    F3A1

    45GR

    F322

    C32B

  • SQL query to get the range of Date values

    Hello

    The database is Oracle11i.

    I'm looking for a way to generate a list of the dates of a fixed date in the past (could be hardcoded) at the time of the day (sysdate).

    In other words, if the fixed date is June 19, 2011, and assuming today ' today is June 24, 2011 the SQL must be able to generate the

    Next: -.

    June 19, 2011
    June 20, 2011
    June 21, 2011
    June 22, 2011
    June 23, 2011
    June 24, 2011

    And the constraint is that I can not make any change to the database in question. I can only shoot a (SELECT) SQL query. NO.

    use time dimension type of approach (time dimension is not available here) and no procedure, etc. from PL/SQL. Is it possible?

    Thank you

    Jaimeen Shah wrote:
    Hello

    The database is Oracle11i.

    I'm looking for a way to generate a list of the dates of a fixed date in the past (could be hardcoded) at the time of the day (sysdate).

    In other words, if the fixed date is June 19, 2011, and assuming today ' today is June 24, 2011 the SQL must be able to generate the

    Next: -.

    June 19, 2011
    June 20, 2011
    June 21, 2011
    June 22, 2011
    June 23, 2011
    June 24, 2011

    And the constraint is that I can not make any change to the database in question. I can only shoot a (SELECT) SQL query. NO.

    use time dimension type of approach (time dimension is not available here) and no procedure, etc. from PL/SQL. Is it possible?

    Thank you

    SQL> def date_start = '13/11/2010'
    SQL> def date_end   = '22/11/2010'
    SQL> with
      2    data as (
      3      select to_date('&date_start', 'DD/MM/YYYY') date1,
      4             to_date('&date_end',   'DD/MM/YYYY') date2
      5      from dual
      6    )
      7  select to_char(date1+level-1, 'DD/MM/YYYY') the_date
      8  from data
      9  connect by level <= date2-date1+1
     10  /
    THE_DATE
    ----------
    13/11/2010
    14/11/2010
    15/11/2010
    16/11/2010
    17/11/2010
    18/11/2010
    19/11/2010
    20/11/2010
    21/11/2010
    22/11/2010
    

Maybe you are looking for