Strange TO_DATE/TO_CHAR

Hi all

I am facing a problem with To_char function for the date object.

I am trying to execute the following SQL code:

Select do_date, XXX, to_char (xxx))

Select

TO_DATE)

case substr (do_date, 1, 14)

When '2016' then do_date

of another substr (do_date, 1, 14)

end

, 'YYYYMMDDhh24miss '.

)

XXX, wns_attack_meminfo_work do_date

);

The result is

DO_DATE XXX TO_CHAR (XXX)

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

20150731181234 31 JULY 15 000-00-00

20150731181234 31 JULY 15 000-00-00

20150731181234 31 JULY 15 000-00-00

20150731181234 31 JULY 15 000-00-00

Any body knows why, when XXX has a valid value, TO_CHAR (XXX) returns an incorrect value?

I run the query against ORACLE 10 g 10.2.0.1.0, 32-bit, Windows server 2003.

When I try to run the same query against an another DB (CENTOS5.5_64, 10.2.0.4.0, 64-bit) the result is ok.

I not only have to solve this problem, but also need to explain to the client why we have this problem.

Any help is highly appreciated.

Thanks in advance,

Tuan

Simple guideline - if there is no other difference between the two databases and it works on 10.2.0.4 but not on 10.2.0.1 then there is a very good chance that you look at a bug that is corrected.

In your case, the result is something that "cannot possibly" appears, this suggests a bug even more strongly; and then you can't help but notice that your SQL * Plus shows XXX as a readable date, she made an implicit conversion of some sort and you expect your Explicit to_char() (server side) to work as well.

You dump (XXX) is very informative. Type 7 is what you get by immersion of a date of database column, type 8, that's what you get by dumping (e.g. SYSDATE) when it is used as a variable. This suggests an error in the internal code that produces a gap between two stages of execution of SQL.

Speculation is not necessary, though - I just did a quick search on Metalink (MOS) in the "Bug" database for 'to_date' "" 000-00-00 and found the following: Bug 5174854 : RETURNS TO_CHAR ON A DATE VALUE "000-00-00 '.

Reported in 10.2.0.1, 10.2.0.2 fixed

Concerning

Jonathan Lewis

Tags: Database

