Addition/subtraction of TIMESTAMP interval

Hi all

I have a requirement to subtract the number of days or months or weeks of a Timestamp column and get a timestamp value in return.

I have the following table-
Table name: Test
Columns:
Effective_End_Date: TIMESTAMP
Interval_type: VARCHAR2
Interval_value: NUMBER

In general, we'd go with the following query-

Select Effective_End_Date - '1'-DAY interval of the test;

The issue is I have to subtract the value stored in interval_value stored in the effective_end_date table. In addition, the type of interval (DAY, MONTH, etc.) is stored in the INTERVAL_TYPE.

Does anyone could suggest any request for this? Let me know if you count more inputs.

Thank you
Maithily.

Hello

Sorry, my mistake. All branches of the CASE expression must return the same type of data. The version below works, because all branches return a TIMESTAMP:

SELECT     test.*
,       CASE interval_type
            WHEN 'DAY'   THEN effective_end_date - NUMTODSINTERVAL (interval_value,     'DAY')
         WHEN 'WEEK'  THEN effective_end_date - NUMTODSINTERVAL (interval_value * 7, 'DAY')
         WHEN 'MONTH' THEN effective_end_date - NUMTOYMINTERVAL (interval_value,     'MONTH')
        END AS new_timestamp
FROM      test;

Tags: Database

