How to insert date value into oracle?

hi,
iam reading date from xml using vb.net and inserting it into oracle table.
the date value in xml file is in the format of "01012003".
i want to insert into oracle table.but iam getting an error "ORA-1843: not a valid month".
how to solve this problem.
Any suggestions or examples...

That's not a date. It's just a string. Convert it to a date using,
DateTime d = DateTime.ParseExact("01022003", "MMddyyyy", null);
or
Dim d As DateTime = DateTime.ParseExact("01022003", "MMddyyyy", Nothing)
and then bind it to a parameter. ODP.NET will take it from there.
You should never be hard-coding the date literal into your SQL query.
David

Similar Messages

  • Insert date time into oracle database from jsp

    pls tell me ,from jsp how can I insert datetime values into oracle database .I am using oracle 9i .here is codethat i have tried
    html--code
    <select name="date">
    <option selected>dd</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    </select>
    <select name="month">
    <option selected>dd</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    </select>
    <select name="year">
    <option selected>dd</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    </select>
    here the jsp code
    <% date= request.getParameter("date"); %>
    <% month= request.getParameter("month"); %>
    <% year= request.getParameter("year"); %>
    try
    { Class.forName("oracle.jdbc.driver.OracleDriver"); }
    catch (ClassNotFoundException exception)
    try
         Connection connection = null;
         out.println("connectiong the database");
    connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcsid","scott","tiger");
    out.println("connection getted");
         int rows = 0;
         String query_2 = "insert into mrdetails values(?)";
         String dob = date+month+year;
         prepstat = connection.prepareStatement(query_2);
         prepstat.setTimestamp(4,dob);
         rows = prepstat.executeUpdate();
         out.println("data updated");
    catch (Exception exception3)
    out.println("Exception raised"+exception3.toString());
    }

    To insert date values into a database, you should use java.sql.Date. If it also has a time component, then java.sql.TimeStamp.
    Your use of prepared statements is good.
    You just need to convert the parameters into a date.
    One way to do this is using java.text.SimpleDateFormat.
    int rows = 0;
    String query_2 = "insert into mrdetails values(?)";
    String dob = date+"/" + month+ "/" + year;
    SimpleDateFormat sdf = new SImpleDateFormat("dd/MM/yyyy");
    java.util.Date javaDate = sdf.parse(dob);
    java.sql.Date sqlDate = new java.sql.Date(javaDate .getTime);
    prepstat = connection.prepareStatement(query_2);
    prepstat.setTimestamp(4,sqlDate);
    rows = prepstat.executeUpdate();
    out.println("data updated");Cheers,
    evnafets

  • How to insert column values into database as rows

    Hi,
    I have 8 columns and some not null columns. Based on not null columns I want to insert into table as rows. The 8 columns may contain values or no value. If the first column contains data, then I have to insert into one row. if the second column contains data I have to insert a row and in second column. respectively...So How can I insert column values into rows. Can I write 8 insert statements. (OR) is it possible to insert data from columns using where clause.
    Please help me out....
    Thanks in Advance

    Lines Table:
    line_id, orcl_bank_account_num, product_type, service_type, lease_type,
    funding_type, cpi, billing_frequency_unit_cd , annual_due_date ,
    pricing_start_date, pricing_end_date, install_date, contract_end_date ,
    prdct_replacement_cost_amt, cradle_replacement_amt, supranet_contract,
    issuance_fee, board_inactive_date, header_id, creation_date, last_modified_date,
    created_by_nam, modified_by_nam, activeinactive_flg, prdct_bill_amt_yr1,
    prdct_bill_amt_yr2, prdct_bill_amt_yr3, prdct_bill_amt_yr4, prdct_bill_amt_yr5,
    prdct_bill_amt_yr6, prdct_bill_amt_yr7, prdct_bill_amt_yr8, activation_fee_yr1,
    activation_fee_yr2, activation_fee_yr3, activation_fee_yr4, activation_fee_yr5,
    activation_fee_yr6, activation_fee_yr7, activation_fee_yr8,
    In this table the columns structure is :
    -- PRDCT_BILL_AMT_YR (1 to 8) NUMBER(14,4)
    -- ACTIVATION_FEE_YR (1 to 8) NUMBER(8,2)
    I have one more table:
    PRDCT_INS_AMT               NUMBER(14,4)
    ACTIVATION_FEE_AMT          NUMBER(14,4)
    I want to insert prdct_bill_amt_yr (1 to 8) columns data into PRDCT_INS_AMT column. similarly activation_fee (1 to 8) columns data.
    But the data should be inserted based product_type, service_type, lease_type columns values. (These 3 columns may contain upto 45 combinations).

  • How to insert a value into a field of binary type?

    I've been using Oracle for a while now but never dealt with BLOB
    or long raw type before. Does anyone here know how to insert a
    record into a field of either blob or long raw type?
    Any suggestions would be very appreicated.
    Thanks.

    pls used the loadfromfile procedure which is in the DBMS_LOB
    package to insert the data from external os file into blob data
    type column.
    Kunjan

  • *HOW TO INSERT DATA MANUALLY INTO A BW TABLE*

    Dear experts,
    I'm working in BW 3.5 version.
    Since I need to test some tables which are going to be load manually, please could anyone explain me which are the steps to insert data manually into a BW table.
    Thank you very much in advance,
    Jorge

    Hi Jorge,
    You can maintain the TMG(Table maintenance generator) and then enter the data manually. TMG creation Tcode is se55. and to view and maintain TMG it is sm30 .
    Or if you have the data in excel. You can write a simple excel uploading ABAP program which will load your excel data to the table .
    Hope the above reply was helpful.
    Thanks & Regards,
    Ashutosh Singh
    Edited by: Ashutosh Singh on Apr 30, 2011 6:45 AM

  • How to insert date value through xml in oracle

    hi,  I am inserting data using xml string. Everything is working perfect but it shows error when i try to insert data into a table with date coloumn. it shows unparsable date error.... I am using this format of date 1-jan-2011
    my prcedure and java method is as follows...
    CREATE OR REPLACE procedure app_data.Insert_callrepHeader(xmlDoc in CLOB,t_id out varchar2,flag out varchar2) is
    insCtx DBMS_XMLSave.ctxType;
    rows number;
    t_tablename VARCHAR2(300);
    t_seqval varchar2(100);
    begin
    t_tablename:='T_CALLREPORT_HDR';
    insCtx := DBMS_XMLSave.newContext(t_tablename);
    rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc);
    dbms_output.put_line(to_char(rows) || ' rows inserted');
    DBMS_XMLSave.closeContext(insCtx);
    select SEQ_T_CALLREPORT_HDR.currval into t_seqval from dual;
    dbms_output.put_line(to_char(t_seqval) || ' is the current sequence number');
    end;
    public void insertAll(String[][] dbTblFieldValues) throws Exception
    Connection conn=null;
    conn=getOracleConnection();
    try
    String str="<ROWSET>"+
    "<ROW>"+
    "<PROCESSNAME>sheet</PROCESSNAME>"+
    "<FK_EMPID>1</FK_EMPID>"+
    "<FK_JRNY_PLAN_HDR_ID>278</FK_JRNY_PLAN_HDR_ID>"+
    "<FK_DIVISIONID>3</FK_DIVISIONID>"+
    "<STARTDATE>7-may-2011</STARTDATE>"+ what should be the format of this date????_+
    "<COMMENTSFORWEEK>comment</COMMENTSFORWEEK>"+
    "<SAPCODE>mysapcode300</SAPCODE>"+
    "<WEEKNO>1</WEEKNO>"+
    "<TOTALEXPENSE>800</TOTALEXPENSE>"+
    "<VENDORINVOICETYPE>mytype</VENDORINVOICETYPE>"+
    "<REPORTNO>1</REPORTNO>"+
    "<SUBPROCESSID>800</SUBPROCESSID>"+
    "</ROW>"+
    "</ROWSET>";
    StringBuffer sb = new StringBuffer(400000);
    sb.append(str);
    String clobValue = sb.toString();
    PreparedStatement preparedStatement=conn.prepareStatement("{call INSERT_CALLREPHEADER (?,?,?)}");
    preparedStatement.setString(1, clobValue);
    preparedStatement.setString(2,null );
    preparedStatement.setString(3,null );
    preparedStatement.execute();
    preparedStatement.close();
    conn.close();
    catch (Exception e) {
    // System.out.println(e.getMessage());
    e.printStackTrace();
    }

    I have got the answer...
    use DBMS_XMLSave.setdateformat(insCtx, 'dd-MM-yyyy'); and u can change ur date format....

  • Problems inserting date values in Oracle 10g

    Hi All,
    I'm having SERIOUS problems trying to insert a simple date value in my oracle.
    I did this one million times before in xMII 11.5, but now it appears that doesn't work anymore!
    Here are some info:
    Data Server Config:
    Date Prefix: TO_DATE('
    Date_Sufix: ', 'MM/DD/YYYY HH24:MI:SS')
    Internal Date Format: yyyy-MM-dd HH:mm:ss
    In my Query Template:
    Date and Time Format: MM/dd/yyyy HH:mm:ss
    In my Transaction
    Parameter: datefromxmlformat(datenow, "MM/dd/yyyy HH:mm:ss")
    I also tried change the parameter to datenow, no success.
    I tried to change the Query Template format, no success.
    Finally, I tried to change my Date prefix & sufix, no success too.
    I really don't know what else I can do. I would appreciate some help.
    PS: I'm using xMII 12.0.1 with ojdbc14.jar
    Thanks in advance.
    Pedro Sena

    Pedro,
    The Data Server config for InternalDateFormat should be:  MM/dd/yyyy HH:mm:ss
    This is because it is used in conjunction with the DatePrefix and DateSuffix whenever you use the DateColumn or  the [SD] and [ED] tokens in a query template.
    If you are inserting a date field with an arbitrary parameter (not a date token like above) then you need to use the TO_DATE wrapper pieces around your date field string.
    The DateFormat in the query template controls the format of the StartDate and EndDate buttons in the applet toolbar if using an iChart/iSPCChart/iGrid and a time sensitive query, but when you build the string for an insert parameter you must manage the whole format yourself.
    If you really just want datenow and the xMII server time is sufficient for your insert query then you can leverage the Data Server config settings like: INSERT INTO TABLE VALUES([ED)
    This way the default query template time settings will use 'now' for the end date of the query and when the string is sent to Oracle it will actually look like:
    INSERT INTO TABLE VALUES(TO_DATE('10/19/2007 08:41:00', 'MM/DD/YYYY HH24:MI:SS'))
    Regards,
    Jeremy

  • How to insert & # special characters into oracle table?

    I have a text value which contains special characters such as & and #.
    After I pass from one page to another,
    TEST& becomes "TEST&amp;"
    I put " " on the above test, otherwise amp; will be truncated by OTN).
    TEST# becomes TEST (# is truncated).
    Actually the value is saved in table like this: "TEST&amp;"
    How to solve this problem?
    How to insert & into table without &amp;
    Thank you.
    Edited by: user628655 on Jul 27, 2009 9:47 AM
    Edited by: user628655 on Jul 27, 2009 9:49 AM
    Edited by: user628655 on Jul 27, 2009 10:39 AM

    Avoid doing that through a link. If this is a page item then submit the page and redirect to the target page using a branching. On the target page, create a computation to compute the target item using the original page item as the source. If you are talking about a report, use the id to pass through the link and fetch the text column in an on load computation.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------

  • How to insert parameter value into multiple columns and rows

    Hi All,
    I have one procedure insert_tab and I am passing
    100~101~102:103~104~105:106~107~108 as a parameter to that procedure. I wanted to insert each numeric value into one column. The output of the table should contain
    Table:
    Col1 Col2 Col3
    100 101 102
    103 104 105
    106 107 108
    Awaiting for your reply..

    That's not more clear for me...
    Anyway, if you really want a procedure for that, try :
    SQL> create table tblstr (col1 number,col2 number,col3 number);
    Table created.
    SQL>
    SQL> create or replace procedure insert_fct (p_string IN varchar2)
      2  as
      3  v_string     varchar2(4000):=p_string||':';
      4  v_substring  varchar2(4000);
      5 
      6  begin
      7      while instr(v_string,':') > 0 loop
      8            v_substring := substr(v_string,1,instr(v_string,':')-1)||'~';
      9            insert into tblstr(col1,col2,col3)
    10            values (substr(v_substring,1,instr(v_substring,'~',1,1)-1),
    11                    substr(v_substring,instr(v_substring,'~',1,1)+1,instr(v_substring,'~',1,2)-instr(v_substring,'~',1,1)-1),
    12                    substr(v_substring,instr(v_substring,'~',1,2)+1,instr(v_substring,'~',1,3)-instr(v_substring,'~',1,2)-1));
    13            v_string:=substr(v_string,instr(v_string,':')+1);
    14      end loop;
    15  end;
    16  /
    Procedure created.
    SQL>
    SQL> show err
    No errors.
    SQL>
    SQL> select * from tblstr;
    no rows selected
    SQL> exec insert_fct('100~101~102:103~104~105:106~107~108')
    PL/SQL procedure successfully completed.
    SQL> select * from tblstr;
          COL1       COL2       COL3
           100        101        102
           103        104        105
           106        107        108
    SQL> exec insert_fct('109~~')
    PL/SQL procedure successfully completed.
    SQL> exec insert_fct('~110~')
    PL/SQL procedure successfully completed.
    SQL> exec insert_fct('~~111')
    PL/SQL procedure successfully completed.
    SQL> select * from tblstr;
          COL1       COL2       COL3
           100        101        102
           103        104        105
           106        107        108
           109
                      110
                                 111
    6 rows selected.
    SQL> Nicolas.

  • How to insert data with & into table..

    Hi,
    i want to insert following data to table
    sql>insert into emp values('company & co');
    Enter value for co:
    how to avoid this ?

    You should disable the interactive prompt in SQL Plus. How to do check this link
    http://www.orafaq.com/wiki/SQL*Plus_FAQ#How_does_one_disable_interactive_prompting_in_SQL.2APlus.3F

  • How to insert object values into table.

    Hi All,
    I have a problem with passing java object to procedure. Procedure is running properly when I execute in oracle,but it is not executing when I call from Java.
    I am getting Error :
    java.sql.SQLException: invalid name pattern: Pkg_Bulk_Insert.ITW_EMP_OBJ_ARRAY
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
         at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java)
         at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java)
         at oracle.sql.ArrayDescriptor.initPickler(ArrayDescriptor.java)
         at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java)
         at JavaObjectToOracle.main(JavaObjectToOracle.java:31)
    Here I am copying my procedure,oracle version is 9i.
    Package specification:
    CREATE OR REPLACE PACKAGE Pkg_Bulk_Insert AS
    TYPE ITW_EMP_OBJ_ARRAY IS VARRAY(20) OF VARCHAR2(200);
    PROCEDURE BULK_INSERT_TEST(strTable IN ITW_EMP_OBJ_ARRAY);
    END Pkg_Bulk_Insert;
    package body:
    CREATE OR REPLACE PACKAGE BODY Pkg_Bulk_Insert AS
    PROCEDURE BULK_INSERT_TEST(strTable IN ITW_EMP_OBJ_ARRAY) AS
    i BINARY_INTEGER;
    BEGIN
    FORALL i IN 1..strTable.COUNT
    INSERT INTO TEMP(NAME)
    VALUES(strTable(i));
    COMMIT;
    END BULK_INSERT_TEST;
    END Pkg_Bulk_Insert;
    Here I am invoking the procedure:
    DECLARE
    x Pkg_Bulk_Insert.ITW_EMP_OBJ_ARRAY;
    BEGIN
    x := Pkg_Bulk_Insert.ITW_EMP_OBJ_ARRAY('A','B','C');
    Pkg_Bulk_Insert.BULK_INSERT_TEST(x);
    DBMS_OUTPUT.PUT_LINE('AFTER INSERTION');
    END;
    Please any body can help me on this regard.

    Your PL/SQL seems reasonable.
    My suspicion would be that the oracle.sql.ArrayDescriptor.createDescriptor class only supports persistent collection types, i.e. those declared at the schema level with CREATE TYPE.

  • How to insert a value into a table

    I have an ordering system. It displays all the orders by
    customer ID. If an order is complete, a check number is entered for
    the corresponding line item, otherwise it is left blank.
    My code uses the following code to display the form. All are
    display fields only, except for the last one, where the check
    number can be entered.
    <cfoutput query="qryDetail" group="partNumber">
    <tr>
    <td valign="top" class="TitleText"
    align="center">#lineItem#</td>
    <td valign="top" class="TitleText"
    align="center">#OrderNumber#</td>
    <td valign="top" class="TitleText"
    align="center">#partNumber#</td>
    <td valign="top" class="TitleText"
    align="center">#dollarformat(qryDetail.unitValue)#</td>
    <td valign="top" class="TitleText" align="center">
    <cfinput type="text" name="checkNumber#keyID#">
    <input type="hidden" name="keyID"
    value="#qryDetail.keyID#">
    </td>
    I use something like the following to update the table with
    the check numbers entered.
    <cfloop index="KeyID" list="#form.KeyID#"
    delimiters=",">
    <cfquery name="qryUpdate" datasource="dbName">
    update tblChecks
    set checkNumber = '#Evaluate("form.checkNumber#KeyID#")#'
    where custID = '#form.custID#'
    and KeyID = '#KeyID#'
    </cfquery>
    </cfloop>
    Now we have another table that will contain the customer
    order history. If the check number was entered for a particular
    line item, I need to insert that line item nubmer into this table,
    along with some other columns. I tried to use the same loop, then
    other loops, but cannot seem to get this to work. Seems simple
    enough, but I obvisouly am missing something.
    How would I insert the line item number (only if a check
    number was entered for that line item) into the table ?

    Here is the code with the queries commented out :
    <cfloop list="#form.fieldnames#" index="field">
    <cfif left(field, 11) is "checkNumber" AND
    len(trim(form[field]))>
    <cfset keyID = listlast(field, '_')>
    <cfset lineItem = listgetat(field, 2, '_')>
    <cfset checknum = form[field]>
    <!---cfquery name="qryUpdate" datasource="dbName">
    UPDATE tblChecks
    SET checkNumber = '#checknum#'
    WHERE custID = #form.custID#
    AND KeyID = #keyid#
    </cfquery--->
    <cfoutput> loop is
    field: <b>#field#</b><br>
    checknum: #checknum#<br>
    lineitem: #lineitem#<br>
    keyID: #keyID#<br>
    </cfoutput>
    <cfelse>
    <cfoutput>Else is
    field: <b>#field#</b><br>
    form[field]: #form[field]#<br>
    len: #len(trim(form[field]))#<br>
    </cfoutput><cfabort>
    </cfif>
    </cfloop>
    This is the output. If I do not put in cfabort, the code just
    drops thru and I never see any output display, so I use cfabort to
    stop so I can see the output.
    loop is field: CHECKNUMBER_11_218
    CHECKNum: xxxxxxxxxxxxxxxxxxxx
    lineitem: 11
    keyID: 218
    Else is field: CHECKNUMBER_1_24
    form[field]:
    I entered the x's into checknum for line item 11, so that is
    correct.
    I then took out the comments from the update query and tried
    it again and it updated for line item 11 (you were right, I had to
    take out the single quotes in the query). I then removed the
    commets for the insert query and it did not insert. I tried the
    whole thing again and tried to add to line item 10 and it dropped
    straight to the else part, displaying :
    Else is field: CHECKNUMBER_1_24
    form[field]:
    len: 0
    So it seems the if statement if failing the second time thru
    the loop :
    <cfif left(field, 11) is "checkNumber" AND
    len(trim(form[field]))>
    This is my input statement :
    <cfinput type="text"
    name="checkNumber_#lineItem#_#keyID#">
    I am really confused now. It seems to work the first time
    thru the loop, then the second time it fails.

  • How to insert new record into oracle table from GridView in VS2005.

    I need to insert records into Oracle10g table from VS2005 GridView using the Insert Method in Business Logic Class. The Update and Delete Methods are working fine. What's the best way out?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • Sqlloader: how to insert -ve value into table

    hi..
    i had problem during loading. The error is Record 1: Rejected - Error on table FILE01, column AMOUNT.
    ORA-01722: invalid number
    For AMOUNT, the datatype is number(20,2).
    here is my .ctl
    LOAD DATA
    INFILE 'file1bp0103.txt'
    BADFILE 'file01.bad'
    APPEND
    INTO TABLE file01
    acct_no POSITION(01:13),
    amount POSITION(14:28),
    description POSITION(29:32)
    my .dat file
    A500000030401- 32.74PYMT
    A500000320106- 46.95PYMT
    A500000520408- 63.95PYMT
    A500000610301- 12.99PYMT
    A500001720110- 56.21PYMT
    A500001800103- 55.65PYMT
    A500002000109- 27.25PYMT
    A500002000305- 53.35PYMT
    A500002080210- 75.04PYMT
    A500002250106- 103.38PYMT
    A500002500104- 60.69PYMT
    A500002620902- 509.77PYMT
    A500002621010- 398.69PYMT
    what is the problem? is it because of my datatype?
    please help me..
    TQ

    Is there a need to use dynamic sql here?
    at the very least, try using bind variables instead of concatenating values like that.
    EXECUTE IMMEDIATE 'insert into your_table (column_list) values (:val1, :val2, ...)'
    USING l_val1, l_val2, l_val3 ... ;

  • How to insert new value into an array

    I have an already declared array (including the size) and want to write a method for inserting a new value. Do I have to re-declare the array to the new size? ie old size + 1, then add the new value or is there a java method for this. I can't find one.
    Thanks in advance....
    Mike

    Hi,
    there is no method for that. Look up class Vector. That class implements automatic growing of the Vector.
    Phil