Similar Questions

  • TO_DATE and to_char

    Hello

    Can someone explain to me why

    Select to_date (to_char (to_date('17.05.0012','dd.mm.yyyy'), 'dd'), 'dd.mm.rr') of double
    gives * 17.05.0012 * (what I think wrongly), but

    Select to_date (to_char (to_date('17.05.0012','dd.mm.yyyy'), ' dd.mm.yy' ")" | ") "dd.mm.rr") of the double
    gives * 17.05.2012 *.

    Thank you!

    Ok thank you! Seems it is explained more or less (only I can't do a patch, it is not my private Oracle).
    I asked a different colleague with Oracle to test and she got good results for 10.1 and 10.2.
    Well, it's not the biggest bug of my life! I'll close the question and thanks for the help!

  • use function TO_DATE in Oracle 11i

    Expected output below using the query: select sysdate, ' to_date ('|) '''|| SYSDATE | " (', "DD-MON-YYYY"),' the double;

    To_date('08-OCT-2013','DD-MON-YYYY') 8 October 2013,

    But by getting the output below, please provide your inputs.

    To_date('08-OCT-13','DD-MON-YYYY') 8 October 2013,

    Select sysdate, ' to_date ('|) '''|| to_char(sysdate,'DD-MON-YYYY') | " (', "DD-MON-YYYY"), "of the double;

  • How to convert value to_date characters?

    I want to change the time (hours) sysdate to '10', then save this new date in a date column that I wrote the following command
    (TO_CHAR(SYSDATE,'DD-MON-RRRR')||' 10:'||TO_CHAR(SYSDATE,'MI:SS AM'))
    This command deletes the actual hours of sysdate and change with the value "10". but the result of this command is a character value. and I want a date value into a date column. to do this, I have converted this command to_date as follows
    TO_DATE(TO_CHAR(SYSDATE,'DD-MON-RRRR')||' 10:'||TO_CHAR(SYSDATE,'MI:SS AM'))
    but it gives the following error

    ORA-01830: date format picture ends before converting all of the input string

    How to do this?

    Gul says:
    I want to change the time (hours) sysdate to '10', then save this new date in a date column that I wrote the following command

    (TO_CHAR(SYSDATE,'DD-MON-RRRR')||' 10:'||TO_CHAR(SYSDATE,'MI:SS AM'))
    

    This command deletes the actual hours of sysdate and change with the value "10". but the result of this command is a character value. and I want a date value into a date column. to do this, I have converted this command to_date as follows

    TO_DATE(TO_CHAR(SYSDATE,'DD-MON-RRRR')||' 10:'||TO_CHAR(SYSDATE,'MI:SS AM'))
    

    but it gives the following error

    ORA-01830: date format picture ends before converting all of the input string

    How to do this?

    TO_DATE (TO_CHAR(SYSDATE,'DD-MON-YYYY') |) ' 10 :'|| TO_CHAR(SYSDATE,'MI:SS_AM'),' DD-MON-YYYY HH: MI: SS AM')

  • can we use to_date using Union or Union

    Hi, while I do any union with two tables I get

    ORA-01790: expression must have same type of data, matching expression
    01790 00000 - "expression must have the same type of data, matching expression.


    and if I change this data type of TO_CHAR is showing correct result

    SELECT (TO_CHAR (C61_CURRENT_MONTH, ' MON-DD-YYYY "") CURRENT_MONTH EDW.) C$ _0VW_TEMP_PLAYER_DTL_LOAD
    UNION ALL
    SELECT (TO_CHAR (C17_CURRENT_MONTH, ' MON-DD-YYYY "") CURRENT_MONTH EDW.) C$ _1VW_TEMP_PLAYER_DTL_LOAD

    and I'm going to insert this result in a table which column is defined as the DATE data type

    so I tried below one as

    Select to_date (TO_CHAR (C61_CURRENT_MONTH, ' MON-DD-YYYY ""), 'dd-mon-yyyy') CURRENT_MONTH OF EDW. C$ _0VW_TEMP_PLAYER_DTL_LOAD
    UNION ALL
    TO_DATE (TO_CHAR (C17_CURRENT_MONTH, ' MON-DD-YYYY ""), 'dd-mon-yyyy') CURRENT_MONTH OF EDW. C$ _1VW_TEMP_PLAYER_DTL_LOAD

    but I get the error message like

    ORA-01790: expression must have same type of data, matching expression

    so my question is can we use to_date using union all.

    Maybe do you the conversion to remove time from date values.

    This could be done better with:

    select trunc(C61_CURRENT_MONTH) CURRENT_MONTH FROM EDW.C$_0VW_TEMP_PLAYER_DTL_LOAD
    UNION ALL
    select trunc(C17_CURRENT_MONTH) CURRENT_MONTH FROM EDW.C$_1VW_TEMP_PLAYER_DTL_LOAD
    

    I can't reproduce your original error, because I do not have your tables (test data would be nice)
    and no doubt I'm on another database-version (we do not know your version of db).

    Published by: hm on 19.04.2012 04:30

  • Error: No function with name to_date does exist in this scope

    Hai All

    insert into dail_att(empcode,barcode,intime,attend_date)

    (select r1.barcode, to_date (to_char (r1.bardate, 'ddmmyyyy'): min (r1.bartime), 'ddmmyyyy hh24mi'),)
    R1.bardate of the r1.barcode temp_attendance group, r1.bardat);

    It is my statement to insert

    Here I insert data Dail_att the table Temp_attendance and here R1 is the folder that I stated.

    It works very well. More I need to add a column in the Insert EMPCODE IE and I need to

    take Empl_barcode.

    Table of Empl_barcode consist of fields

    Empcode tank

    Barcode varchar

    Etc.

    So I need to include empcode in this statement when I use this in my insert statement


    insert into dail_att(empcode,barcode,intime,attend_date)
    (selecte.emplcode, r1.barcode, to_date (to_char (r1.bardate, 'ddmmyyyy'): min (r1.bartime), 'ddmmyyyy hh24mi'),)

    Temp_attendance R1.bardate, e empl_barcode, where e.barcode = r1.barcode group by

    R1. Barcode, R1.bardate, e.emplcode);


    I got an error

    No function with name to_date does exist in the scope



    Any help is highly appericatable


    Thanks and greetings

    Srikkanth.M

    Published by: Srikkanth.M on April 24, 2010 09:26

    Dear Srikkanth,
    First of all, in the table / column you provided and that the corresponding query names there are a large number of spelling errors or incompatibilities. It is very important that you make sure that your question is consistent.

    We have 'trying to figure out' if Bar_code is anme name or a table column, whence the emplcode column etc.
    Take the time to write the question and format, please.
    Frame queries and code in a pair of tags {code} without spaces.

    That said...

    update dail_att set empcode=(select emplcode
    from empl_barcode ,dail_att where bar_Code= barcode);
    
    And i have an error
    
    ORA-01427: single-row subquery returns more than one row 
    

    Let us think about this...
    The subquery in your update statement (which is the main request) is

    (select emplcode
    from empl_barcode ,dail_att where bar_Code= barcode)
    

    In this query, you want to join empl_barcode table and dail_att on * bar_code = barcode) condition.

    Why must you table dial_att in the subquery? You do not have.
    Remove dail_att the subquery table.

    VR
    Sudhakar B.

  • With the help of INTERVAL with the value of the column in to_char?

    I have a table with data having a datetime value in a column and a zone in the next column offset, designated as an integer (-6, - 7, etc.) I need to get the value of real time for use in queries, but I can't seem to find a way to do this without creating my own function to do so.

    Basically, I have to be able to do something like this:
    SELECT LOCATION_DATE + INTERVAL LOCATION_TIMEZONE HOUR from tablex
    LOCATION_DATE and LOCATION_TIMEZONE are columns in tablex


    This function seems to work:
    CREATE OR REPLACE FUNCTION FN_SHIFTDATE(dt DATE, tz VARCHAR2)
      RETURN DATE
    IS
      f_dt      DATE;
      f_tz      VARCHAR2(3);
      v_sql     VARCHAR2(500);
      r_dt      DATE;
    BEGIN
      f_dt      := dt;
      f_tz      := tz;
      v_sql  := 'select to_date('''|| to_char(f_dt,'MM/DD/YYYY HH24:MI:SS')||''',''MM/DD/YYYY HH24:MI:SS'')'||'+INTERVAL '''|| f_tz ||''' HOUR from dual';
      EXECUTE IMMEDIATE v_sql into r_dt;
      RETURN r_dt;
    END;
    /
    I was just curious if there was a way to do it directly in SQL without having to call a function every time to slow down the query.

    So, you want to just add a number of hours on a date?

    select LOCATION_DATE + LOCATION_TIMEZONE/24 NEW_TIME from tablex
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 19, 2010 12:21 AM

  • Problem strange date range

    I know that this kind of question is covered in other posts, so sorry to repeat, but at the moment I am confused about what I'm doing wrong.

    I am trying to select the 'book' of column for the rows of a table "library" for the date of today (in the format DD - MON) between the line start date and end date. What ends by going on, it is that I get lines where the number of date is between the number of start date and end date. For example, on today, 01 - JUN the order would display rows between 00 - OCT and 30 - DEC (car 01 is between 00 and 30), but not 02-JAN and 30 December (as 01 is not between 02 and 30).

    I don't want to display lines between the dates of arrival and not the number of the day.

    Select 'BOOK '.
    "library".
    where ((select TO_CHAR(SYSDATE, 'DD-MON') FROM DUAL) > = 'LIBRARY'.) ("' STARTING_DATE ') and ((select TO_CHAR(SYSDATE, 'DD-MON') FROM DUAL) < = 'LIBRARY'.) (("" ENDING_DATE '))

    Thanks for any clarification.

    If they are DATE data types, and you want to ignore year try

    select book
      from library
     where sysdate between to_date(to_char(starting_date, 'DD-MON')||'-'||to_char(sysdate, 'YYYY'), 'DD-MON-YYYY')
                       and to_date(to_char(ending_date, 'DD-MON')||'-'||to_char(sysdate, 'YYYY'), 'DD-MON-YYYY')
    

    This example uses the current year YYYY

  • Dates in SelectBox and a report querying return does not

    Hi all

    I'm fighting a bit with this one... I can see what is the problem, but the solution has me confused... (and I'm sure it's a simple...)

    APEX 4.2 on XE... The SUMMIT also has a version. Application of test/test ORACLE.COM Workspace VRS 291 page 7 connection.

    I try to query for a report based on the date of registration.

    The date on the table is of type DATE, and when the file is loaded its cargo directly from sysdate (and on the test on the APEX is simply an Insert into values of payments (ID, CREATED_DATE) (1, SYSDATE)

    I then create a selection list where I want to create a list of dates of the table, so the query is:

    Select distinct (to_char(created_date,'DD-MON-YY')) c1, c2 to_char(created_date,'DD-MON-YY') of payments

    It gives me a list of dates in the select list.

    Then I do a query on the report:

    Select

    "CREATED_DATE."

    "ID".

    of #OWNER #. PAYMENTS

    where created_date = to_date(:P7_SELECT_DATE,'DD-MON-YY')

    to get back the date, then pull it out...

    However, there is no so...    Ive tried all the combinations of to_char, to_date, etc...

    My assumption that the to_char on the selection list select bands the value down to the element of date only to the format character and the to_date on the request he turns his back in a date format...

    On my system, I realized that the time element is a factor. If I insert the date in the system as to_date (to_char(sysdate,'DD-MON-YY'),'DD - MON - YY') then everything works... (as likely Ive undress the time element.  (Which would be OK, but I want as well to the time element for any other purpose.)

    Also, if its related or contributing to I don't know, but it seems to select on the old records of the table...  When I restart the session and select an older date, they show up to... which is a little strange...

    When I looked at the content of the table (by unloading a txt file), some records is loaded with a time and others do not... They are all however, loaded with sysdate. Here is an example... (first column is the ID... some are loaded without time. other time.)

    1629, 2014-05 - 30 T 00: 00:00

    1630, 2014-05 - 30 T 00: 00:00

    1631, 2014-05 - 30 T 00: 00:00

    1632, 2014-05 - 30 T 00: 00:00

    1633, 2014-05 - 30 T 00: 00:00

    1634, 2014-05 - 30 T 00: 00:00

    1635, 2014-05 - 30 T 16: 14:17

    1636, 2014-05 - 30 T 16: 14:17

    1637, 2014-05 - 30 T 16: 14:17

    1638, 2014-05 - 30 T 16: 14:17

    Finally, I have one - show all - on the selectlist too. If I show everything, then update the record in the report (form tab) and set the date with the date picker, it seems also then to query OK when I update...

    ID be grateful if someone could help...

    Rgds

    Richard

    Hi Richard,

    Find out what I did with your application.  I changed the WHERE clause to:

    where created_date between to_date(:P7_SELECT_DATE,'DD-MON-YY') and to_date(:P7_SELECT_DATE,'DD-MON-YY') + .99999
    

    If I understand your condition, you select a day from the drop-down and you want to see the entries for that day.  Because you use a DATE data type, you want to check your created_date covers the full day.  You can do this in ajoutant.99999 (5 nine) to date.  It is the maximum resolution of a day without going over for the next day.  That means that you cover from 00:00:00 to 11:59:59 pm

    Does that help?  Or I read too quickly?

    I guess I have to explain that when you make an equal (=), which is the DATE must be exactly equal all the way at the same time.

    The other way to handle this is to truncate the time:

    When trunc (created_date) = to_date (: P7_SELECT_DATE, 'DD-MON-YY')

    Then both sides are identical with a time "anchored" in midnight 00:00:00

    Thank you

    -Jorge

  • HELLP needed to resolve the error



    Hello

    While running a package get the error below on a function call inside
    a function, I have bolded the error line. Can any help me to clear what is doing
    something wrong, please advice.

    Error: PLS-00201: identifier 'PRICE' must be declared


    FUNCTION process_client (p_bill_date IN VARCHAR2) RETURN WHOLE
    IS
    CURSOR c_flat_fees
    IS
    SELECT
    ES.client_id,
    NVL(es.customer_id, '000000000') AS customer_id,
    ES.schedule_id,
    . PRODUCT_TYPE,
    TO_CHAR (NVL (es.last_bill_date, TO_DATE (TO_CHAR (ADD_MONTHS (SYSDATE-1), "YYYYMM"), "YYYYMM")), "YYYYMM")
    AS last_bill_date,
    NVL (PT.) Description, ' ') as the description.
    NVL (PT.acctg_code, 4010) as acctg_code,
    PR. Price,
    PR.price_period,
    PR.price_period_unit,
    NVL (to_char (es.grace_period_end_date, 'YYYYMM'), ' 0') AS grace_period_end_date
    To era_client_schedule,
    PRODUCT_TYPE pt,
    price_schedule pr
    WHERE es.product_type = pt.product_type
    AND es.schedule_id = pr.schedule_id
    AND es.bill_code = 'A '.
    AND pr.price_type IN ('A', 'F', 'I' am ');

    r_flat_fees_cur c_flat_fees % rowtype;


    IF WRITE_INVOICE_item ( price*, 1) = - 1
    THEN
    RETURN RET_ERR;
    END IF;

    CLOSE C_flat_fees;

    EXCEPTION
    ........................

    END PROCESS_CLIENT;





    Thanks in advance.

    I don't see anywhere in your code that you assign a value to the variable PRICE. PRICE is always NULL, which seems strange.

    I think, since I do not understand your needs, is that you do not want to move in the PRICE of the C_FLAT_FEES cursor column. If you replace of hilighted with something like code

    IF write_invoice_item ( r_flat_fees.price, 1) = -1
    

    and get rid of the local variable total. Since you know of course how to refer to columns in the cursor in the loop, as you create VAR_LINE with the values of the cursor on the line immediately before, however, it is quite possible that my assumption is wrong.

    If you are trying to move in the PRICE of the C_FLAT_FEES cursor column, can you explain where you intend to get the value to WRITE_INVOICE_ITEM?

    Justin

  • query for tune

    Hi Master,

    I am not able to resolve this query. Because it is a such a huge request. Take the time when I run this. Please help me to write this query in an optimized way. It's very kind of you.

    SELECT payer_id_n, instance_id_n, lifecycle_type_n,

    payer_status_n, replenishment_id_n, start_date_dt,

    next_replenishment_date_dt, no_of_occurences_n,

    payer_repl_status_n, last_charge_start_date_dt,

    last_charge_end_date_dt, payer_repl_sequence_n,

    pr_row_id_r, tariff_id_n, charge_type_n,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 4)) AS occurrence_type_n,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 5)) AS occurrence_count_n,

    balance_option_n, repl_status_n,

    discount_multiplier_flag_n,

    TO_NUMBER (SUBSTR (gnl_extract_frm_cmd_str_fnc (slab_data, 1), 2)) AS start_period_n,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (slab_data, 2)) AS period_type_n,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (slab_data, 3)) AS interval_n,

    gnl_extract_frm_cmd_str_fnc (slab_data, 4) AS start_day_v,

    To_date (gnl_extract_frm_cmd_str_fnc (plan_data, 0), 'YYYYMMDDHH24MISS') AS plan_start_date_dt,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 1)) AS plan_id_n,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 2)) AS plan_type_n,

    TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 3)) AS repl_plan_status_n,

    debit_wallet_id_n, debit_units_n, debit_article_id_n,

    credit_wallet_id_n, credit_units_n, credit_cf_policy_n,

    credit_cf_limit_n, affect_validity_on_n,

    validity_period_type_n, validity_period_n,

    validity_extension_policy_n, credit_article_id_n,

    TO_NUMBER (SUBSTR (bill_cycle, 9)),.

    DECODE (ip_batch_count_n, 0, ROWNUM, MOD (ROWNUM, ip_batch_count_n)) AS process_batch_n

    FROM (SELECT pa.payer_id_n, pa.instance_id_n,

    PA.lifecycle_type_n, pa.payer_status_n,

    PRT.replenishment_id_n, prt.start_date_dt,

    PRT.next_replenishment_date_dt,

    PRT.no_of_occurences_n,

    PRT.status_n AS payer_repl_status_n,

    PRT.last_charge_start_date_dt,

    PRT.last_charge_end_date_dt,

    PRT.payer_repl_sequence_n,

    PRT. ROWID AS pr_row_id_r, rpl.tariff_id_n,

    RPL.charge_type_n, rpl.balance_option_n,

    RPL.status_n AS repl_status_n,

    RPL.discount_multiplier_flag_n,

    MAX (TO_CHAR (rp.start_date_dt,

    'YYYYMMDDHH24MISS '.

    )

    || '|'

    || To_char (100000 + rs.start_period_n)

    || '|'

    || RS.period_type_n

    || '|'

    || RS.interval_n

    || '|'

    || RS.start_day_v

    ) AS slab_data,

    MAX (TO_CHAR (rp.start_date_dt,

    'YYYYMMDDHH24MISS '.

    )

    || '|'

    || RP.plan_id_n

    || '|'

    || RP.plan_type_n

    || '|'

    || RP.status_n

    || '|'

    || RP.occurrence_type_n

    || '|'

    || RP.occurrence_count_n

    ) AS plan_data,.

    MAX (TO_CHAR (pbd.start_date_dt, 'YYYYMMDD')

    || PBD.bill_cycle_n

    ) AS bill_cycle

    PA, payers,

    payer_replenishment prt,

    replenishment_master rpl,

    replenishment_slabs rs,

    replenishment_plan rp,

    payer_bill_cycle_details pbd

    WHERE pa.instance_id_n BETWEEN ip_min_instance_id_n

    AND ip_max_instance_id_n

    AND pa.payer_id_n = prt.payer_id_n

    AND prt.status_n = crp_get_config_params.active_status

    AND prt.occurrence_completion_flag_n = repl_occurrence_ongoing

    AND prt.next_replenishment_date_dt < = TRUNC (ip_actual_sch_date_d)

    AND prt.replenishment_id_n = rpl.replenishment_id_n

    AND prt.event_request_no_n IS NULL

    AND NVL (prt. SCHEDULE_FLG_YN_V, 'Y') = 'Y' - added CR CC-99

    AND rp.replenishment_id_n = prt.replenishment_id_n

    AND rp.start_date_dt < = prt.next_replenishment_date_dt

    AND rp.status_n = crp_get_config_params.master_launched_status

    AND rs.replenishment_id_n = prt.replenishment_id_n

    AND rs.plan_id_n = rp.plan_id_n

    AND rs.start_period_n < = prt.no_of_occurences_n + 1

    AND pbd.payer_id_n = prt.payer_id_n

    AND pbd.start_date_dt < = prt.next_replenishment_date_dt

    AND pa.payer_status_n NOT IN (crp_get_config_params.waiting_payer_closure, crp_get_config_params.payer_closed)

    AND NOT EXISTS)

    SELECT 1

    OF payer_replenishment_schedules prs

    WHERE prs.payer_id_n = pa.payer_id_n

    AND prs.replenishment_id_n = prt.replenishment_id_n

    AND prs.status_n = crp_get_config_params.repl_retry)

    AND THERE ARE)

    SELECT 1

    OF payer_tariffs pt

    WHERE pt.payer_id_n = pa.payer_id_n

    AND pt.tariff_id_n = rpl.tariff_id_n

    AND pt.start_date_dt < = TO_DATE (TO_CHAR (prt.start_date_dt, 'YYYYMMDD') |) ("' 235959 ', ' YYYYMMDDHH24MISS ')

    AND pt.event_request_no_n IS NULL

    AND pt.status_n = crp_get_config_params.active_status)

    Pa.payer_id_n GROUP,

    PA.instance_id_n,

    PA.lifecycle_type_n,

    PA.payer_status_n,

    PRT.replenishment_id_n,

    PRT.start_date_dt,

    PRT.next_replenishment_date_dt,

    PRT.no_of_occurences_n,

    PRT.status_n,

    PRT.last_charge_start_date_dt,

    PRT.last_charge_end_date_dt,

    PRT.payer_repl_sequence_n,

    PRT. ROWID,

    RPL.tariff_id_n,

    RPL.charge_type_n,

    RPL.balance_option_n,

    RPL.status_n,

    RPL.discount_multiplier_flag_n),

    RA replenishment_attribute

    WHERE ((TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 4)) = 1))

    AND TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 5)) > no_of_occurences_n)

    OR (TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 4)) = 0)

    )

    )

    AND TO_NUMBER (gnl_extract_frm_cmd_str_fnc (plan_data, 1)) = ra.plan_id_n

    AND TO_NUMBER (SUBSTR (gnl_extract_frm_cmd_str_fnc (a.slab_data, 1), 2)) = ra.start_period_n;

    Concerning

    AR

    Known Devil (regular expression - Yes, it's time CPU...) But it suits your problem) is better than an unknown Angel (your function)

    You don't not tell/check if the query works at all the

    See you soon,.

    Manik.

  • A loop dynamic sql in the procedure

    Hi guys,.

    I'm having a procedure that will have two input start_date and end_date parameters

    I need a loop in alter procedure statement something like this using dynamic sql


    CHANGE TABLE M1

    SWAP PARTITION FOR (TO_DATE('01-JAN-2015','dd-MON-yyyy'))

    WITH TABLE T2

    INCLUDING THE INDEX;

    CHANGE TABLE M1

    BY EXCHANGE COMPETITION FOR (TO_DATE('02-JAN-2015','dd-MON-yyyy'))

    WITH TABLE T3

    INCLUDING THE INDEX;

    .

    .

    .


    For example I have dates in setting something like January 1, 2015-4 January 2015

    I need something like this, where T is a constant variable, I need to add T1, T2. T3 according to the dates of the range.

    Hello

    your procedure can not simply be rolled up, but the call session can be rolled up the output to a file.

    Try something like this

    col act_date noprint new_value act_date
    
    SET TERMOUT  OFF
    
    select to_char(sysdate, 'yyyy_mm_dd_hh24miss') act_date
      from dual;
    
    SET TERMOUT      ON
    set serveroutput on
    set feedback     off
    set linesize     3000
    
    col statement for a200 heading "-- alter statements"
    
    spool d:\temp\&act_date._&_CONNECT_IDENTIFIER._alter_partition.sql
    
    -- exec your_procedure
    
    -- or simple plain sql
    
    with data (start_date, end_date) as (
      select to_date('01/01/2016', 'dd/mm/yyyy'),
            to_date('05/01/2016', 'dd/mm/yyyy')
        from dual
        )
    select --level, to_char(start_date + (level - 1), 'dd-MON-yyyy' ) cur_date
                     'ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE(''' || to_char(start_date + (level - 1), 'dd-MON-yyyy' ) || ''',''dd-MON-yyyy'')) WITH TABLE T2 INCLUDING INDEXES;'
      || chr(10) ||  'ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE(''' || to_char(start_date + (level - 1), 'dd-MON-yyyy' ) || ''',''dd-MON-yyyy'')) WITH TABLE T3 INCLUDING INDEXES;'  as statement
      from data
    connect by level <= end_date - start_date + 1;
    
    spool off
    
    set feedback    on
    
    prompt @d:\temp\mk_alter.sql
    

    concerning
    Kay

  • DB procedure / function can return multiple values in a PL/SQL block

    Hi all


    I have a problem returning to the exit procedure following in PL/SQL because I have SELECT INTO variable but with no output back in my PL/SQL block even if I turned it into a function.


    . pls suggest.

    CREATE OR REPLACE PROCEDURE nominations (p_start_date AS, p_end_date IN DATE)

    IS

    v_day_id PLS_INTEGER;

    v_day_name VARCHAR2 (33);

    v_day_date DATE;

    BEGIN

    SELECT (2 + (p_start_date + (LEVEL - 1) + LEVEL - 1 - TRUNK (LEVEL - 1 + 1, "IW" + p_start_date)) AS day_id

    , TO_CHAR (LEVEL - 1, 'Day' + p_start_date) AS day_name

    , TO_CHAR (LEVEL - 1, "DD-MM-RRRR" + p_start_date) AS day_date

    IN v_day_id, v_day_name, v_day_date

    OF THE DOUBLE

    CONNECTION OF LEVEL < = 1 + p_end_date - p_start_date;

    END;

    /

    Your insert would be something like this:

    INSERT INTO PR_OPS_APPOINT_SETS (SPEC_CODE1, SPEC_CODE2, CLINIC_NO, SECTOR_ID, USER_ID, APPOINT_DATE)

    SELECT r.SPEC_CODE1, r.SPEC_CODE2, r.CLINIC_NO, r.SECTOR_ID, USER, d.APPOINT_DATE

    PR_OPS_CLINIC_RECS r

    CROSS JOIN)

    SELECT TO_DATE (TO_CHAR (LEVEL - 1, "MM/DD/RRRR" + p_start_date), "MM/DD/RRRR") AS APPOINT_DATE

    OF THE DOUBLE

    CONNECT BY LEVEL<= p_end_date="" -="" p_start_date="" +="">

    ) d

    WHERE SPEC_CODE1 = p_SPEC_CODE1

    AND SPEC_CODE2 = p_SPEC_CODE2

    AND CLINIC_NO = p_CLINIC_NO

    AND SECTOR_ID = P_SECTOR_ID;

    In terms of getting the parameters p_SPEC_CODE1, p_SPEC_CODE2, p_CLINIC_NO, P_SECTOR_ID...? I don't have enough information on your part.

  • a non-digit character was while digital was expected

    Hello


    I get the error from database when working with Oracle PLSQL code below.

    I come from a previous date Sunday in a variable and passing the date in the native dynamic SQL

    DECLARE
    v_sun_date DATE;
    v_sql varchar2(30);
    v_s1_date VARCHAR2(30);
    v_sql1  VARCHAR2(1000);
    v_date VARCHAR2(30);
    BEGIN
    
    
    --select to_char(next_day ( trunc (sysdate-5, 'iw') , 'Sunday'  ) ,'DD-MON-YY') into v_sun_date from dual;
    
    
    SELECT to_date(to_char(trunc(next_day(sysdate-5,'Sunday')),'MM/DD/YYYY'),'MM/DD/RRRR') into v_sun_date from dual;
    dbms_output.put_line('The sunday date is '||v_sun_date);
    
    
    --select TO_DATE(v_sun_date,'MM/DD/YYYY') into v_s1_date from dual;
    --dbms_output.put_line('The sunday date is '||v_s1_date);
    
    
    --v_sql := q'[drop table test_util]';
    --execute immediate v_sql;
    
    
    execute immediate q'[create table test_util as
    SELECT A.*
    From  HRBOSTF.TBL_STF_UTL_MAIN A, DIM_DATE
    where EMPLOYEE_NUMBER <> 'FILLER' and (A.PROVIDER_REGION = 'Own' or A.PROVIDER_REGION ='Inter SBU')
              and dim_date.Weekend_date <=  '||v_sun_date||'                             --to_date('11/01/2015','MM/DD/YYYY')  --- 1st feb sunday date
              and NVL(DIm_date.Note,'A') <> 'I'
              and COST_PA_PERIOD=DIm_date.Week_no
              and PROJECT_TYPE <> 'Public Holidays'
              and provdr_bu in ('CPRD','EUC','HTEC','IDS','MALS','CBS')
              and job_rank not in ('5 CN','05 SB','ZZ','NonEm','16','64 SU')
              and job_desc not in('Contractor', 'Supervising Associate')
              and job_class = 'CSS']';
    
    
    
    
    END;
    /
    

    If please appreciate your help and must pass the v_sun_date to immediate execution.

    Concerning

    What are you trying to do with this?

    To_date (to_char(some_date_expression,'MM/DD/YYYY'), ' DD/MM/RRRR')

    This is a verbose and inefficient way to TRUNC (some_date_expression), but your expression of date is already truncated so it is useless.

    Your problem however is that your immediate execution of the query compares Weekend_date with the literal string. v_sun_date | instead of the contents of the variable v_sun_date. The best solution would be to use a variable binding (although I agree with Paul that it is generally a bad idea to create tables on the fly like this):

    run immediately q'[create table test_util like

    SELECT A.*

    Of HRBOSTF. TBL_STF_UTL_MAIN A, DIM_DATE

    where EMPLOYEE_NUMBER <> 'FILL' and (A.PROVIDER_REGION = 'Clean') or A.PROVIDER_REGION = 'SBU Inter'

    and dim_date. Weekend_date <=> : 1

    and NVL (dim_date.note, 'A') <> 'I '.

    and COST_PA_PERIOD = DIm_date. Week_no

    and PROJECT_TYPE <> "holidays".

    and provdr_bu in ('SPCER', 'EUC', 'SACTH', 'ID', 'EVILS', 'CBS')

    and not job_rank ("' CN 5 ', '05', 'ZZ', 'NonEm' SB ', '16', ' SU 64 ')

    and not job_desc ("Entrepreneur", "supervision associated with")

    and job_class = 'CSS']'

    Using v_sun_date;

  • 12 hours to convert the time format to 24-hour time format

    Hello

    The following query does not work why?

    Select To_date ('10:35 PM', 'HH24:MI') From DUAL
    

    It gives the following error

    date format picture ends before converting all of the input string.

    but the following query works fine

    Select To_date ('10:35', 'HH24:MI') From DUAL


    I need to convert the format of the time in the first motion HH24 in PLSQL, how can I do this?

    Thank you


    Thank you youHH24:MI

    1 * Select To_date (' 22:35 ', ' Hh: mi AM "), TO_CHAR (To_date (' 22:35 ', ' HH: mi AM'), 'YYYY-MM-DD HH24:MI:SS') From DUAL

    SQL > /.

    TO_DATE (' TO_CHAR (TO_DATE('10))

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

    01-SEPT.-15 2015-09-01 22:35

Maybe you are looking for