ORA-01841

Hi expert,
I have two statement in my procedure :
r_period IN VARCHAR2
v_from_date date;
v_to_date date;
v_from_date := to_date('1/4/'||to_char(r_period),'dd/mm/yyyy');
v_to_date := to_date('31/3/'||to_char((to_number(r_period)-5)),'dd/mm/yyyy');
when I ran procedure , got following error message:
"ORA-01841 :(full) year must be between -4713 and +9999, and not be 0 "
appreciate very much if help me to resolve it.
Many Thanks,

Hi,
I can't re-produce the problem.
Whenever you have a problem, please post a complete test script that people can run to re-create the problem and test their ideas. In this case, include the complete procedure code (or a simplified version that has the same problem) and the code that you use to call it.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
918440 wrote:
Hi expert,
I have two statement in my procedure :
r_period IN VARCHAR2
v_from_date date;
v_to_date date;
v_from_date := to_date('1/4/'||to_char(r_period),'dd/mm/yyyy');
v_to_date := to_date('31/3/'||to_char((to_number(r_period)-5)),'dd/mm/yyyy');Usuaully, when people talk about dates "from x to y", x is earlier than y. You're setting v_from_date to be over 5 years later than v_to_date. That's not the cause of the ORA-01841 error, or any other Oracle error, but it is likely to confuse whoever has to maintain this code.
when I ran procedure , got following error message:
"ORA-01841 :(full) year must be between -4713 and +9999, and not be 0 "That's one of those error messages that actually means what it says. Apparantly, you're calling the procedure with a bad value for r_period. I can't say anthing more specific until you post a complete script.
Converting from NUMBERs to VARCHAR2s to DATEs is very error prone. Try to avoid doing so many conversions. For example, you're doing 3 data type conversions to compute v_from_date. You could get the same results with only 1 conversion, like this:
v_to_date   := ADD_MONTHS ( TO_DATE ( '31/3/' || r_period
                                          , 'DD/MM/YYYY'
                 , -5 * 12
                    );Personally, I would do it this way:
v_to_date   := ADD_MONTHS ( TRUNC ( TO_DATE (r_period, 'YYYY')
                      , 'YEAR'
                      ) - 1
                 , -57
                    );which also uses only 1 conversion, and that conversion is very simple. You can still get errors, including ORA-01841, if you pass a bad value for r_period, but the errors will be easier to find and fix.

Similar Messages

  • Regarding the error ORA-01841: (full) year must be between -4713 and +9999,

    The issue is the code is not inserting the good records into the MIE table. This is becasue of the error 'OtherError GFSTM_INS_SNURK_NEW_TABLES_PA.gfstm_ins_asn_journal_pr:ORA-01841: (full) year must be between -4713 and +9999, and not be 0' This error is throwing out because of space issue in dt_asn_shipped.
    My requirement is to log error if any if not get the next record in the loop and insert it in the table if it has no error. The issue is good records are not getting inserted. The snurk_cmms_crct018_asn_journl in the cursor is a synonym which uses dblionk to connect to the remote db. The dt_asn_shipped data type is char(6) and the format is YYMMDD.
    declare
    CURSOR cur_asn_journal IS
    SELECT NVL(TRIM(cd_asn_plant),' ') cd_asn_plant,
         NVL(TRIM(no_journal),0) no_journal,
    NVL(TRIM(cd_ship_from),' ') cd_ship_from,
         TRIM(no_asn) no_asn,
    DECODE(LENGTH(dt_asn_shipped),6, to_date(to_char(to_date(trim(dt_asn_shipped),'YYMMDD'),
    'DD-MON-YY'),'DD-MON-YY'), '') dt_asn_shipped,
    TRIM(dt_processed) dt_processed,
    TRIM(in_manual) in_manual,
         TRIM(ts_last_update) ts_last_update     
    FROM snurk_cmms_crct018_asn_journl;
    BEGIN
    FOR l_rec_asn_journal IN cur_asn_journal LOOP
    BEGIN
    INSERT INTO gfstmie_st_cmms_asn_journal
    gsdb_site_code ,
    journal_num,
    gsdb_site_from_code,
    adv_shipping_notice_cnum,
    adv_sn_shipping_date,
    processed_date,
    manual_in_code,
    cmms_last_update_cdate,
    create_userid,
    create_dts,
    update_userid,
    update_dts
    ) VALUES
    l_rec_asn_journal.cd_asn_plant,
    l_rec_asn_journal.no_journal,
    l_rec_asn_journal.cd_ship_from,
    l_rec_asn_journal.no_asn,
    l_rec_asn_journal.dt_asn_shipped,
    l_rec_asn_journal.dt_processed,
    l_rec_asn_journal.in_manual,
    l_rec_asn_journal.ts_last_update,
    g_con_user_id,
         l_dts_current_gmt,
    g_con_user_id,
    l_dts_current_gmt
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('l_num_exception_pt_7');
    --To assign value to error attributes
    l_str_email_body := GFSTU_MSG_CONTEXT_STACKER_PA.gfstu_add_msg_context_fn(
    SQLERRM || l_str_process_track,
    g_con_package_name || l_con_proc_name,
    g_con_string_null);
    l_rec_apm_error_attributes.job_run_sakey := l_num_job_run_id;
    l_rec_apm_error_attributes.proj_acronym_code := GFSTM_PARM_SPECIFICATION_PA.g_con_proj_acronym_code_ta;           
    l_rec_apm_error_attributes.module_code := l_con_module_code;
    l_rec_apm_error_attributes.notes_text := l_str_email_body;
    l_rec_apm_error_attributes.msg_id := GFSTM_PARM_SPECIFICATION_PA.g_con_msg_id_invalid_date;
    --Calling procedure to log and notify subscribers of transaction
    --related errors and informational messages
    GFSTM_COMMON_UTL_PA.gfstm_log_message_pr(
    SUBSTR(l_str_email_body,1,2000),
    g_con_string_null,
    g_con_string_null,
    SUBSTR(l_str_email_body,1,2000),
    l_rec_apm_error_attributes,
    g_con_string_null,
    l_num_wait_time,
    l_num_wait_interval_time,
    l_str_msg_action_code,
    l_num_oracle_error_code,
    l_str_oracle_msg,
    l_num_return_code,
    l_num_status);
    END;
    END LOOP;
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('l_num_exception_pt_12');
    DBMS_OUTPUT.PUT_LINE('l_num_exception_pt_2 '||l_str_procg_mode_code);
    --Rollback uncommitted transactions
    ROLLBACK;
    --Assigning failure status
    o_num_status := g_con_status_failure;
    --Assigning procedure end time in GMT
    l_dts_end_time := GFSTU_DATETIME_UTILITIES_PA.gfstu_to_gmt_fn;
    --To assign value to error attributes
    l_str_email_body := GFSTU_MSG_CONTEXT_STACKER_PA.gfstu_add_msg_context_fn(
    SQLERRM || l_str_process_track,
    g_con_package_name || l_con_proc_name,
    g_con_string_null);
    l_rec_apm_error_attributes.job_run_sakey := l_num_job_run_id;
    l_rec_apm_error_attributes.proj_acronym_code := GFSTM_PARM_SPECIFICATION_PA.g_con_proj_acronym_code_ta;           
    l_rec_apm_error_attributes.module_code := l_con_module_code;
    l_rec_apm_error_attributes.notes_text := l_str_email_body;
    l_rec_apm_error_attributes.msg_id := GFSTM_PARM_SPECIFICATION_PA.g_con_msg_id_oracle;
    --Calling procedure to log and notify subscribers of transaction
    --related errors and informational messages
    GFSTM_COMMON_UTL_PA.gfstm_log_message_pr(
    SUBSTR(l_str_email_body,1,2000),
    g_con_string_null,
    g_con_string_null,
    SUBSTR(l_str_email_body,1,2000),
    l_rec_apm_error_attributes,
    g_con_string_null,
    l_num_wait_time,
    l_num_wait_interval_time,
    l_str_msg_action_code,
    l_num_oracle_error_code,
    l_str_oracle_msg,
    l_num_return_code,
    l_num_status);
    --Calling procedure to update the job status
    GFSTM_COMMON_UTL_PA.gfstm_update_job_status_pr(
    l_num_job_run_id,
    GFSTM_PARM_SPECIFICATION_PA.g_con_process_abort,
    l_dts_end_time,
    g_con_perf_metric_code,
    g_con_zero,
    g_con_n,
    l_num_oracle_error_code,
    l_str_oracle_msg,
    l_num_return_code,
    l_num_status);
    END ;
    Thanks,
    Vinodh

    Hi,
    Could you not have reduced your question to what is relevant?
    You seem to be saying that this is your problem:
    SELECT DECODE ( LENGTH (dt_asn_shipped),
              6,
              TO_DATE ( TO_CHAR ( TO_DATE ( TRIM (dt_asn_shipped), 'YYMMDD'), 'DD-MON-YY'), 'DD-MON-YY'),
             dt_asn_shipped
    FROM   snurk_cmms_crct018_asn_journl;As far as I can see, problem might be that you decode on UNTRIMMED length.
    Also, you could get rid of some the to_date(to_char(to_date), which is nothing more than simply to_date()
    Try something like
    SELECT CASE LENGTH (TRIM (dt_asn_shipped))
             WHEN 6 THEN TO_DATE ( TRIM (dt_asn_shipped), 'YYMMDD')
           END
             dt_asn_shipped
    FROM   snurk_cmms_crct018_asn_journl;Regards
    Peter

  • Error ORA-01841: (full) year must be between -4713 and +9999, and not be 0

    Hi Experts,
    I seem to be getting the error "Error ORA-01841: (full) year must be between -4713 and +9999, and not be 0" when my dates are in the year 2000. Here's my SQL:
    DROP TABLE PER_ALL_ASSIGNMENTS_M_XTERN;
    create table PER_ALL_ASSIGNMENTS_M_XTERN(
    PERSON_NUMBER                    VARCHAR2(30 CHAR),
    ASSIGNMENT_NUMBER VARCHAR2(30 CHAR),
    EFFECTIVE_START_DATE                DATE,
    EFFECTIVE_END_DATE           DATE,
    EFFECTIVE_SEQUENCE           NUMBER(4),
    ASS_ATTRIBUTE_CATEGORY           VARCHAR2(30 CHAR),
    ASS_ATTRIBUTE1 VARCHAR2(150 CHAR),
    ASS_ATTRIBUTE_NUMBER20 NUMBER,
    ASS_ATTRIBUTE_DATE1 DATE,
    ASS_ATTRIBUTE_DATE2 DATE,
    ASS_ATTRIBUTE_DATE3 DATE,
    ASS_ATTRIBUTE_DATE4 DATE,
    ASS_ATTRIBUTE_DATE5 DATE,
    ASS_ATTRIBUTE_DATE6 DATE,
    ASS_ATTRIBUTE_DATE7 DATE,
    ASS_ATTRIBUTE_DATE8 DATE,
    ASS_ATTRIBUTE_DATE9 DATE,
    ASS_ATTRIBUTE_DATE10 DATE,
    ASS_ATTRIBUTE_DATE11 DATE,
    ASS_ATTRIBUTE_DATE12 DATE,
    ASS_ATTRIBUTE_DATE13 DATE,
    ASS_ATTRIBUTE_DATE14 DATE,
    ASS_ATTRIBUTE_DATE15 DATE,
    ASG_INFORMATION_CATEGORY           VARCHAR2(30 CHAR),
    ASG_INFORMATION1 VARCHAR2(150 CHAR),
    ASG_INFORMATION_NUMBER20 NUMBER,
    ASG_INFORMATION_DATE1 DATE,
    ASG_INFORMATION_DATE2 DATE,
    ASG_INFORMATION_DATE3 DATE,
    ASG_INFORMATION_DATE4 DATE,
    ASG_INFORMATION_DATE5 DATE,
    ASG_INFORMATION_DATE6 DATE,
    ASG_INFORMATION_DATE7 DATE,
    ASG_INFORMATION_DATE8 DATE,
    ASG_INFORMATION_DATE9 DATE,
    ASG_INFORMATION_DATE10 DATE,
    ASG_INFORMATION_DATE11 DATE,
    ASG_INFORMATION_DATE12 DATE,
    ASG_INFORMATION_DATE13 DATE,
    ASG_INFORMATION_DATE14 DATE,
    ASG_INFORMATION_DATE15 DATE
    organization external
    ( default directory APPLCP_FILE_DIR
    access parameters
    ( records delimited by newline skip 1
         badfile APPLCP_FILE_DIR:'PER_ALL_ASSIGNMENTS_M_XTERN.bad'
    logfile APPLCP_FILE_DIR:'PER_ALL_ASSIGNMENTS_M_XTERN.log'
    fields terminated by ',' OPTIONALLY ENCLOSED BY '"'
    (PERSON_NUMBER,     
    ASSIGNMENT_NUMBER,
    EFFECTIVE_START_DATE CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    EFFECTIVE_END_DATE CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    EFFECTIVE_SEQUENCE,
    ASS_ATTRIBUTE_CATEGORY,
    ASS_ATTRIBUTE1,
    ASS_ATTRIBUTE_NUMBER20,
    ASS_ATTRIBUTE_DATE1 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE2 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE3 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE4 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE5 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE6 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE7 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE8 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE9 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE10 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE11 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE12 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE13 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE14 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASS_ATTRIBUTE_DATE15 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_CATEGORY,
    ASG_INFORMATION1,
    ASG_INFORMATION_NUMBER20,
    ASG_INFORMATION_DATE1 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE2 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE3 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE4 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE5 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE6 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE7 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE8 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE9 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE10 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE11 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE12 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE13 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE14 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    ASG_INFORMATION_DATE15 CHAR(20) DATE_FORMAT DATE MASK "DD-MON-YYYY"
    location ('PER_ALL_ASSIGNMENTS_M.csv')
    REJECT LIMIT UNLIMITED;
    ...and getting errors when data looks like the following:
    E040101,EE040101,*1-Aug-2000*,31-Dec-4712,1,,NDVC,YES,DE,SFC,N,STIP Plan - Pressure,,,,,,,E040101,,,,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,,,,,,,,31113,31113,31113,31113,31113,31113,,,1-Jan-2012,31-Dec-2012,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ...error message:
    error processing column EFFECTIVE_START_DATE in row 19 for datafile /u05/dbadir/jmf/incident_logs/PER_ALL_ASSIGNMENTS_M.csv
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    Thanks,
    Thai

    Here is a snippet of the bad file data:
    E040110,EE040110,01-Aug-00,31-Dec-12,1,,NDVC,YES,DE,SFC,N,STIP Plan - Pressure,,,,,,,E040110,,,,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,,,,,,,,27667.2,27667.2,27667.2,27667.2,27667.2,27667.2,,,01-Jan-12,31-Dec-12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    E040100,EE040100,01-May-00,31-Dec-12,1,,NDVC,YES,DE,SFC,N,STIP Plan - Pressure,,,,,,,E040100,,,,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,,,,,,,,31113,31113,31113,31113,31113,31113,,,01-Jan-12,31-Dec-12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    E040101,EE040101,01-Aug-00,31-Dec-12,1,,NDVC,YES,DE,SFC,N,STIP Plan - Pressure,,,,,,,E040101,,,,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5,,,,,,,,,,,,31113,31113,31113,31113,31113,31113,,,01-Jan-12,31-Dec-12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    E000916,EE000916,01-Oct-00,31-Dec-12,1,,NDVC,YES,NL,SFC-Commercial,E,SIP Plan - Control Technologies,,,,,,,E000916,21000000,555000,99000,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,10,,,,,,,,,,,,34905.65,34905.65,34905.65,34905.65,34905.65,34905.65,,,01-Jan-12,31-Dec-12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    E000807,EE000807,03-Jan-00,31-Dec-12,1,,NDVC,YES,FR,SFC-Commercial,E,STIP Plan - Cross BU,,,,,,,E000807,,,,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,,,,,,,,,,,,35448.56,35448.56,35448.56,35448.56,35448.56,35448.56,,,01-Jan-12,31-Dec-12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    E000851,EE000851,25-Apr-00,31-Dec-12,1,,NDVC,YES,FR,SFC-Commercial,E,SIP Plan - Control Technologies,,,,,,,E000851,21000000,555000,99000,2080,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,13,,,,,,,,,,,,43283.76,43283.76,43283.76,43283.76,43283.76,43283.76,,,01-Jan-12,31-Dec-12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    So, the successfully loaded data is being loaded where year=2003 in the CSV as year=0003. Even though the data is loaded fine the data is not correct. For some reason the external table is set to have the year truncated.

  • ORA-01841 when refreshing materialized view

    Hi,
    I have to upgrade my database from oracle 8.1.7.4 to 9.2.0.1.
    I have tested two ways to do it :
    1) I upgraded my database from 8i to 9i with the u0801070.sql script.
    2) I created an empty 9i database and then I exported the data from the 8i database and imported them to the 9i database.
    The two procedures worked fine.
    But now, when I try to refresh the mateiralized views with DBA Studio on the database upgraded via export/import, I obtain the error : ORA-01841.
    On the database upgraded via u0801070.sql, I don't have the problem.
    Why do I have this error ?
    Regards,
    Rachel TREBUCHET DANJOU

    Error: ORA 1841
    Text: (full) year must be between -4713 and +4713 / +9999
    Cause:
    Action:
    *** Important: The notes below are for experienced users - See Note 22080.1
    Explanation:
         Eg: In a clause like "to_date('XXXX','YYYY')" XXXX is outside of the
         range -4713 and +4713.
         Note that Year 0 is invalid too. See Bug 106242 for an explanation..
         Typically this involves "to_date('00','YYYY')" or similar which is
         invalid. It is probably better to use 'RR' rather than 'YY' which
         prefixes with an appropriate century.
         Eg:
              select to_char(to_date('00','yyyy')) from dual;
              ORA-01841: (full) year must be between -4713 and +4713
              select to_char(to_date('00','rr')) from dual;
              01-MAR-2000
    Year 2000
    ~~~~~~~~~
    You may also see this error if using a TO_DATE() function
    on a date column (or SYSDATE) and your sessions NLS_DATE_FORMAT
    includes a 2 digit year mask (RR or YY).
    eg: alter session set nls_date_format='DD-MON-RR';
    select to_date(sysdate,'DD-MON-YYYY') from dual;
    "ORA-01841: (full) year must be between -4713 and +9999, and not be 0"
    This is because TO_DATE() expects to work on a CHARACTER
    data type and so there is an implicit conversion from
    DATE to CHAR.
    eg: In the above example SYSDATE of 01-JAN-2000 is implictly
    converted to the character string "01-JAN-00", which is
    then converted back to a date using a DD-MON-YYYY date format.
    This gives a year of 0000 which is invalid, hence ORA-1841.
    Note:     From Oracle 7.2 onwards the UPPER bound is +9999 and not +4713
    Regards,
    Reza

  • ORA-01841 Error when value for date col is NULL in .dat (using SQL Loader)

    Hello Gurus,
    I have some data in .dat file which needs to be loaded into oracle table. I am using SQL * Loader to do the job. Although "NULLIF col_name =BLANKS" works for character datatype, but when value for date col is NULL then I get ORA-01841 error. I have to make NULL for all rows withour value for date column
    Early reply will be highly appreciated
    Farooq

    Hi,
    May be this problem is not with the NULLIF. The value for the date column is not in proper date format.
    create table:
    create table kk (empno number, ename varchar2(20), deptno number, hiredate date)
    Control file:
    LOAD DATA
    INFILE 'd:\kk\empdata.dat'
    insert into TABLE kk ( empno position (1:2) integer external,
    ename position(4:5) char NULLIF ename=BLANKS,
    deptno position (7:8) integer external NULLIF deptno=BLANKS,
    hiredate position (10:20) date NULLIF hiredate=BLANKS)
    data file:
    10 KK 01-jan-2005
    20 10
    SELECT * FROM KK;
    EMPNO ENAME DEPTNO HIREDATE
    10 KK 01-JAN-05
    20 10
    Verify the data file.
    Hope it will help

  • ORA-01841 Converting SQL Server DateTime to Oracle Date

    I have Oracle 11gR2 x64 running on my Win7 Enterprise x64 personal system. I'm trying to convert the TSQL to create a database in SQL Server 2008 Express for my C# class to Oracle, and I've run into a "interesting" problem loading date data.
    The SQL Server 2008 TSQL InvoiceDate column in the Invoices table has datatype DATETIME:
    *[InvoiceDate] [datetime] NOT NULL,*
    which Oracle does not support. The Oracle InvoiceDate column in the MMAB_Invoices table has datatype DATE:
    InvoiceDate DATE NOT NULL,
    The fun begins with the TSQL INSERT statements (for example):
    INSERT [dbo].[Invoices] ([InvoiceID], [CustomerID], [InvoiceDate], [ProductTotal], [SalesTax], [Shipping], [InvoiceTotal]) VALUES (18, 20, CAST(0x00009CFD00000000 AS DateTime), 151.0000, 11.3300, 6.2500, 168.5800)
    As you can see, whoever wrote the load script thought it would be totally awesome to convert hex (binary?) data to generate a date, instead of using data readable by a human being.
    BTW, the date generated is 2010-01-13 00:00:00.000.
    After Reading The Fabulous Manual and searching the OTN Discussion Fora, what I came up with is
    INSERT INTO MMAB_Invoices (CustomerID, InvoiceDate, ProductTotal, SalesTax, Shipping, InvoiceTotal) VALUES (20, TO_DATE(UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000')), 'YYYY-MM-DD HH:MI:SS'), 151.0000, 11.3300, 6.2500, 168.5800);
    which returned
    Error starting at line 846 in command:
    INSERT INTO MMAB_Invoices (CustomerID, InvoiceDate, ProductTotal, SalesTax, Shipping, InvoiceTotal) VALUES (20, TO_DATE(UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000')), 'YYYY-MM-DD HH:MI:SS'), 151.0000, 11.3300, 6.2500, 168.5800)
    Error report:
    SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    *01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"*
    **Cause: Illegal year entered*
    **Action: Input year in the specified range*
    The PK InvoiceID is automatically generated by a BEFORE INSERT trigger that uses a sequence.
    Suggestions?
    Thanks.
    P.S. Happy New Year!!!

    Your hex conversion is certainly not returning a date format:
    sql> select UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000')) from dual;
    UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW('00009CFD00000000'))
      ┐²To convert the hex number to decimal, simply use to_number:
    sql> select to_number('00009CFD00000000', 'xxxxxxxxxxxxxxxx') from dual;
    TO_NUMBER('00009CFD00000000','XXXXXXXXXXXXXXXX')
                                          1.7261E+14Now, before you can make any further calculations with that number, you need to know how it represents the date of 2010-01-13. Luckily, we've got Google nowadays. ;-)
    Sql server representation seems to be an 8 byte field. The first 4 bytes stores the number of days since SQL Server's epoch (1st Jan 1900). The second 4 bytes stores the number of milliseconds after midnight.
    sql> select to_number('00009CFD', 'xxxxxxxxxxxxxxxx') from dual;
    TO_NUMBER('00009CFD','XXXXXXXXXXXXXXXX')
                                       40189
    sql> select to_date('1900-01-01','yyyy-mm-dd') + 40189 from dual;
    TO_DATE('
    13-JAN-10So, the conversion would be something like this:
    sql> select to_date('1900-01-01','yyyy-mm-dd') + to_number(substr('00009CFD00000000',1,8), 'xxxxxxxx') + to_number(substr('00009CFD00000000',9,8), 'xxxxxxxx') / (24*60*60*1000) from dual;
    TO_DATE('
    13-JAN-10Note: Oracle DATE format specifies a datetime up to the second, whereas the sqlserver DATETIME format specifies a datetime up to the millisecond; if that precision is needed, use Oracle's TIMESTAMP instead.
    Note: using an internal representation is risky, implementation details may change. In this case, it seems pretty unlikely that Microsoft will ever change the datetime internal representation, since that would break lots and lots of code.
    Edited by: theoa on 2-jan-2012 9:14

  • Application Express 4.0.1.00.03 -   ORA-01841 error when attempting to edit

    I am logged into a development workspace and am able to add new users in HOME|ADMINISTRATION|USERS but when I try to edit them afterward I get the following error:
    Application Express Users
    ORA-01841: (full) year must be between -4713 and 9999, and not be 0+
    Obviously APEX is looking for a date value and not finding it. Anyone else encounter this or know where to look to resolve this? I got the same error in APEX 4.0 so the patch didn't resolve this error. I've done some research in the tables but couldn't find anything that looked like a missing date value.
    I'm using an 11gR2 database on OEL 5.5 running in VBOX on my laptop.
    Thanks.
    Rob

    FIX:
    Cause
    The issue appears due to a problem with the PASSWORD_LIFE_TIME.
    Solution
    Using the apex_admin application, navigate to Home > Manage Service > Security then enter integer values for:
    * Account Password Lifetime (days) - enter 11688, for example
    Apply Changes.
    Looks like it is a bug in apex 4.0 which has also affected previous versions (known about since version 1.5)........

  • FRM-40735:when-button-pressed trigger raised unhandled exception ORA-01841

    hello to all
    i m getting this error FRM-40735: when-button-pressed trigger raised unhandled exception ORA-01841
    and the trigger i had written is like this:-
    DECLARE
         CURSOR I IS SELECT SANCDATE,REFNO,PRINCIPALAMT,SANCAMT,TOTINSTALMENT,RATERECOVERY,AMTRECOVERED,INSTALMENTRECOVERED,
         STARTYEARMM,ENDYEARMM
         FROM PRMALOAN
         WHERE EMPNO=:PRMALOAN.EMPNO
         AND EARNINGDEDUCTION=:PRMALOAN.EARNINGDEDUCTION
         AND PAYCALPERIOD IS NULL;
         d date:=to_date('200908','yyyymm');
         s date;
         e date;
    BEGIN
         go_block('prmaloan2');
         OPEN I;
         LOOP
              FETCH I INTO :PRMALOAN2.SANCDATE,:PRMALOAN2.REFNO,:PRMALOAN2.PRINCIPALAMT,:PRMALOAN2.SANCAMT,:PRMALOAN2.TOTINSTALMENT,
              :PRMALOAN2.RATERECOVERY,:PRMALOAN2.AMTRECOVERED,:PRMALOAN2.INSTALMENTRECOVERED,:PRMALOAN2.STARTYEARMM,:PRMALOAN2.ENDYEARMM;
              s:=to_date(':prmaloan2.startyearmm','yyyymm');
              e:=to_date(':prmaloan2.endyearmm','yyyymm');
              if
                   e is null
                                  then
                   :prmaloan2.TEXT_ITEM164:=months_between(d,s);
              exit when I%notfound;
    next_record;
    end if;
         end loop;
         close I;
         END;
    plz help me to remove this error

    this is the description of my table:-
    desc prmaloan
    Describing prmaloan....
    NAME Null? Type
    EMPNO NOT NULL VARCHAR2(8)
    EARNINGDEDUCTION NOT NULL VARCHAR2(6)
    REFNO NOT NULL VARCHAR2(15)
    SANCDATE NOT NULL DATE
    PRINCIPALAMT NUMBER(8,0)
    SANCAMT NUMBER(8,0)
    RATERECOVERY NUMBER(5,0)
    TOTINSTALMENT NUMBER(3,0)
    AMTRECOVERED NUMBER(8,0)
    INSTALMENTRECOVERED NUMBER(3,0)
    STARTYEARMM VARCHAR2(6)
    ENDYEARMM VARCHAR2(6)
    CHANGEDATE DATE
    USERID VARCHAR2(30)
    PAYCALPERIOD VARCHAR2(6)

  • ORA-01841 - (full) year must be between -4713 and +9999, and not be 0

    Hi Comunnity,
    Let me explain the scenario:
    We want to replicate a number of Discoverer reports, adding more columns to the reports. Due to the internal structure of the views and materialized tables, we can not make the joins inside the Discoverer Administration Edition, so we have decided to replicate the original materialized table adding the columns in order to get what we want. So the new materialized table has built as follows:
    CREATE TABLE APPS.GUZMAN_STOCK_DEPRE_EXIST_MAT_X
    EMPRESA VARCHAR2(240 BYTE),
    COD_ORGANIZACION NUMBER,
    COD_SECCION VARCHAR2(40 BYTE),
    SECCION VARCHAR2(4000 BYTE),
    FAMILIA VARCHAR2(40 BYTE),
    NOMBRE_PRODUCTO VARCHAR2(240 BYTE),
    DESCRIPCION_ARTICULO VARCHAR2(240 BYTE),
    UNIDAD_EXISTENCIA_ACT NUMBER,
    PRECIO_MEDIO NUMBER,
    FECHA_ULT_VENTA DATE,
    FECHA_ULT_COMPRA DATE,
    FECHA_ULT_MOVIMIENTO DATE,
    PRECIO_ULT_COMPRA NUMBER,
    CLASE_UNIDAD VARCHAR2(40 BYTE),
    COD_ORG_INV NUMBER,
    ORG_INV_NAME VARCHAR2(240 BYTE),
    COD_ARTICULO NUMBER,
    AÑO VARCHAR2(2 BYTE),
    MES VARCHAR2(2 BYTE),
    ULTIMO_DIA_TRANS DATE,
    SEIS_MESES_ANTES DATE,
    DOCE_MESES_ANTES DATE,
    DIECIOCHO_MESES_ANTES DATE,
    SEIS_MESES NUMBER,
    SIETE_DOCE_MESES NUMBER,
    TRECE_DIECIOCHO_MESES NUMBER,
    FCOMVACIA NUMBER,
    TIPO_ARTICULO VARCHAR2(80 BYTE),
    TRANSACTION_ID NUMBER,
    FECHA_MOVIMIENTO DATE,
    TIPO_MOVIMIENTO VARCHAR2(80 BYTE)
    TABLESPACE APPLSYSD
    PCTUSED 40
    NOMONITORING;
    The bold fields are the new ones. So we added the materialized table as a new folder in our working business area and add the following new intems:
    Valor Compra = CASE WHEN Precio Ult Compra = 0 THEN Importe Stocks ELSE Unidad Existencia Act*Precio Ult Compra END
    Importe Stocks = Unidad Existencia Act*Precio Medio
    Depreciación = CASE WHEN Valor Compra < Importe Stocks THEN Importe Stocks-Valor Compra ELSE 0 END
    DiasMes = CASE WHEN ((((((Mes = '01' OR Mes = '03') OR Mes = '05') OR Mes = '07') OR Mes = '08') OR Mes = '10') OR Mes = '12') THEN 31 WHEN (((Mes = '04' OR Mes = '06') OR Mes = '09') OR Mes = '11') THEN 30 ELSE 28 END
    fecha_MES = TO_NUMBER(CONCAT(DiasMes,Mes))
    Nueva_Fecha = TO_DATE(CONCAT(fecha_MES,Ano))
    Dias = NVL(Nueva_Fecha-Fecha Ult Venta,0)
    PorcenDepre = CASE WHEN Dias = 0 AND DiasC < 181 THEN 0 WHEN Dias = 0 AND DiasC > 180 THEN 100 WHEN Dias < 181 THEN 0 WHEN Dias < 361 THEN 25 WHEN Dias < 540 THEN 50 WHEN Dias > 541 THEN 100 ELSE 0 END
    Valor Depr = Valor Compra*PorcenDepre/100
    DiasC = NVL(Nueva_Fecha-Fecha Ult Compra,0)
    PorcenDepreC = CASE WHEN DiasC = 0 THEN 100 WHEN DiasC < 181 THEN 0 WHEN DiasC < 361 THEN 25 WHEN DiasC < 540 THEN 50 WHEN DiasC > 541 THEN 100 ELSE 0 END
    Valor DepreC = Valor Compra*PorcenDepreC/100
    T6 = CASE WHEN Unidad Existencia Act >= SEISMESES THEN SEISMESES ELSE Unidad Existencia Act END
    T12 = CASE WHEN Unidad Existencia Act-T6 > DOCEMESES THEN DOCEMESES WHEN Unidad Existencia Act-T6 < DOCEMESES THEN Unidad Existencia Act-T6 WHEN Unidad Existencia Act-T6 = DOCEMESES THEN Unidad Existencia Act-T6 END
    T18 = CASE WHEN Unidad Existencia Act-( T6+T12 ) > DIECIOCHOMESES THEN DIECIOCHOMESES WHEN Unidad Existencia Act-( T6+T12 ) < DIECIOCHOMESES THEN Unidad Existencia Act-( T6+T12 ) WHEN Unidad Existencia Act-( T6+T12 ) = DIECIOCHOMESES THEN Unidad Existencia Act-( T6+T12 ) END
    TR = Unidad Existencia Act-( T6+T12+T18 )
    DT6 = T6*Precio Medio*0/100
    DT12 = ( T12*Precio Medio )*25/100
    DT18 = T18*Precio Medio*50/100
    DTR = TR*Precio Medio*100/100
    DTOTAL = DT6+DT12+DT18+DTRVCIA+DFCOMPVCIA
    SEISMESES = CASE WHEN NVL(Seis Meses,0) < 0 THEN 0 ELSE NVL(Seis Meses,0) END
    DOCEMESES = CASE WHEN NVL(Siete Doce Meses,0) < 0 THEN 0 ELSE NVL(Siete Doce Meses,0) END
    DIECIOCHOMESES = CASE WHEN NVL(Trece Dieciocho Meses,0) < 0 THEN 0 ELSE NVL(Trece Dieciocho Meses,0) END
    FCOMPVCIA = DECODE(Fecha Ult Compra,NULL,Unidad Existencia Act,0)
    TRVCIA = TR-FCOMPVCIA
    DTRVCIA = TRVCIA*Precio Medio*100/100
    DFCOMPVCIA = FCOMPVCIA*Precio Medio*100/100
    Due to Discoverer does not allow foreign characters (ñ), we have changed the name of Field Año to Ano (as you can check in the Nueva_Fecha calculated field).
    Now, when we select the fields (Empresa, Cod Sección, Nombre Producto, Unidad Existencia Act, Precio Medio, Fecha Ult Venta, Fecha Ult Compra, Fecha Ult Movimiento, Precio Ult Compra, Org Inv Name, Ano, Mes, Valor Compra, Importe Stocks, Depreciación, Dias, PorcenDepre, Valor Depr, DiasC, PorcenDepreC, ValorDepreC) in order to build a new report, Discoverer shows us the ORA-01841 Error.
    Can be produced the error by the way in which discoverer stores the Nueva_Fecha Field?, cause as we check the field in Adminostration Edition, it appears as TO_DATE(CONCAT(fecha_MES,'Ano')) (with the field Ano in simple quotes), or just by any other circumstance?
    Thanks a lot for your help.
    Luis.
    Update:*
    It seems that the problem comes with the item created in Discoverer Administration Edition "Nueva_Fecha":
    Nueva_Fecha = TO_DATE(CONCAT(fecha_MES,Ano))
    (Keep in mind that:
    fecha_MES = TO_NUMBER(CONCAT(DiasMes,Mes))
    DiasMes = CASE WHEN ((((((Mes = '01' OR Mes = '03') OR Mes = '05') OR Mes = '07') OR Mes = '08') OR Mes = '10') OR Mes = '12') THEN 31 WHEN (((Mes = '04' OR Mes = '06') OR Mes = '09') OR Mes = '11') THEN 30 ELSE 28 END
    ), so any created field that uses Nueva_Fecha or is derivated from Nueva_Fecha causes the error (e.g. --> Dias = NVL(Nueva_Fecha-Fecha Ult Venta,0))
    Then; How can we configure the field in order that discoverer deals with it as a date field?
    Regards,
    Luis.
    Edited by: GGOracle User on 27-may-2010 15:23

    Hi,
    I think you forgot the separator in the string you want to convert to date.
    Your problem lies in the format of the date you are trying to create.
    try
    Nueva_Fecha = TO_DATE(DiasMes||'-'||Mes||'-'||Ano ,'DD-MM-YYYY')
    BTW
    you can use || instead of CONCAT so that you can concatenate more than 2 values each time
    Tamir

  • [Sorted] ORA-01841 - date problem

    I must be doing something stupid here, but for the life of me, I can't work out what it is! I'm on 10.2.0.2
    I have a partitioned table that has partitions named PART_<YYYYMMDD> (eg. PART_20070618) or PART_MAX (for the catchall partition).
    I've written a query to try and find the partition that's greater than a specified date, so I can work out what partition to split in my partition upkeep procedure.
    (This is the test version of the query - in the procedure the table_name and the date comparison will be variables)
        SELECT 'PART_'||to_char(MIN(TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd')), 'yyyymmdd')
        FROM   (select partition_name
                from   all_tab_partitions
                WHERE  table_name = UPPER('task_archive')
                AND    partition_name <> 'PART_MAX')
        WHERE   TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd') > trunc(to_date('20070618', 'yyyymmdd'))This gives the error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    However, taking off the last WHERE clause gives this:
        SELECT 'PART_'||to_char(MIN(TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd')), 'yyyymmdd')
        FROM   (select partition_name
                from   all_tab_partitions
                WHERE  table_name = UPPER('task_archive')
                AND    partition_name <> 'PART_MAX')
    'PART_'||TO_CHAR(MIN(TO_DATE(SUBSTR(PARTITION_NAME,6),'YYYYMMDD')),'YYYYMMDD')
    PART_20070604And the inner query gives this:
                select partition_name
                from   all_tab_partitions
                WHERE  table_name = UPPER('task_archive')
                AND    partition_name <> 'PART_MAX'
    PARTITION_NAME
    PART_20070604
    PART_20070611
    PART_20070618Can anyone spot what it is that I've done wrong, please?!

    Heh, yes, I did rewrite the query due to receiving the error initially. I've gone down the same route as you and couldn't get it to work.
    I've just pasted your query in and run it, and same error occurs. Then I thought perhaps it's a Toad-ism, somewhere, but sqlplus gives the same error:
    SQL>     SELECT 'PART_'|| to_char(MIN( part_date ), 'yyyymmdd')
      2      FROM   (select partition_name, TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd') part_Date
      3              from   all_tab_partitions
      4              WHERE  table_name = UPPER('task_archive')
      5              AND    partition_name <> 'PART_MAX')
      6      WHERE   part_date > to_date('20070618', 'yyyymmdd')
      7 
    SQL> /
        FROM   (select partition_name, TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd') part_Date
    ERROR at line 2:
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0I'm pretty sure Oracle's rewriting the query somehow, but I'm not sure how to stop it, given that the materialize hint isn't working:
      1      SELECT 'PART_'|| to_char(MIN( part_date ), 'yyyymmdd')
      2      FROM   (select /*+ materialize */ partition_name, TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd')
      3              from   all_tab_partitions
      4              WHERE  table_name = UPPER('task_archive')
      5              AND    partition_name <> 'PART_MAX')
      6*     WHERE   part_date > to_date('20070618', 'yyyymmdd')
    SQL> /
        FROM   (select /*+ materialize */ partition_name, TO_DATE(SUBSTR(partition_name, 6), 'yyyymmdd')
    ERROR at line 2:
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0

  • Ora-01841 returned

    Hi,
    ***Condition***
    - Table1 has
    [field1] : varchar2 (20)
    (data: '20110301', '20110302', ... (No null values))
    - View2 has
    [date1]: to_date(Table1.field1, 'yyyymmdd')
    under the condition above, ora-01841 returned by the following sql[1]:
    select date1 from View2
    where to_char(View2.date1, 'rrrr') = '2011' and substrb(to_char(View2.date1, 'mm'),1) = '03'
    i can get the records by the following sql[2]:
    select date1 from View2
    where to_char(View2.date1, 'rrrrmm') = '2011' || '03'
    any idea of the difference between sql[1] & [2]?
    *Oracle version is 11g
    Edited by: user5334162 on 2012/03/26 23:58

    This problem was solved by
    adding "ORDERED" hint & disabling cardinarity feedback option.

  • Administer User gives ORA-01841

    Hello,
    I'm using Apex 4.0.1 The database is Oracle XE (10g).
    I've managed multiple users in this workspace for almost a year.
    Recently, someone locked the Admin account for the workspace (the application workspace, not the INTERNAL workspace).
    I can Login to Apex_Admin using the Admin account for the INTERNAL workspace. I was attempting to unlock the application workspace Admin account. However, whenever I attempt to edit the application workspace Admin user in either Apex_Admin or in Apex, I receive the following error:
    ORA-01841 (full) year must be between -4713 and +9999
    Do you have any idea why Apex is returning this error?
    Thanks for checking
    Edited by: PhilMan2 on Jun 4, 2011 6:48 PM
    Edited by: PhilMan2 on Jun 5, 2011 12:19 PM

    I found a fix to the problem. It showed up in Apex 4.0.2
    When I searched for ORA-01841 on the APEX forum, I got nothing back. When I google'd the error code, I found this answer.
    I got the answer from oracle-and-apex.com
    ""Ever got a “ORA-01841: (full) year must be between -4713 and +9999, and not be 0″ Error when trying to edit an existing user in APEX Administration Panel (Manage Workspaces > Manage Developers and Users) ?
    The reason to this error can be a too large value in Manage Instance > Security > Account Password Lifetime (days). For example you can store there a number of 999999 days which is saved without any problems, but when trying to edit an user you get the ORA-01841 error message.
    This error occurs in APEX 4.0.2.*, reported as Bug in APEX Forum.
    Thanks Pascal for showing this error to me.""
    FIX: I changed the value of 'Account Password Lifetime' to 9999 (27+ years) and everything worked fine again.
    Edited by: PhilMan2 on Jun 5, 2011 12:21 PM

  • ORA-01841 full year must be between .....error when order by

    Hi all
    i have this query with me ,when order by clause is included ,when it is removed ,i see the output with  so  many record counts
    SELECT   porh.segment1,
             CASE
                WHEN popr.action_code = 'APPROVE'
                AND prall.full_name <> 'Sudheer T. Paraputhra'
                AND grdpr.short_name < 'PS-10'
                   THEN prall.full_name
             END directman_pr,-----getting names of managers who perform PR approve action
             porh.description, porl.line_num,
             CASE
                WHEN popr.action_code = 'APPROVE'
                AND prall.full_name <> 'Sudheer T. Paraputhra'
                AND grdpr.short_name < 'PS-10'
                AND poph.action_code = 'SUBMIT'
                   THEN TO_NUMBER (  TO_CHAR (  TO_DATE ('1', 'J')
                                              + (  poph.action_date
                                                 - popr.action_date
                                              'J'
                                   - 1
             END days_pr,------------------------------(calculating days from PR approval by manager to PO submit by user)
             poha.segment1 po_num, prall.full_name pr_approved_by,
             popr.action_date pr_approved_date,
             CASE
                WHEN poall_apprv.full_name <> 'Sudheer T. Paraputhra'
                AND grdpo_apprv.short_name < 'PS-10'
                AND poph_apprv.action_code = 'APPROVE'
                AND poph.action_code = 'SUBMIT'
                   THEN TO_NUMBER (  TO_CHAR (  TO_DATE ('1', 'J')
                                              + (  poph_apprv.action_date
                                                 - poph.action_date
                                              'J'
                                   - 1
             END days_po,------calculating days  from PO submit action by user to PO approve action by managers
             popr.sequence_num pr_seq, popr.action_code pr_action,
             poall.full_name po_approved_by, poph.action_date po_approved_date,
             poph.sequence_num po_seq, poph.action_code po_action,
             poph_apprv.action_date po_approved_date_appr,
             poph_apprv.action_code apprv_action_code
        FROM po_requisition_headers_all porh,
             po_requisition_lines_all porl,
             po_req_distributions_all prda,
             po_distributions_all poda,
             po_headers_all poha,
             po_action_history popr,
             po_action_history poph,
             hr.per_all_people_f poall,
             hr.per_all_people_f prall,
             hr.per_all_assignments_f asgpo,
             hr.per_all_assignments_f asgpr,
             per_grades_vl grdpo,
             per_grades_vl grdpr,
             po_headers_all poha_apprv,
             po_distributions_all poda_apprv,
             po_action_history poph_apprv,
             hr.per_all_people_f poall_apprv,
             hr.per_all_assignments_f asgpo_apprv,
             per_grades_vl grdpo_apprv
       WHERE poph.employee_id = poall.person_id
         AND popr.employee_id = prall.person_id
         AND poall.person_id = asgpo.person_id
         AND prall.person_id = asgpr.person_id
         AND asgpr.grade_id = grdpr.grade_id(+)
         AND asgpo.grade_id = grdpo.grade_id(+)
         AND prda.distribution_id = poda.req_distribution_id
         AND poha.po_header_id = poda.po_header_id
         AND prda.requisition_line_id = porl.requisition_line_id
         AND porh.requisition_header_id = porl.requisition_header_id
         AND porh.requisition_header_id = popr.object_id
         AND poph.object_type_code = 'PO'
         AND poha.po_header_id = poph.object_id
         AND SYSDATE BETWEEN poall.effective_start_date AND poall.effective_end_date
         AND SYSDATE BETWEEN prall.effective_start_date AND prall.effective_end_date
         AND SYSDATE BETWEEN asgpo.effective_start_date AND asgpo.effective_end_date
         AND SYSDATE BETWEEN asgpr.effective_start_date AND asgpr.effective_end_date
         AND SYSDATE BETWEEN poall_apprv.effective_start_date
                         AND poall_apprv.effective_end_date
         AND SYSDATE BETWEEN asgpo_apprv.effective_start_date
                         AND asgpo_apprv.effective_end_date
         AND prda.distribution_id = poda_apprv.req_distribution_id
         AND poha_apprv.po_header_id = poda_apprv.po_header_id
         AND poph_apprv.employee_id = poall_apprv.person_id
         AND poall_apprv.person_id = asgpo_apprv.person_id
         AND asgpo_apprv.grade_id = grdpo_apprv.grade_id(+)
         AND poha_apprv.po_header_id = poph_apprv.object_id
         AND poph_apprv.object_type_code = 'PO'
         AND poph_apprv.action_code = 'APPROVE'
    ORDER BY 4, 10, 14the calcuation works fine except for when order by clause is inlcuded
    kindly help
    Edited by: makdutakdu on Jun 1, 2010 2:51 PM

    hi Alex,John
    even i am confused as to why its happening ,
    SELECT   porh.segment1,
             CASE
                WHEN popr.action_code = 'APPROVE'
                AND prall.full_name <> 'Sudheer T. Paraputhra'
                AND grdpr.short_name < 'PS-10'------------< 'PS-10'
                   THEN prall.full_name
             END directman_pr,
             porh.description, porl.line_num,
             CASE
                WHEN popr.action_code = 'APPROVE'
                AND prall.full_name <> 'Sudheer T. Paraputhra'
                AND grdpr.short_name < 'PS-10'
                AND poph.action_code = 'SUBMIT'
                   THEN TO_NUMBER (  TO_CHAR (  TO_DATE ('1', 'J')
                                              + (  poph.action_date
                                                 - popr.action_date
                                              'J'
                                   - 1
             END days_pr,
             poha.segment1 po_num, prall.full_name pr_approved_by,
             popr.action_date pr_approved_date,
             CASE
                WHEN poall_apprv.full_name <> 'Sudheer T. Paraputhra'
                AND grdpo_apprv.short_name < 'PS-10'
                AND poph_apprv.action_code = 'APPROVE'
                AND poph.action_code = 'SUBMIT'
                   THEN TO_NUMBER (  TO_CHAR (  TO_DATE ('1', 'J')
                                              + (  poph_apprv.action_date
                                                 - poph.action_date
                                              'J'
                                   - 1
             END days_po,
             popr.sequence_num pr_seq, popr.action_code pr_action,
             poall.full_name po_approved_by, poph.action_date po_approved_date,
             poph.sequence_num po_seq, poph.action_code po_action,
             poph_apprv.action_date po_approved_date_appr,
             poph_apprv.action_code apprv_action_code
        FROM po_requisition_headers_all porh,
             po_requisition_lines_all porl,
             po_req_distributions_all prda,
             po_distributions_all poda,
             po_headers_all poha,
             po_action_history popr,
             po_action_history poph,
             hr.per_all_people_f poall,
             hr.per_all_people_f prall,
             hr.per_all_assignments_f asgpo,
             hr.per_all_assignments_f asgpr,
             per_grades_vl grdpo,
             per_grades_vl grdpr,
             po_headers_all poha_apprv,
             po_distributions_all poda_apprv,
             po_action_history poph_apprv,
             hr.per_all_people_f poall_apprv,
             hr.per_all_assignments_f asgpo_apprv,
             per_grades_vl grdpo_apprv
       WHERE poph.employee_id = poall.person_id
         AND popr.employee_id = prall.person_id
         AND poall.person_id = asgpo.person_id
         AND prall.person_id = asgpr.person_id
         AND asgpr.grade_id = grdpr.grade_id(+)
         AND asgpo.grade_id = grdpo.grade_id(+)
         AND prda.distribution_id = poda.req_distribution_id
         AND poha.po_header_id = poda.po_header_id
         AND prda.requisition_line_id = porl.requisition_line_id
         AND porh.requisition_header_id = porl.requisition_header_id
         AND porh.requisition_header_id = popr.object_id
         AND poph.object_type_code = 'PO'
         AND poha.po_header_id = poph.object_id
         AND SYSDATE BETWEEN poall.effective_start_date AND poall.effective_end_date
         AND SYSDATE BETWEEN prall.effective_start_date AND prall.effective_end_date
         AND SYSDATE BETWEEN asgpo.effective_start_date AND asgpo.effective_end_date
         AND SYSDATE BETWEEN asgpr.effective_start_date AND asgpr.effective_end_date
         AND SYSDATE BETWEEN poall_apprv.effective_start_date
                         AND poall_apprv.effective_end_date
         AND SYSDATE BETWEEN asgpo_apprv.effective_start_date
                         AND asgpo_apprv.effective_end_date
         AND prda.distribution_id = poda_apprv.req_distribution_id
         AND poha_apprv.po_header_id = poda_apprv.po_header_id
         AND poph_apprv.employee_id = poall_apprv.person_id
         AND poall_apprv.person_id = asgpo_apprv.person_id
         AND asgpo_apprv.grade_id = grdpo_apprv.grade_id(+)
         AND poha_apprv.po_header_id = poph_apprv.object_id
         AND poph_apprv.object_type_code = 'PO'
    --AND PORH.SEGMENT1='6003' -------when i give a particular PR number it comes out correct even with the order by clause    
    AND poph_apprv.action_code = 'APPROVE'
    ORDER BY 4, 10, 14when the PORH.SEGMENT1 is commented in oorder to display days for all po/pr i get the error
    kindly help me
    or is there an alternate calculation to get the number of days
    my date is in the format of 4/29/2009 9:13:51 AM
    for my caluculation i ve just taken the dates as i require days only kindly help
    Edited by: makdutakdu on Jun 2, 2010 7:52 AM

  • Oracle error 01841  Help please!

    I am using 10g on Unix. I am converting queries to Oracle and am down to a few errors that I cannot resolve on my own. I have this query
    SELECT DISTINCT TI.TICKET_ID,
    (QUEUE_DATE-(TO_CHAR(TRUNC(SYSDATE),'YYYYMMDD'))) AS DAYS_OPEN,
    TI.QUEUE_DATE,
    L1.LONG_DESC AS ITEM_STATUS,
    R.REQUEST_DESC,
    H.HELP_DESK_NAME,
    U.NAME_LAST || ', ' || U.NAME_FIRST AS ASSIGNED_TECH
    FROM WEBDESK.WD_TICKET T
    INNER JOIN WEBDESK.WD_TICKET_ITEM TI ON ((TI.TICKET_ID = T.TICKET_ID) AND (TI.ROUTE_GROUP_ID = 'G5097'))
    LEFT OUTER JOIN WEBDESK.WD_GROUP G ON (TI.ROUTE_GROUP_ID = GROUP_ID)
    LEFT OUTER JOIN WEBDESK.WD_USER U ON (U.USER_ID = TI.TECH_USER_ID)
    LEFT OUTER JOIN WEBDESK.WD_REQUEST R ON (T.REQUEST_ID = R.REQUEST_ID)
    LEFT OUTER JOIN WEBDESK.WD_LOOK_UP L ON (T.REQUEST_CATEGORY_NO = L.LOOKUP_ID)
    LEFT OUTER JOIN WEBDESK.WD_LOOK_UP L1 ON (TI.STATUS_NO = L1.LOOKUP_ID)
    LEFT OUTER JOIN WEBDESK.WD_HELP_DESK H ON (T.HELP_DESK_ID = H.HELP_DESK_ID)
    LEFT OUTER JOIN
    (SELECT IR.TICKET_ID,IR.TICKET_ITEM_ID
    FROM WEBDESK.WD_TICKET_IROUTE IR
    INNER JOIN WEBDESK.WD_TICKET_ITEM TIM ON ((IR.TICKET_ID = TIM.TICKET_ID)
    AND (IR.ITEM_ID_DEPENDENCY = TIM.TICKET_ITEM_ID)
    AND (TIM.END_DATE = '31-DEC-9999'))) LIR ON ((TI.TICKET_ID = LIR.TICKET_ID)
    AND (TI.TICKET_ITEM_ID = LIR.TICKET_ITEM_ID))
    WHERE ((LIR.TICKET_ID IS NULL)
    AND (TI.TECH_USER_ID IS NULL))
    --AND (TI.END_DATE = '31-DEC-9999')
    UNION
    SELECT DISTINCT TI.TICKET_ID,
    (TI.QUEUE_DATE-(TO_CHAR(TRUNC(SYSDATE),'YYYYMMDD'))) AS DAYS_OPEN,
    TI.QUEUE_DATE,
    L1.LONG_DESC AS ITEM_STATUS,
    R.REQUEST_DESC,
    H.HELP_DESK_NAME,
    U.NAME_LAST || ', ' || U.NAME_FIRST AS ASSIGNED_TECH
    FROM WEBDESK.WD_TICKET T
    INNER JOIN WEBDESK.WD_TICKET_ITEM TI ON (TI.TICKET_ID = T.TICKET_ID)
    INNER JOIN WEBDESK.WD_USER_GROUP UG ON ((TI.ROUTE_GROUP_ID = UG.GROUP_ID) AND ((TI.TECH_USER_ID = UG.USER_ID)
    AND (UG.GROUP_ID = 'G5097')) AND (TI.TECH_USER_ID IS NOT NULL))
    LEFT OUTER JOIN WEBDESK.WD_GROUP G ON (TI.ROUTE_GROUP_ID = G.GROUP_ID)
    LEFT OUTER JOIN WEBDESK.WD_USER U ON (U.USER_ID = TI.TECH_USER_ID)
    LEFT OUTER JOIN WEBDESK.WD_REQUEST R ON (T.REQUEST_ID = R.REQUEST_ID)
    LEFT OUTER JOIN WEBDESK.WD_LOOK_UP L ON (T.REQUEST_CATEGORY_NO = L.LOOKUP_ID)
    LEFT OUTER JOIN WEBDESK.WD_LOOK_UP L1 ON (TI.STATUS_NO = L1.LOOKUP_ID)
    LEFT OUTER JOIN WEBDESK.WD_HELP_DESK H ON (T.HELP_DESK_ID = H.HELP_DESK_ID)
    --WHERE (TI.END_DATE = '31-DEC-9999')
    ORDER BY 2 DESC,3,4
    and when I run it I am getting
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"
    *Cause:    Illegal year entered
    *Action:   Input year in the specified range
    As far as I can tell the date IS in the proper range, but obviously I am missing something. Any help is greatly appreciated.

    AND ( tim.end_date = '31-DEC-9999' ) ))With Oracle characters between single quote marks are STRINGS!
    'This is a string, 2009-12-31, not a date'
    When a DATE datatype is desired, then use TO_DATE() function.
    SELECT DISTINCT ti.ticket_id,
                    ( queue_date - ( To_char(Trunc(SYSDATE), 'YYYYMMDD') ) ) AS
                    days_open,
                    ti.queue_date,
                    l1.long_desc                                             AS
                    item_status,
                    r.request_desc,
                    h.help_desk_name,
                    u.name_last
                    || ', '
                    || u.name_first                                          AS
                    assigned_tech
    FROM   webdesk.wd_ticket t
           inner join webdesk.wd_ticket_item ti
             ON ( ( ti.ticket_id = t.ticket_id )
                  AND ( ti.route_group_id = 'G5097' ) )
           left outer join webdesk.wd_group g
             ON ( ti.route_group_id = group_id )
           left outer join webdesk.wd_user u
             ON ( u.user_id = ti.tech_user_id )
           left outer join webdesk.wd_request r
             ON ( t.request_id = r.request_id )
           left outer join webdesk.wd_look_up l
             ON ( t.request_category_no = l.lookup_id )
           left outer join webdesk.wd_look_up l1
             ON ( ti.status_no = l1.lookup_id )
           left outer join webdesk.wd_help_desk h
             ON ( t.help_desk_id = h.help_desk_id )
           left outer join (SELECT ir.ticket_id,
                                   ir.ticket_item_id
                            FROM   webdesk.wd_ticket_iroute ir
                                   inner join webdesk.wd_ticket_item tim
                                     ON ( ( ir.ticket_id = tim.ticket_id )
                                          AND ( ir.item_id_dependency =
                                              tim.ticket_item_id )
                                          AND ( tim.end_date = '31-DEC-9999' ) ))
                           lir
             ON ( ( ti.ticket_id = lir.ticket_id )
                  AND ( ti.ticket_item_id = lir.ticket_item_id ) )
    WHERE  ( ( lir.ticket_id IS NULL )
             AND ( ti.tech_user_id IS NULL ) )
    --AND (TI.END_DATE = '31-DEC-9999')
    UNION
    SELECT DISTINCT ti.ticket_id,
                    ( ti.queue_date - ( To_char(Trunc(SYSDATE), 'YYYYMMDD') ) ) AS
                    days_open,
                    ti.queue_date,
                    l1.long_desc                                                AS
                    item_status,
                    r.request_desc,
                    h.help_desk_name,
                    u.name_last
                    || ', '
                    || u.name_first                                             AS
                    assigned_tech
    FROM   webdesk.wd_ticket t
           inner join webdesk.wd_ticket_item ti
             ON ( ti.ticket_id = t.ticket_id )
           inner join webdesk.wd_user_group ug
             ON ( ( ti.route_group_id = ug.group_id )
                  AND ( ( ti.tech_user_id = ug.user_id )
                        AND ( ug.group_id = 'G5097' ) )
                  AND ( ti.tech_user_id IS NOT NULL ) )
           left outer join webdesk.wd_group g
             ON ( ti.route_group_id = g.group_id )
           left outer join webdesk.wd_user u
             ON ( u.user_id = ti.tech_user_id )
           left outer join webdesk.wd_request r
             ON ( t.request_id = r.request_id )
           left outer join webdesk.wd_look_up l
             ON ( t.request_category_no = l.lookup_id )
           left outer join webdesk.wd_look_up l1
             ON ( ti.status_no = l1.lookup_id )
           left outer join webdesk.wd_help_desk h
             ON ( t.help_desk_id = h.help_desk_id )
    --WHERE (TI.END_DATE = '31-DEC-9999')
    ORDER  BY 2 DESC,
              3,
              4 

  • 10g standard edition, create a manual standby without ORA-279 and ORA-308.

    Hi,
    I have a 10 g database 10g r2 on linux rhel 5.2. I've create a standby database from an rman backup on another server (same name, same path....).
    every 10 minutes , i switch log on primary database and rsync them to the stanby path on stanby server.
    every 10 minutes, i apply the new received archive to the standby database with this script :
    sqlplus /nolog
    connect / as sysdba
    recover database until cancel using backup controlfile;
    AUTO
    recover database until cancel using backup controlfile;
    CANCEL
    exit
    this script gives some ORA errors like this :
    2010/03/31 Wed 11:30:03 Media Recovery Log /v4/db/oradata/LFEX/archives/1_61705_640182036.dbf
    2010/03/31 Wed 11:30:03 ORA-308 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
    2010/03/31 Wed 11:30:04 ORA-279 signalled during: ALTER DATABASE RECOVER database until cancel using backup controlfile ...
    2010/03/31 Wed 11:40:01 ORA-279 signalled during: ALTER DATABASE RECOVER database until cancel using backup controlfile ...
    I understand this error, the script is searching the next archive, which doesn't exist at this time, that's OK.
    To avoid to have this error, i believe that i can do something like that:
    sqlplus /nolog
    connect / as sysdba
    recover database until time 'sysdate-1/(24*4)' using backup controlfile;
    AUTO
    exit
    i'm searching to replay the archive and stop 15 minutes before sysdate, Is it possible?
    when i try this, i have this message :
    SQL> recover database until time 'sysdate-1/(24*4)' using backup controlfile;
    ORA-01841: L'année (complète) doit être comprise entre -4713 et +9999 et être
    différente de 0.
    I'm trying to change nls_date_format, nls_lang without any success.
    thx.
    Antoine.

    i found a script to do an automatic recover script like this :
    recover database until time '2010-04-01:16:49:05' using backup controlfile;
    ORA-00279: changement 2456430208 généré à 04/01/2010 16:31:01 requis pour thread 1
    ORA-00289: suggestion : /v4/db/oradata/LFEX/archives/1_61853_640182036.dbf
    ORA-00280: le changement 2456430208 pour le thread 1 se trouve au no de séquence 61853
    ORA-00279: changement 2456432030 généré à 04/01/2010 16:39:01 requis pour thread 1
    ORA-00289: suggestion : /v4/db/oradata/LFEX/archives/1_61854_640182036.dbf
    ORA-00280: le changement 2456432030 pour le thread 1 se trouve au no de séquence 61854
    ORA-00278: le fichier journal
    '/v4/db/oradata/LFEX/archives/1_61853_640182036.dbf' n'est plus nécessaire pour cette récupération
    So i continue to have some error like ORA-278.... but no more ORA-308 error, it's better, because ORA-278 279 and 280 are only information messages, so i can ignore it in alert.log files.
    Only ORA-308 in this case interresting me, to see if an archive is really missing.
    thx.
    PS : the script standby_recover generate the recover.sql script :
    [dblegu@dbback SQL]$ cat $PGLEGU/SQL/standby_recover.sql
    connect sys/password as sysdba
    set trimspool on linesize 200 head off feedback off sqlprompt "--" verify off
    spool &1/SQL/recover.sql
    select 'connect sys/password as sysdba'||chr(10)||
    'set autorecovery on'||chr(10)||
    'recover database until time '''||
    to_char(sysdate - 1/(24*4),'YYYY-MM-DD:HH24:MI:SS')||''' using backup controlfile;'||chr(10)||
    'exit;' from dual;
    spool off
    exit
    the resul in recover.sql is :
    connect sys/password as sysdba
    set autorecovery on
    recover database until time '2010-04-01:16:49:05' using backup controlfile;
    exit;
    i found this on site : http://erkanorclog.blogspot.com/2007/08/batch-scripts-to-set-up-asyncronous.html.
    Edited by: fleuron on 1 avr. 2010 09:04

Maybe you are looking for