String field value convert into Date with validation

Dear all,
I need some help if someone can please?
Actually I am getting date in string format as 20110315 or 20111025 or so on. I could use to date function for this for conversion but what if 20091432 which is wrong so I can hadle this.
Actually I m using oracle 10g and using anonymous pl SQL block . Can't write function or procedure for this. So I am extracting all the data including date as above and setting some flag so if date is correct then y otherwise no. Pls help. I think I have described everything what exactly I want?
If date is correct then insert in the different table otherwise setting flag if date is not correct. I.e. bdate varchar2
Best regards,
Edited by: Irha10 on 26-Jul-2012 12:29

Why wouldn't you be able to use a function or procedure in your anonymous block?
SQL> declare
  2  --
  3   function is_valid_date
  4    ( p_str in varchar2
  5    , p_format in varchar2 default 'yyyymmdd'
  6    )
  7    return varchar2
  8    as
  9      dt date;
10    begin
11      dt := to_date(p_str, p_format);
12      return 'Valid';
13    exception
14      when others
15      then
16        return 'Invalid'; 
17    end;
18  --
19  begin 
20    for rec in ( select 20110315 str from dual union
21                 select 20111025 from dual union
22                 select 20091432 from dual
23               )
24            
25    loop
26      dbms_output.put_line(rec.str||'  '||is_valid_date(rec.str));
27    end loop;
28  end;
29  /
20091432  Invalid
20110315  Valid
20111025  Valid
PL/SQL procedure successfully completed.Just a small example, instead of dbms_output, you could do an update of a 'Valid' column etc. etc...