Similar Questions

  • Subtracting two timestamps

    Hi all

    Thanks for looking

    I'm subtracting (systimestamp - "TIME_IN") as "HOURS_WORKED".
    (30/08/2010 16:42-30/08/2010 04:00) = "HOURS_WORKED".

    the column called hours, the columns hours 'worked' shows '000000000 12:42:58.9881'

    I understand that the hours are 12 hours and 42 minutes and 58 seconds.

    is it possible that I can format this column to just show me hours and minutes?

    of '000000000 12:42:58.9881' 12:42?

    is there an easier way?

    Thanks in advance

    Published by: jo3y2 on August 30, 2010 17:19

    Select double to_char(sysdate,'hh24:mi:ss')

    or

    SELECT TO_CHAR(date1,'MMDDYYYY:HH24:MI:SS') date1,
    To_char(date2,'MMDDYYYY:HH24:mi:SS') date2,
    trunc (86400 *(date2-date1))-60 * (trunc ((86400 *(date2-date1)) / 60)) seconds.
    trunc ((86400 *(date2-date1)) / 60)-60 * (trunc (((86400 *(date2-date1)) / 60) / 60)) minutes,.
    trunc (((86400 *(date2-date1)) / 60) / 60)-24 * (trunc (((86400 *(date2-date1)) / 60) / 60) / 24)) hours.
    trunc (((86400 *(date2-date1)) / 60) / 60) / 24) days.
    trunc (((86400 *(date2-date1)) / 60) / 60) / 24) / 7) weeks
    OF date_table

    See this post
    http://www.databasejournal.com/features/Oracle/article.php/2234501/A-comparison-of-oracles-date-and-timestamp-datatypes.htm

  • checkboxes: addition/subtraction of values

    Hi, this is a problem which has been irritates me for some time now.

    There are several checkboxes and a text box. How each box is adjustable with a certain numeric value (price of the exodus) which, when selected, adds its value to the textarea component? for example:

    the user selects the box 1: its value (say, 3.24) added to the text box. then the user selects the box 2. its value is 6.45. It will be the same for each checkbox in the application, it is not only limited to 2 boxes. How make the text box to display "9.69" instead of something like 3.246.45?

    In addition, how the app is adjustable so that when the user unselects a checkbox, its value is rather subtracted from the current value of the text box?

    Thank you.

    Here's one way:


    "http://www.adobe.com/2006/MXML" layout = "absolute" xmlns:ns1 ="*" >


    [Bindable]
    private var totalValue:Number = 0;
    private var: number = 4;

    private void itemClicked(event:MouseEvent):void
    {
    var target: CustomCheckbox = CustomCheckbox (event.target);
    var selectedValue:Number = target.selected? setPrecision (target.value): setPrecision (target.value *-1);
    totalValue = number ((totalValue_+_selectedValue).toPrecision (4));
    }
    private void setPrecision(num:Number):Number
    {
    Return Number (num.toPrecision (precision));
    }

    ]]>





    http://www.Adobe.com/2006/mxml">

    private var _value:Number;
    public function set value(v:Number):void {_value = v ;}
    public function get value (): number {return _value ;}

    ]]>

  • How can I distribute randomly addition or subtraction in a loop for?

    Someone at - it ideas for how can I randomly assign a loop for to add or subtract from the random numbers throughout the various itterations?  My current code generates two random numbers and added together for a number of itterations.  I need a few itterations randomly to be subtraction.  Thanks in advance!

    Add another random number generator and compare the result against 0.5. Use a case around your addition/subtraction operator.

    Looks like you might also want to exit what operation is in fact taken.

  • Difference between 2 timestamps in seconds

    Can someone tell me how to subtract 2 timestamps and
    get the difference in seconds? does not "rip."
    He always gives a value between 0 and 59, I want total
    seconds, not the seconds part of the interval.

    I use Oracle Database 10 g Express Edition Release 10.2.0.1.0
    SQL> @id8
    SQL> drop   table holder ;
    
    Table dropped.
    
    SQL> create table holder (
      2  beg_date timestamp,
      3  end_date timestamp)
      4  /
    
    Table created.
    
    SQL> INSERT INTO HOLDER VALUES(to_timestamp('2009-07-16:19:00:01.50','YYYY-MM-DD:HH24:MI:SS.FF'),
      2                        to_timestamp('2009-08-17:20:00','YYYY-MM-DD:HH24:MI'));
    
    1 row created.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL> SELECT EXTRACT (DAY    FROM (END_DATE-BEG_DATE))*24*60*60+
      2           EXTRACT (HOUR   FROM (END_DATE-BEG_DATE))*60*60+
      3           EXTRACT (MINUTE FROM (END_DATE-BEG_DATE))*60+
      4           EXTRACT (SECOND FROM (END_DATE-BEG_DATE)) DELTA
      5  from holder
      6  /
    
         DELTA
    ----------
     2768398.5
    
  • How to get a date to the timestamp of a file XML format

    Hello

    I'm trying to get a date from an external XML file. My XML file looks like this:


    <>http://www.NI.com/LVData">
        8.6.1
        
            Date of birth
            31/03/1983
        
     

    I can get the system to retrieve the correct XML element that shows the nested and elements , but I have no way to retrieve correctly the date. It seems as if she interprets my date seconds since 1904. I try to keep the "readable" for the end user XML, so it is important to keep this date in standard U.S. date format. I eventually uses this date to calculate the age of something. I labour code to subtract a timestamp in the format of the date to the current date and time, but I can't access it when I get back from XML.

    Starting from XML schema, it looks like the timestamp element requires a cluster... but there is no documentation on what to spend. Any ideas how to get back an XML date in this format in a simple and clean?

    Here's my current VI:

    Thank you

    Ryan

    Cambridge, MY

    Quick Tip on "bundle by name.  You don't need to consolidate all these constants where the values correspond to what is the constant of cluster at the top.  The cluster constant defines the data structure and the starting values.  Simply group the values for specific change items.

    Example of tone would be a bit cleaner.  Although the format string should use a capital T.

    As always with dealing with the time, complications could arise due to dealing with time zones and leap years.  Zones shouldn't matter for the calculation of the years since you are rounded up to years.  Although you probably want to round down rather than round at most closely. (I forgot this part in my example).  The problem with leap years when you would be only in a certain number of days of the anniversary, he would round up the age.  The number of rounded days would depend on how much on leap days that nobody has seen in their lifetime.

  • Select the event to add (or subtract) per day for a date field

    I have a form that gives me a little trouble. I want to be able to enter a start date in a field, and then enter a number of days in another field and then have it calculate a date that is the number of days from the start date. The form is actually work very well most of the time, but there are a few problems I encounter.

    1 end date does not immediately calculate out the number of days. You need to tab all the way back to the start and date only when you leave that field does calculate the end date I need to calculate when you leave the number of days.

    2. I added a small (+) and (-) button to increase or decrease the date by one day. It works, but the problem is, I want to do it in the background. Which means, I want the calculated date to change, but the number of days field not change.

    Tell me if I go on 01/12/2010 to the start date. Then I go 1 in the # of days field. When I tab to the calculated date field, it must immediately change to 02/12/2010. So, if I click on the (+), the date calculated field should go up to 03/12/2010, but the number of days field should stay at 1.

    I downloaded a sample of what I've understood so far:

    https://Acrobat.com/#d=v4c4KKdj0hesicxO8yO1pw

    Thanks a lot for any help I can get on it!

    JO

    I think that's what you're after. I moved the logic to calculate the date event deadline and added a numeric field to store the result of the addition/subtraction (called 'delta').

    Form1. #subform [0]. date2::calculate - (FormCalc, client)

    var date1 = Date2Num(date1.formattedValue,"MM/DD/YYYY")

    $.rawValue = Num2Date(date1+days+delta,"MM/DD/YYYY")

    You could do 'delta' hidden.

    Steve

  • RETURN TYPE in mathematics of difference in Date

    Hi all

    I try to get the difference in days between two timestamps.

    I tried: (date2-date1) and I get a result, but I get them as a VARCHAR, while I need like an INTEGER or the NUMBER or the DECIMAL can I apply mathematics more on.

    Any ideas on how I could go about this?

    If you are subtracting two TIMESTAMP values, the difference is returned as an INTERVAL, not as a VARCHAR. It can stand as a string in your tool (SQL * Plus, TOAD, SQL Developer, etc.), but there is a gap. Once you have an interval, you can get the parts using the EXTRACT function.

    In addition, you can add a different TIMESTAMP to the INTERVAL and the result will be an another TIMESTAMP.

    Here is an example:

      1  SELECT SYSTIMESTAMP
      2  , TIMESTAMP '2012-02-11 11:45:00' - SYSTIMESTAMP   diff
      3  , EXTRACT ( DAY FROM ( TIMESTAMP '2012-02-11 11:45:00' - SYSTIMESTAMP )) days
      4  , ( TIMESTAMP '2012-02-11 11:45:00' - SYSTIMESTAMP  ) + TIMESTAMP '2005-06-16 05:00:00' calc
      5* FROM DUAL
    07:18:54 SQL> /
    
    SYSTIMESTAMP                          DIFF                            DAYS      CALC
    ------------------------------------- ------------------------------- --------- -------------------------------
    10-AUG-11 07.18.54.953000 AM -06:00   +000000185 05:26:05.047000000         185 18-DEC-05 10.26.05.047000000 AM
    
    1 row selected.
    

    The second field, 'DIFF', is the difference between two timestamps, as an interval
    The third field, "DAYS", illustrates the use of the EXTRACT to get the number of days of the DIFF
    The fourth field, 'CALC', shows how to use the interval in a second calculation. In this case, I added 185 days, 5 hours, 26 minutes and 5,047 seconds to another timestamp.

    Once you get over the lack of knowledge, the timestamps and intervals are simpler in many ways than dates.

  • Creating a PL/SQL procedure to run the following code but the landing upwards errors!

    Hey all!

    This is my first time with PL/SQL. I created the following procedure to load a major part of the update instructions at the same time to read the DB performance. I need to print a sysdate timestamp before and after the load so that I can know how long it takes for the DB update prescribed lines. I gave 100 lines initially and will keep changing. When I run this code, I came across some errors. Could you please help me with it.

    CODE:

    PROCEDURE FACT_UPDATE
    IS
    DECLARE
    CNT NUMBER: = 0;

    UPD CURSOR is
    SELECT
    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').
    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').
    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').
    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').
    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | Decode (START_TS, null, "to_date('''|| to_char (START_TS,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")').
    ', END_TS =' | Decode (END_TS, null, "to_date('''|| to_char (END_TS,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').
    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').
    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').
    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | Decode (LAST_UPD, null, "to_date('''|| to_char (LAST_UPD,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').
    "', W_INSERT_DT = ' | Decode (W_INSERT_DT, null, "to_date('''|| to_char (W_INSERT_DT,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', W_UPDATE_DT = ' | Decode (W_UPDATE_DT, null, "to_date('''|| to_char (W_UPDATE_DT,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")').
    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |
    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; » AS a Column OF XXAFL_MON_FACTS_F;

    BEGIN
    dbms_output.put_line (sysdate);
    to record in a loop of the UPD

    dbms_output.put_line (record.col_name);
    immediately run record.col_name;

    CNT: = cnt + 1;
    If cnt > 1000
    and then commit;
    CNT: = 0;
    dbms_output.put_line (sysdate);
    end if;
    end loop;
    dbms_output.put_line (sysdate);


    END; -Procedure

    ERRORS:

    Error starting line: 1 at the controls.
    PROCEDURE FACT_UPDATE
    Error report-
    Unknown command

    Error from line: 2 in command.
    IS
    Error report-
    Unknown command
    Error from line: 3 in command.
    DECLARE
    CNT: = 0;

    UPD CURSOR is
    SELECT
    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').
    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').
    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').
    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').
    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | Decode (START_TS, null, "to_date('''|| to_char (START_TS,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")').
    ', END_TS =' | Decode (END_TS, null, "to_date('''|| to_char (END_TS,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').
    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').
    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').
    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | Decode (LAST_UPD, null, "to_date('''|| to_char (LAST_UPD,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').
    "', W_INSERT_DT = ' | Decode (W_INSERT_DT, null, "to_date('''|| to_char (W_INSERT_DT,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', W_UPDATE_DT = ' | Decode (W_UPDATE_DT, null, "to_date('''|| to_char (W_UPDATE_DT,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")').
    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |
    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; » AS a Column OF XXAFL_MON_FACTS_F;

    BEGIN
    dbms_output.put_line (sysdate);
    to record in a loop of the UPD

    dbms_output.put_line (record.col_name);
    immediately run record.col_name;

    CNT: = cnt + 1;
    If cnt > 1000
    and then commit;
    CNT: = 0;
    dbms_output.put_line (sysdate);
    end if;
    end loop;
    dbms_output.put_line (sysdate);


    END; -Procedure
    Error report-
    ORA-06550: line 2, column 6:
    PLS-00103: encountered the symbol "=" when expecting one of the following conditions:

    constant exception < an ID >
    < a between double quote delimited identifiers > double long Ref table
    char time timestamp interval date binary national character
    NCHAR
    The symbol '< identifier >' has been substituted for "=" continue.
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error.
    * Action:
    Error starting line: 1 at the controls.
    PROCEDURE FACT_UPDATE
    Error report-
    Unknown command

    Error from line: 2 in command.
    IS
    Error report-
    Unknown command
    Error from line: 3 in command.
    DECLARE
    CNT NUMBER: = 0;

    UPD CURSOR is
    SELECT
    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').
    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').
    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').
    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').
    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | Decode (START_TS, null, "to_date('''|| to_char (START_TS,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")').
    ', END_TS =' | Decode (END_TS, null, "to_date('''|| to_char (END_TS,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').
    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').
    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').
    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | Decode (LAST_UPD, null, "to_date('''|| to_char (LAST_UPD,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').
    "', W_INSERT_DT = ' | Decode (W_INSERT_DT, null, "to_date('''|| to_char (W_INSERT_DT,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")') |', W_UPDATE_DT = ' | Decode (W_UPDATE_DT, null, "to_date('''|| to_char (W_UPDATE_DT,' jj/mm/aaaa hh) |")) ((', "dd/mm/yyyy hh")').
    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |
    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; » AS a Column OF XXAFL_MON_FACTS_F;

    BEGIN
    dbms_output.put_line (sysdate);
    to record in a loop of the UPD

    dbms_output.put_line (record.col_name);
    immediately run record.col_name;

    CNT: = cnt + 1;
    If cnt > 1000
    and then commit;
    CNT: = 0;
    dbms_output.put_line (sysdate);
    end if;
    end loop;
    dbms_output.put_line (sysdate);


    END; -Procedure
    Error report-
    ORA-00911: invalid character
    ORA-06512: at line 24
    00911 00000 - "invalid character".
    * Cause: identifiers may not start with any character other than ASCII
    letters and numbers.  $# _ are allowed after the first
    character.  May contain identifiers surrounded by doublequotes
    any character other than a quotation mark.  Other quotes
    (q' #... #') cannot use spaces, tabs or as carriage returns
    delimiters.  For all other settings, consult the SQL language
    Reference manual.
    * Action:

    In addition to the other reviews, and apart from the quality of the code, you should really (really!) learn how to format your code for better "read-ability.  This will also contribute to a better quality.  If you are unsure how to format, then use a development as a SQL developer tool.  It will not format "as you type", but a frequent use of the shortened format keyboard (Ctrl + F7 in SQL Dev) will keep your code readable and coherent.

    And then you learn to keep this format when you post on the forum.

    Like this:

    PROCEDURE FACT_UPDATE

    IS

    DECLARE

    CNT NUMBER: = 0;

    CURSOR UPD

    IS

    SELECT "UPDATE XXAFL_MON_FACTS_F SET TASK_WID ='"

    || NVL (TO_CHAR (TASK_WID), 'NULL')

    |', EXECUTION_PLAN_WID ='

    || NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL')

    || ', DETAILS_WID ='

    || NVL (TO_CHAR (DETAILS_WID), 'NULL')

    |', SOURCE_WID ='

    || NVL (TO_CHAR (SOURCE_WID), 'NULL')

    |', TARGET_WID = '

    || NVL (TO_CHAR (TARGET_WID), 'NULL')

    || ', RUN_STATUS_WID ='

    || NVL (TO_CHAR (RUN_STATUS_WID), 'NULL')

    |', SEQ_NUM ='

    || NVL (TO_CHAR (SEQ_NUM), 'NULL')

    |', NAME = "'

    || NVL (TO_CHAR (NAME), 'NULL')

    || ' ', NO_POSITION = "'

    || NVL (TO_CHAR (INSTANCE_NUM), 'NULL')

    ||'' ', INSTANCE_NAME = "'

    || NVL (TO_CHAR (INSTANCE_NAME), 'NULL')

    || ' ', TYPE_CD = "'

    || NVL (TO_CHAR (TYPE_CD), 'NULL')

    ||'' ', STATUS_CD = "'

    || NVL (TO_CHAR (STATUS_CD), 'NULL')

    ||'' ', START_TS ='

    || DECODE (START_TS, ",' to_date(''e))

    || To_char (START_TS, "mm/dd/yyyy hh)

    ||'' ((', "dd/mm/yyyy hh")')

    || ', END_TS ='

    || DECODE (END_TS, ",' to_date(''e))

    || To_char (END_TS, "mm/dd/yyyy hh)

    ||'' ((', "dd/mm/yyyy hh")')

    |', DURATION = '

    || NVL (TO_CHAR (DURATION), 'NULL')

    |', STATUS_DESC = "'

    || NVL (TO_CHAR (STATUS_DESC), 'NULL')

    || ' ', DBCONN_NAME = "'

    || NVL (TO_CHAR (DBCONN_NAME), 'NULL')

    ||'' ', SUCESS_ROWS ='

    || NVL (TO_CHAR (SUCESS_ROWS), 'NULL')

    || ', FAILED_ROWS ='

    || NVL (TO_CHAR (FAILED_ROWS), 'NULL')

    |', ERROR_CODE = '

    || NVL (TO_CHAR (ERROR_CODE), 'NULL')

    |', NUM_RETRIES ='

    || NVL (TO_CHAR (NUM_RETRIES), 'NULL')

    || ', READ_THRUPUT ='

    || NVL (TO_CHAR (READ_THRUPUT), 'NULL')

    |', LAST_UPD = '

    || DECODE (LAST_UPD, ",' to_date(''e))

    || To_char (LAST_UPD, "mm/dd/yyyy hh)

    ||'' ((', "dd/mm/yyyy hh")')

    |', RUN_STEP_WID = "'

    || NVL (TO_CHAR (RUN_STEP_WID), 'NULL')

    || ' ', W_INSERT_DT = '

    || DECODE (W_INSERT_DT, ",' to_date(''e))

    || To_char (W_INSERT_DT, "mm/dd/yyyy hh)

    ||'' ((', "dd/mm/yyyy hh")')

    |', W_UPDATE_DT = '

    || DECODE (W_UPDATE_DT, ",' to_date(''e))

    || To_char (W_UPDATE_DT, "mm/dd/yyyy hh)

    ||'' ((', "dd/mm/yyyy hh")')

    || ', START_DATE_WID ='

    || NVL (TO_CHAR (START_DATE_WID), 'NULL')

    |', END_DATE_WID = '

    || NVL (TO_CHAR (END_DATE_WID), 'NULL')

    |', START_TIME ='

    || NVL (TO_CHAR (START_TIME), 'NULL')

    |', END_TIME ='

    || NVL (TO_CHAR (END_TIME), 'NULL')

    ||' WHERE INTEGRATION_ID = "'

    || INTEGRATION_ID

    ||''';' AS Column

    OF XXAFL_MON_FACTS_F;

    BEGIN

    dbms_output.put_line (sysdate);

    FOR registration in UPD

    LOOP

    dbms_output.put_line (record.col_name);

    EXECUTE immediate record.col_name;

    CNT: = cnt + 1;

    IF cnt > 1000 THEN

    COMMIT;

    CNT: = 0;

    dbms_output.put_line (sysdate);

    END IF;

    END LOOP;

    dbms_output.put_line (sysdate);

    END; -Procedure

  • get the ora-01830, but cannot say what I'm doing wrong

    Hi, Oracle 11g R2.

    Could someone help me understand what I'm doing wrong in following select clause? I'm trying to convert the difference in seconds to hh.

    ISN.snapshot_ts and iobd.bd_handshake_ts are TIMESTAMP (6) WITH ZONE SCHEDULE

    Select to_date ((to_date (to_char (isn. )))) snapshot_ts , 'HH24:MI:SS DD/MM/YYYY'), ' MM/DD/YYYY HH24:MI:SS')

    - to_date (to_char (iobd. )) bd_handshake_ts , 'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'))*60*60*24, 'sssss')

    Hello

    Back-and-forth conversion as

    TO_DATE (to_char)

    are almost never necessary in Oracle.  There are a lot of built-in functions and features that make everything you need more simply.

    If you subtract one TIMESTAMP on the other, the result is an INTERVAL DAY TO SECOND.

    If you view an INTERVAL DAY TO SECOND, it is formatted as

    + 00:01:10.879000 000000000

    which is what you want.  In fact, it's what you want and then some others, which can be a problem for you.  If you are certain that the difference will be less than 24 hours, you can display the number of days in the beginning, and you're neither to display fractions of a second at the end.  In this case, you can convert the INTERVAL DAY TO SECOND string and then use SUBSTR (or similar) to get exactly the parts you want.

    Try something like:

    SELECT isn.snapshot_ts - iobd.bd.handshake_ts AS diff

    ...

    If this isn't what you want (or close enough) then after a small example of data (CREATE TABLE and INSERT statements) and the accurate results you want from these sample data.

    Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

  • The procedure helps

    Hello

    Can someone help me with the procedure below. It seems to me, but I'm unable to turn it and get the error.

    "Error (8.36): PLS-00103: encountered the symbol"UNDER"when expecting one of the following conditions: (- + case null new mod continue County avg current prior min max sql stddev sum variance execute forall time timestamp interval date fusion pipe)"

    CREATE OR REPLACE PROCEDURE ddl_create_proc(p_table IN varchar2)
    AS
    i_stmt varchar2(200);
    BEGIN
    dbms_output.put_line('starting....');
    i_stmt := 'create table'||p_table||as 'select * from emp';
    execute immediate i_stmt;
    dbms_output.put_line('procedure Ended');
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('EXCEPTION '||SQLERRM||'MESSAGE'||SQLCODE);
    END;
    /
    
    

    Thanks in advance!

    Hello

    user782973 wrote:

    Hello

    Can someone help me with the procedure below. It seems to me, but I'm unable to turn it and get the error.

    "Error (8.36): PLS-00103: encountered the symbol"UNDER"when expecting one of the following conditions: (- + case mod new null continue County avg current min max sql prior stddev sum variance execute forall time timestamp interval date fusionpipe" ").

    1. CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table IN varchar2)
    2. AS
    3. i_stmt varchar2 (200);
    4. BEGIN
    5. dbms_output.put_line ('starting...');
    6. i_stmt: = 'create table ' | p_table | as ' select * from emp';
    7. immediately run i_stmt;
    8. dbms_output.put_line ("'procedure completed");
    9. EXCEPTION
    10. WHILE OTHERS THEN
    11. dbms_output.put_line ('EXCEPTION' |) SQLERRM | ' MESSAGE' | SQLCODE);
    12. END;
    13. /

    Thanks in advance!

    In addition to what others have said, whenever you do the dynamic SQL code, display the value chain before you run it, like this:

    CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table IN varchar2)

    AS

    i_stmt varchar2 (200);

    BEGIN

    dbms_output.put_line ('go... ») ;

    i_stmt: = 'create table ' | p_table | ' in select * from emp';

    dbms_output.put_line (i_stmt |) '= i_stmt in ddl_create_proc");  -For debugging

    immediately run i_stmt;

    dbms_output.put_line ('procedure completed");

    END ddl_create_proc;

    /

    After the test is finished, you can comment out the line marked "for debugging.

    You need an EXCEPTION section.  If there is an error, the error message will be displayed by default; you don't need to explicitly show.

    What is the big picture here?  What is this procedure intended to do?  There may already be a procedure provided by Oracle that the fact, perhaps in dbms_metadata:

    DBMS_METADATA

  • EXTRACT function can be used directly in the CASE statement WHEN

    I wrote the following SELECT statement. The function 'calc_time_diff' is a stored function that subtracts two timestamps and returns the result to the total number of seconds. My DBA does not 'calc_time_diff' as a stored function, then, I replaced the third line (in bold) in the SELECT statement with this:

    COUNTY ( BOX WHEN (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +)

    (extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

    (excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

    extract ((DEUXIÈME à PARTIR de v_end_ts-v_st_ts) < 3600 THEN 1 END) less_than_1_hrs_count

    But the CASE above does not work. It returns the same value as COUNT (*). If the total number of tickets is 32 output will be

    total_tickets less_than_1_hrs_count

    32                                 32

    If I call the "calc_time_diff" then I get the correct result. What I'm doing wrong here?

    **********************************************************************************************************************************************************************

    SELECT

    Count (*) total_tickets,

    COUNTY ( CASE WHEN END of calc_time_diff (t.created_date, h.closed_date) < 3600 THEN 1) less_than_1_hrs_count

    OF n01.cc_ticket_info t

    JOIN IN-HOUSE

    (SELECT ticket_id, MAX (created_date) closed_date

    OF n01.cc_ticket_status_history

    WHERE ticket_status = 'CLOSED' AND created_date > = 18 August 2013 ' AND created_date < (to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY)

    GROUP BY ticket_id

    ) h

    WE (t.ticket_id = h.ticket_id)

    INNER JOIN n01.cc_ticket_notes n

    WE (n.created_date = h.closed_date)

    WHERE (t. ticket_status = 'NOTIFICATION' t.ticket_status 'CLOSED' = GOLD) AND t.created_date > = 18 August 2013 ' AND t.last_changed < to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY);

    ***********************************************************************************************************************************************************

    create or replace

    FUNCTION calc_time_diff)

    p_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %,

    p_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %)

    RETURN NUMBER

    AS

    v_no_sec NUMBER;

    v_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

    v_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

    BEGIN

    v_st_ts: = p_st_ts;

    v_end_ts: = p_end_ts;

    SELECT (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +.

    (extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

    (excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

    excerpt ((SECOND from v_end_ts-v_st_ts)

    IN v_no_sec

    DOUBLE;

    Return v_no_sec;

    END calc_time_diff;

    Hello

    You don't need a function defined by the user or the EXTRACT to find the difference between two timestamps.

    SELECT COUNT (*) AS total_tickets

    , COUNTY ( BOX WHEN h.closed_date < t.created_date="" +="" interval="" '1'=""> )

                         THEN 1

    END

    ) AS less_than_1_hrs_count

    ...

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • PLS-00103: error, produces the symbol

    Hi all, I am using a slider from my package spec, but when I do this, I get the error in a particular cursor below

    Spec
    CURSOR x_sysdate_rec IS
    SELECT sysdate
        --to_char(sysdate,'DD-MON-YYYY') "Date"
    FROM dual;
    x_sysdate      x_sysdate_rec%ROWTYPE;   
    Body
    44  PROCEDURE format_inv_rec IS
    45         x_report_start_date   := x_sysdate.sysdate;
    46        -- x_report_end_date   := x_sysdate.sysdate;
    47        --x_inv_date          := x_sysdate.sysdate;
    
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    45/32    PLS-00103: Encountered the symbol "=" when expecting one of the
             following:
             constant exception <an identifier>
             <a double-quoted delimited-identifier> table long double ref
             char time timestamp interval date binary national character
             nchar
             The symbol "<an identifier>" was substituted for "=" to continue.
    Can someone guide me where I am doing wrong.

    Thanks in advance!

    I think you missed to mention the data type for variables.

    PROCEDURE format_inv_rec IS
    x_report_start_date  date := x_sysdate.sysdate;
    -- x_report_end_date date := x_sysdate.sysdate;
    --x_inv_date         date := x_sysdate.sysdate;
    

    In addition, as hoek said, are why complicate things?

  • problem with counting seconds

    I found this function

    SELECT

    TRUNC (86400 *(date_to-date_from))-60 * (trunc ((86400 *(date_to-date_from)) / 60));
    TRUNC ((86400 *(date_to-date_from)) / 60)-60 * (trunc (((86400 *(date_to-date_from)) / 60) / 60));
    TRUNC (((86400 *(date_to-date_from)) / 60) / 60)-24 * (trunc (((86400 *(date_to-date_from)) / 60) / 60) / 24)),
    TRUNC (((86400 *(date_to-date_from)) / 60) / 60) / 24)

    IN tempsSec, tempsMin, timeHr, heureDAY

    FROM DUAL;

    Nice and easy compare two dates and return the (time) difference as 13 hours, 40 minutes, 10seconds

    now, my system shows delays like this from 10:00 to 10:19 (which is the duration of 9 seconds if you use the function above).
    now, what I tried to do is to add 1 second of time, since there are between 10:00 and 10:19 actuially 10 seconds elaps (0 to 1 (1 second), 1-2 (1 second)...)

    so I tried to just add a seconds before the date_to

    SELECT date_to + 1/24/60/60 INTO date_to FROM DUAL; -Add a second because 00 09 is 10 seconds of display time (not 9!)

    but sometimes, this provides a valid information, sometimes when counting only seconds each presents a wrong time, so there is an obvious mistake, I do somewhere...

    Rather than trying to debug the code you posted, it is probably easier to convert dates to timestamp, subtract the timestamps whiich returns an interval and extract the components of the interval.

    Note that I add 1 second in the inline query. For the subtraction normal timestamp, you who would remove.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with x as (
      2    select to_date( '10/24/2009 10:05:10',
      3                    'MM/DD/YYYY HH24:MI:SS' ) date_from,
      4           to_date( '10/24/2009 14:55:19',
      5                    'MM/DD/YYYY HH24:MI:SS' ) date_to
      6      from dual
      7    union all
      8    select to_date( '10/24/2009 10:05:10',
      9                    'MM/DD/YYYY HH24:MI:SS' ) date_from,
     10           to_date( '10/24/2009 10:05:29',
     11                    'MM/DD/YYYY HH24:MI:SS' ) date_to
     12      from dual
     13  )
     14  SELECT extract( day    from interval ) days,
     15         extract( hour   from interval ) hours,
     16         extract( minute from interval ) mins,
     17         extract( second from interval ) secs
     18    from (
     19  SELECT  to_timestamp(to_char(date_to,'MM/DD/YYYY HH24:MI:SS'),
     20                       'MM/DD/YYYY HH24:MI:SS')
     21          + interval '1' second
     22          - to_timestamp(to_char(date_from,'MM/DD/YYYY HH24:MI:SS'),
     23                       'MM/DD/YYYY HH24:MI:SS') interval
     24  FROM x
     25* )
    SQL> /
    
          DAYS      HOURS       MINS       SECS
    ---------- ---------- ---------- ----------
             0          4         50         10
             0          0          0         20
    

    Justin

  • FIRST HP: Normal Distribution

    Hello

    I am trying to solve the following equation:

    X - N(50,15^2) find Pr (50 < X < 70)

    When I type the above in the calculator, the following occur:

    I don't understand why I get a 'erf' rather than a decimal answer.

    Can anyone help me please with the help of the function of standard normal distribution on HP Calculator first.

    Thank you

    Arthur

    Please, do not change the settings of your CASE, as described. Usually it makes more problems then helps until you understand how things work a bit more. Default settings are almost always going to be better for most users.

    Basically, the reason for this is because you are in the display CASE. Click home, try again and you will see it comes out a decimal number. Putting a decimal value at the end of one of your own in the CASE would ALSO return a decimal value lead (as you say the CASE "Please calculate using values digital apprixmated, since I gave you an approximate numeric value with a decimal"), as would hit the function SHIFT + ENTER to close the last calculation After obtaining this result.  None of those are the best solutions instead of changing the settings as shown.

    As to which is the (Railroad), which is in fact the way in which the normal distributions are calculated. See this link for a large Description: http://mathworld.wolfram.com/NormalDistributionFunction.html

    Cite this page: ' or or erf may be expressed in terms finished additions, subtractions, multiplications and extraction of roots, and must therefore be either computed numerically or otherwise by approximation.»

    Essentially, the CASE is you give the representation exact, symbolic of your normal distribution using a function that represents a certain operation. These types of 'special functions' are becoming more frequent in senior type math/engineering calculations.

    When it comes to exact/approximate, mathematicians refer to the idea that something is "a perfect representation of the concept of this thing" or just "a number which is quite close to her.  For example, + infinity is a concept that CASES can actually understand, but a normal calculator could not - he could not hold a number large enough to be "infinite". Yet in many cases, simply put it in a very large number in the calculation is "good enough" to represent the positive idea of infinity.

    Another good example of this is pi. Are pi cannot be represented as a decimal number is perfect, but in most cases a round off the coast of the value is "close enough".   The first CASE mode takes all integer with no decimal to be "the idea of this number. For example, sqrt (2) return sqrt (2) in the form of CASE. It is not a number that can simplify low. If you try to do SQRT(2.) (<-note the. after the two), you say really "take the square root of the number which is"close enough"of the ideal value of 2. The calculator then returns a number that is "close enough" to the result perfect, exact square root.

    If you get an accurate result and want to see the decimal approximation, just press SHIFT ENTER. This sign of equality gribouilli little is the mathematical symbol for "approximates of»

    As to the last question, use this rule to help go you as you - if you try to get an approximate result of decimal number, the home screen is where you work. If you want accurate results, symbolic algebra, the CASE screen is where you work. If you are in the display CASE and you want a decimal result, press shift ENTER to run the command "about" that will make an estimate time of your last result in a decimal number. Make sense?

Maybe you are looking for