Maybe you are looking for

  • Status Bar at the bottom of applet

    Hi, How can I get rid of Status bar at the bottom of an applet? I dont' wana see word "Java Applet Started". I have called JFrame.setDefaultLookAndFeelDecorated(true); Everything is fine, but the unwanted status bar at the bottom. Any help is greatly

  • Very dark image on external big screen

    Hi. I've got my 15"MBP attached to a Samsung 40" via miniDV out to VGA. Picture on the big screen is a lot darker than the Computer screen. Settings on the TV don't improve it. Also pretty dim when going through data projectors as well all on VGA. An

  • In Elements 13, how do I type a word on a photo when all I can do with "T" is get a line, e.g., ________?

    I had been able to type text on a photo, but suddenly I am only able to get a line instead of a text.

  • Bug - Miniplayer loses search

    Hi, I would like to report a possible bug in Itunes 9.0.2.25 for Windows Vista. When activating the miniplayer the search field resets. So if you want to play only songs that match the criteria "chill" and you activate the miniplayer the search crite

  • Can't hear my electric guitar in garageband, I've read all prior posts-.

    And I want to play sooooo bad!! Here's my set up: (input) USB to 1/4 jack to guitar (headphone output) 1/8 to 1/4 to guitar amp (I can hear anything else on my MBP through the amp) Preferences: Audio/MIDI- Output is set to built in