Similar Messages

  • I have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    i have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    What does this have to do with iPhone tech support?

  • Blank field getting converted into wrong date

    Dear All,
    I have one date field in SAP table in which there are some entries and some blank entries.
    when Proxy is sending this data from ECC blank entries are converted into 00000000 and through XI in file
    this
    00000000 entry for date getting converted into wrong date like 30.11.0002 in file.
    I have taken data type as string do I need to take data type as date.
    My doubt is if there is no entry in table why it is convertng to  00000000  and after passing from XI why it is converting into
    30.11.0002 .
    Regards

    Hi ,
    My date format like this
    source --yyyyMMDD
    target-DD.MM.YYYY
    so if
    source is
    00000000
    should comes like this
    target
    00.00.0000
    but it is converting into
    30.11.0002
    every where in file values for 00000000 is coming like 30.11.0002
    Regards

  • Fetching logic after converting into Date?

    Hi,
    I have a column Date1 which is a DATETIME datatype.
    First i give the following line in where clause
    "Date1   between '2014-05-05 00:00:00' and '2014-05-05 00:00:00'"
    After this it fetches only those rows where Date1 exactly is 2014-05-05 00:00:00
    Then I issue the following line in the where clause
    "CONVERT(DATE,Date1,103)   between '2014-05-05 00:00:00' and '2014-05-05 00:00:00' "
    How come after converting it into date it fetches all the values that fall on 2014-05-05
    even though the time is hard coded in the between as 00:00:00
    Thanks and Regards
    Regards

    Actually i am getting the correct output after entering the following line in the where clause
    "CONVERT(DATE,Date1,103)   between '2014-05-05 00:00:00' and '2014-05-05 00:00:00' 
    But i just want to know how sql server fetches all data (correct data)  that fall on 2014-05-05 inspite of hard coding with time as 2014-05-05
    00:00:00 and 2014-05-05 00:00:00 in the above where clause.
    Thanks and Regards
    Regards
    The way you're using it will cause optimizer to ignore an index if present in Date1 field.
    When you just pass datepart alone to date field time will default to start of the day (00:00:00 hours of the day). So it starts filtering the data from start of day onwards. Similarly for end day it will filter till the start of date ie including end seconds
    of previous date
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • ALV QUANTITY field Geting converted into decimals ?

    Hi All ,
    I have developed an alv report .In that the quantity field is made editable after editing the quantity when i save it .It gets converted into decimals.Suppose if i give 77 its getting reflected as .077 all the field name ,table name ,reference field name, reference table name, quantity field data type has been passed but the problem persists.If there is any one whos has come across this kind of scenario please share your thoughts on this.
    Best Regards,
    Sreeram

    Hi Sreeram,
    I am not gettin this issue. See below code :
    If you are gettiing the same issue with the below code then it has something to do with your user settings.
    Go to Menu Item System -> User Profile -> Own Data -> Defaults ->Decimal Notation.
    Set it to 1,234,567.89 and save. Now try the program again.
    REPORT z_test.
    TYPE-POOLS: slis.
    TYPES : BEGIN OF ty_ekpo,
              ebeln TYPE ebeln,
              ebelp TYPE ebelp,
              ktmng TYPE ktmng,
              menge TYPE bstmg,
            END OF ty_ekpo.
    DATA: it_ekpo TYPE TABLE OF ty_ekpo,
          it_fieldcat TYPE slis_t_fieldcat_alv.
    SELECT ebeln ebelp ktmng menge
      FROM ekpo
      INTO TABLE it_ekpo
      UP TO 20 ROWS.
    PERFORM add_fieldcat USING 'EBELN'.
    PERFORM add_fieldcat USING 'EBELP'.
    PERFORM add_fieldcat USING 'KTMNG'.
    PERFORM add_fieldcat USING 'MENGE'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       i_callback_program                = sy-repid
       it_fieldcat                       = it_fieldcat
      TABLES
        t_outtab                          = it_ekpo
    EXCEPTIONS
       program_error                     = 1
       OTHERS                            = 2
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    FORM add_fieldcat  USING  p_fieldname TYPE slis_fieldcat_alv-fieldname.
      DATA: wa_fieldcat TYPE slis_fieldcat_alv.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = p_fieldname.
      wa_fieldcat-tabname = 'IT_EKPO'.
      wa_fieldcat-ref_fieldname = p_fieldname.
      wa_fieldcat-ref_tabname = 'EKPO'.
      IF p_fieldname EQ 'KTMNG'.
        wa_fieldcat-edit = 'X'.
      ENDIF.
      APPEND wa_fieldcat TO it_fieldcat.
    ENDFORM.                    " ADD_FIELDCAT
    Regards,
    Jovito

  • Stop download to Excel from converting string of digits & dashes into date

    Hi,
    How can I stop BI and Excel data from converting a column of string data that is comprised of numbers and dashes into a date format when it is downloaded into Excel?
    I'd like to solve this problem in BI, so that any users can download the data from a BI report into Excel without having to change the Excel date column back into a string column.
    Thanks,
    Darcy

    Hi Again Darcy,
    hmmm... That is very interesting. I just tried on OBIEE 10.1.3.2 ( a version before yours) on Windows XP with Office 2003 and an Oracle 11g DB backend and it did not have any problems pulling the value as text and not a DATE
    Can you try something for me? In a new report, add any old dimensional (year, month name, etc) field twice into the report and change the second column formula to be following: '7001-2'
    Try to export that report and see if that value comes through as text or a date. If it is something about the SQL server data set, then the above test should come through as text object in your excel download because we aren't pulling it from SQL Server, we'll creating it directly in OBIEE. If the above test does come through as a date, then it should mean that SQL Server isn't the issue. And if that is the case, I am starting to wonder if there's a setting in Office to can be enabled/disabled to avoid any data casting.
    Best regards,
    -Joe

  • Convert into Data Table issue from Excel Sheet Table

    Hi 
    i've excel file where 10-12 sheets are available in that excel file.one of the sheet is named as summary.there are 8-10 tables(named as Table1,Table2,Table3....) in that summary sheet as well. 
    i've to actually get the Table1 from the summary sheet into the DataTable. 
    So,i've written a following method to read "summary" sheet and then i checked if the Table1 exist then break the loop.My problem is i've found Table1 but i am not able to convert it into the DataTable.Can anyone tell me how to do it.
    private void GetProjectTable(string ExcelFileUrl)
    string sheetName = "Summary";
    string value = null;
    // Open the spreadsheet document for read-only access.
    try
    String siteURL = SPContext.Current.Site.Url;
    SPSecurity.RunWithElevatedPrivileges(delegate()
    Stream dataStream = null;
    using (SPSite site = new SPSite(siteURL))
    using (SPWeb web = site.OpenWeb())
    SPFile file = web.GetFile(ExcelFileUrl);
    dataStream = file.OpenBinaryStream();
    using (SpreadsheetDocument document =
    SpreadsheetDocument.Open(dataStream, false))
    // Retrieve a reference to the workbook part.
    WorkbookPart wbPart = document.WorkbookPart;
    Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
    Where(s => s.Name == sheetName).FirstOrDefault();
    // Throw an exception if there is no sheet.
    if (theSheet == null)
    throw new ArgumentException("sheetName");
    WorksheetPart wsPart =
    (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
    DocumentFormat.OpenXml.Spreadsheet.Table table = null;
    DataTable dt = null;
    foreach (TableDefinitionPart tdp in wsPart.TableDefinitionParts)
    if (tdp.Table.DisplayName == "Table1")
    table = tdp.Table;
    break;
    catch (Exception ex)
    Note: I am using this code in the Visual Web Part for SharePoint

    Hi hellofragrance,
    According to the description, you want to convert to the table in Excel to DataTable using Open XML SDK.
    As far as I know, there is no such API we can achieve the goal directly. However, we can write custom code to complete the job. Here are some major steps for your reference:
    1. Get the information of the table we wanted to convert. For example, column information and the range address for the table. And we can get the these information via the
    Table object of
    TableDefinitionPart Class
    2. Then we can create a DataTable via the column information we get from step1 and initialize the data table via read the data from range of table.
    In addition, here is helpful article about read the value of specific cell for your reference:
    How to: Retrieve the values of cells in a spreadsheet document (Open XML SDK)
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Can't set a hidden field value from onClick event with a runtime expression

    Hi,
    I need to set a hidden field in an onClick event of button but it's not working.
    <html:submit styleClass="btnLink" onclick="document.empForm.hidden.value='<%= empID%>'">
    <%= empID%>
    </html:submit>
    Althought the second expression is evaluated and written successfully "the button value"
    I heard that this is because you can't mix the value of an attribute of a custom tag with both string literal and run time expressions.
    Is there any work around to solve that?
    I can't use EL as I'm using old JSP version

    I guess, it should work; instead of html:submit, try with button.

  • JSF page values are getting cleared with validation errors

    Using Jdev 10.1.3.4, JSF and ADF BC
    I have 2 jspx pages - 1 input page(with bindings to VO) and a lookup page bound to a read-only VO.
    page1: I am entering values to all the fields and then saving the form. Now if I had entered an invalid value for one of the fields and try to save - I am checking if value is valid in page1's managed bean and returning error message.
    After I get this error message I clear out the invalid value and use the lookup & navigate to the 2nd page fetch a valid value and when I return to my 1st page I am loosing values for some of the fields in my 1st page. Not sure how and this is my first issue! I dont see this behavior if I use the lookup option directly(instead of entering an invalid value, clearing the value after seeing the error message and then going to the lookup page)
    Next I am reentering values that I have lost and when I try to save again this time the value I had set from the lookup page is cleared and since this field is required I am getting an exception again. So, basically once there is an error for a field any new value I set gets cleared on commit and i get a required message for the field. Thanks for any clarifications/help with these strange issues.

    Fair enough :)
    Actually what I was meaning was could I use a collection to repopulate the tabular form when I receive errors. It appears as if it may work. However, I am hitting one snag.
    I have created a PL/SQL Process that runs On Submit and Before Computations/Validations. In this process, I have saving the values in the tabular form to a collection.
    I was then hoping to create another process that ran after any errors occur. However, it does not appear as if any processes run when the screen redraws after a validation issue. Is there a process that runs after validations when the screen is redrawing? Will I need to do this using javascript?
    Thanks

  • How to revise form field value in query and skip validation

    Hi all,
    I have a 10g form that has a field which I want to manipulate during query. I want to display a different value depending upon its orignal value. I did this with a Post-Query trigger on the field's datablock. However, now, when I attempt a new query, the form thinks I've changed the field (which I did). I want to change the field but trick Forms into thinking there were no updates. How do I do this? Note: the field is a list item that has a style of combo box.
    Thanks, Mike

    Ammad,
    The reason is that sometimes the list returns the record group's key value (the second column) instead of the intended value (in the first column). This is because the record group is based on a SQL query. There are some values which are no longer in the table queried by the record group, thus the key value is displayed. I would rather nothing be displayed. As of now, I display a message indicating that there is a problem with the LOV.
    I know about using a non-database form field. But I don't have any room left and I don't want to lay the non-database field on top of the database field and then have to enable/disable the two fields.
    A friend at work suggested setting update_permission to trick Forms. Tried it but not successful yet.
    Thanks, Mike

  • Force user to change cost center master data with validity date

    Dear All!
    we do have customer fields in table for cost centers (CSKS) and would like to force the user to do changes for these customer fields in combination with the change of the validity from/to date. I did not find any possibility to add this functionality with the customizing transaction OKEG or any other transaction. We now would need some good ideas from you as SAP experts!
    Regards,

    Hi,
    You can use COOMKS02 enhancement.
    Regards,
    Eli

  • Need to convert into date format

    Hi all,
    I need to convert '2008-11-26T11:07:38-06:00' [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][TIMEZONE]
    in format 'YYYY-MM-DD HH:MM:SS'.
    Thanks in advance.

    >
    Thank you for your reply
    But it is giving me output as '26-NOV-08'
    And I want in format '2008-11-26 07:38' i.e 'YYYY-MM-DD HH:MM'.
    >
    Then you are not looking for a date, You are looking for a string.
    The date format that gets displayed is dependent on nls_date_format parameter.
    If you want a string in the format you asked, then,
    SELECT TO_CHAR ( TO_DATE ( '2008-11-26T11:07:38-06:00', 'YYYY-MM-DD"T"HH24:MI:SS"-06:00"'), 'YYYY-MM-DD HH24:MM:SS')
      FROM DUAL;Or if you just want the date to be displayed like that then
    Do,
    SQL> alter session set nls_date_Format="YYYY-MM-DD HH24:MI:SS";
    Session altered.
    SQL> SELECT TO_DATE ( '2008-11-26T11:07:38-06:00', 'YYYY-MM-DD"T"HH24:MI:SS"-06:00"') dt
      2    FROM DUAL;
    DT
    2008-11-26 11:07:38
    SQL> G.

  • Float value converted into unwanted value

    Hello,
    I have a situation with a strange float(22) value conversion during insert. Value 244655737199025 appears as 244655700000000 in the desination table.
    It is a simple "insert into +table1+ select from +view1+" statement.
    The result of "select * from view1" is correct though.
    Any ideas?
    Edited by: avtandil on Apr 29, 2009 12:17 PM

    Sorry, my bad.
    I can see the source of the issue. In an OraEdit tool I use for Pl/Sql programming:
    SQL>desc table1 (target)
    FORMINDEX          FLOAT(22)
    SQL>desc view1
    FORMINDEX          FLOAT(22)
    In SQLPlus
    SQL>desc table1 (target)
    FORMINDEX          FLOAT(22)
    SQL>desc view1
    FORMINDEX          FLOAT(126)
    Thanks guys

  • Not able to get the taxonomy field value of meta data field type

    Hi Everyone,
    Not able to get the taxonomy filed value from the metadata filed type.
    Any one can help me on this.
    Label, TermGuid, ValidatedString are showing empty when i debug the code.
    Below is the code which i used to get the taxonomy filed value

    Hi,
    Can you please try getting this way?
    var taxonomyField = listItem.Fields.GetFieldByInternalName(fieldName) as TaxonomyField;
    if (taxonomyField.AllowMultipleValues)
    var fieldValuesCollection = listItem[taxonomyField.Title] as TaxonomyFieldValueCollection;
    return fieldValuesCollection.Select(x => new Guid(x.TermGuid)).ToList();
    else
    var fieldValue = listItem[taxonomyField.Title] as TaxonomyFieldValue;
    return new List<Guid>() { new Guid(fieldValue.TermGuid) };
    Hope it helps!
    Thanks,
    Avni Bhatt
    If this helped you resolve your issue, please mark it Answered

  • Retrive data with valid row only

    Hi All,
    Below is my source table.
    CUST_ID     CUST_NAME     VALID_FLAG     ROW_seq
    010     A          0          1
    020     B          1          2
    030     C          0          3
    040     D          0          4
    050     E          1          5
    060     F          0          6
    070     G          1          7
    080     H          0          8Source contains million of records in table and i do not want to load all at once. Also valid_flag is varchar2 and if it has flag 0 then it is valid record, and if it is 1, then it is invalid.
    Now lets say, my batch size is 2. in that case, first batch should take
    CUST_ID     CUST_NAME     VALID_FLAG     ROW_seq
    010     A          0          1     
    030     C          0          3second batch should take
    CUST_ID     CUST_NAME     VALID_FLAG     ROW_seq
    040     D          0          4
    060     F          0          6and third bacth should take
    CUST_ID     CUST_NAME     VALID_FLAG     ROW_seq
    080     H          0          8How to get the valid number of records from table, while excluding invalid record. I have done it using PL/SQL procedure and it workd fine, but we are required to use only SQL statement to achive this.
    How to achive same with SQL statement?

    ace_friends22 wrote:
    Hi All,
    Below is my source table.
    CUST_ID     CUST_NAME     VALID_FLAG     ROW_seq
    010     A          0          1
    020     B          1          2
    030     C          0          3
    040     D          0          4
    050     E          1          5
    060     F          0          6
    070     G          1          7
    080     H          0          8Source contains million of records in table and i do not want to load all at once. Also valid_flag is varchar2 and if it has flag 0 then it is valid record, and if it is 1, then it is invalid.
    How to get the valid number of records from table, while excluding invalid record. I have done it using PL/SQL procedure and it workd fine, but we are required to use only SQL statement to achive this.
    How to achive same with SQL statement?Do you only want to have the count of valid records from the table?
    select count(1) from table where valid_flag = '0'I'd consider a bitmap-index on valid_flag as well, to avoid full table scans on the source table.
    Brgds
    Johan

Maybe you are looking for