Restful service unable to insert data using PL/SQL.

Hi all,
Am running: AL 2.01 standalone mode on OEL 4.8 in VM box A.
Oracle database 10.2.0.4 with Apex 4.2.0.00.27 on OEL4.8 in VM box B.
Able to performed oracle.example.hr Restful services with no problem.
Unable to insert data using AL 2.0.1 but works on AL 1.1.4.
which uses the following table (under schema: scott):
create table json_demo ( title varchar2(20), description varchar2(1000) );
grant all on json_demo to apex_public_user; and below procedure ( scott's schema ):
CREATE OR REPLACE
PROCEDURE post(
    p_url     IN VARCHAR2,
    p_message IN VARCHAR2,
    p_response OUT VARCHAR2)
IS
  l_end_loop BOOLEAN := false;
  l_http_req utl_http.req;
  l_http_resp utl_http.resp;
  l_buffer CLOB;
  l_data       VARCHAR2(20000); 
  C_USER_AGENT CONSTANT VARCHAR2(4000) := 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
BEGIN
  -- source: http://awads.net/wp/2005/11/30/http-post-from-inside-oracle/
  -- Ask UTL_HTTP not to raise an exception for 4xx and 5xx status codes,
  -- rather than just returning the text of the error page.
  utl_http.set_response_error_check(false);
  -- Begin the post request
  l_http_req := utl_http.begin_request (p_url, 'POST', utl_http.HTTP_VERSION_1_1);
  -- Set the HTTP request headers
  utl_http.set_header(l_http_req, 'User-Agent', C_USER_AGENT);
  utl_http.set_header(l_http_req, 'content-type', 'application/json;charset=UTF-8');
  utl_http.set_header(l_http_req, 'content-length', LENGTH(p_message));
  -- Write the data to the body of the HTTP request
  utl_http.write_text(l_http_req, p_message);
  -- Process the request and get the response.
  l_http_resp := utl_http.get_response (l_http_req);
  dbms_output.put_line ('status code: ' || l_http_resp.status_code);
  dbms_output.put_line ('reason phrase: ' || l_http_resp.reason_phrase);
  LOOP
    EXIT
  WHEN l_end_loop;
    BEGIN
      utl_http.read_line(l_http_resp, l_buffer, true);
      IF(l_buffer IS NOT NULL AND (LENGTH(l_buffer)>0)) THEN
        l_data    := l_data||l_buffer;
      END IF;
    EXCEPTION
    WHEN utl_http.end_of_body THEN
      l_end_loop := true;
    END;
  END LOOP;
  dbms_output.put_line(l_data);
  p_response:= l_data;
  -- Look for client-side error and report it.
  IF (l_http_resp.status_code >= 400) AND (l_http_resp.status_code <= 499) THEN
    dbms_output.put_line('Check the URL.');
    utl_http.end_response(l_http_resp);
    -- Look for server-side error and report it.
  elsif (l_http_resp.status_code >= 500) AND (l_http_resp.status_code <= 599) THEN
    dbms_output.put_line('Check if the Web site is up.');
    utl_http.end_response(l_http_resp);
    RETURN;
  END IF;
  utl_http.end_response (l_http_resp);
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line (sqlerrm);
  raise;
END; and executing in sqldeveloper 3.2.20.09 when connecting directly to box B as scott:
SET serveroutput ON
DECLARE
  l_url      VARCHAR2(200)   :='http://MY_IP:8585/apex/demo';
  l_json     VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
  l_response VARCHAR2(30000);
BEGIN
  post( p_url => l_url, p_message =>l_json, p_response => l_response);
END;which resulted in :
anonymous block completed
status code: 200
reason phrase: OK
with data inserted. Setup using 2.0.1
   Workspace : wsdemo
RESTful Service Module:  demo/
          URI Template:      test
                Method:  POST
           Source Type:  PL/SQLand executing in sqldeveloper 3.2.20.09 when connecting directly to box B as scott:
SET serveroutput ON
DECLARE
  l_url      VARCHAR2(200)   :='http://MY_IP:8585//apex/wsdemo/demo/test';
  l_json     VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
  l_response VARCHAR2(30000);
BEGIN
  post( p_url => l_url, p_message =>l_json, p_response => l_response);
END;which resulted in :
status code: 500
reason phrase: Internal Server Error
Listener's log:
Request Path passes syntax validation
Mapping request to database pool: PoolMap [_poolName=apex, _regex=null, _workspaceIdentifier=WSDEMO, _failed=false, _lastUpdate=1364313600000, _template=/wsdemo/, _type=BASE_PATH]
Applied database connection info
Attempting to process with PL/SQL Gateway
Not processed as PL/SQL Gateway request
Attempting to process as a RESTful Service
demo/test matches: demo/test score: 0
Choosing: oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as current candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true]
Determining if request can be dispatched as a Tenanted RESTful Service
Request path has one path segment, continuing processing
Tenant Principal already established, cannot dispatch
Chose oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as the final candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true] for: POST demo/test
demo/test is a public resource
Using generator: oracle.dbtools.rt.plsql.AnonymousBlockGenerator
Performing JDBC request as: SCOTT
Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
INFO: Error occurred during execution of: [CALL, begin
insert into scott.json_demo values(/*in:title*/?,/*in:description*/?);
end;, [title, in, class oracle.dbtools.common.stmt.UnknownParameterType], [description, in, class oracle.dbtools.common.stmt.UnknownParameterType]]with values: [thetitle, thedescription]
Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
INFO: ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
   begin case declare exit for goto if loop mod null pragma
   raise return select update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
   begin case declare end exception exit for goto if loop mod
   null pragma raise return select update while with
   <an identifier> <a double-quoted delimited-id
java.sql.SQLException: ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
   begin case declare exit for goto if loop mod null pragma
   raise return select update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
   begin case declare end exception exit for goto if loop mod
   null pragma raise return select update while with
   <an identifier> <a double-quoted delimited-id
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
        at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:505)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:223)
        at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
        at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:205)
        at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1043)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
        at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3612)
        at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3713)
        at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4755)
        at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at oracle.ucp.jdbc.proxy.StatementProxyFactory.invoke(StatementProxyFactory.java:242)
        at oracle.ucp.jdbc.proxy.PreparedStatementProxyFactory.invoke(PreparedStatementProxyFactory.java:124)
        at oracle.ucp.jdbc.proxy.CallableStatementProxyFactory.invoke(CallableStatementProxyFactory.java:101)
        at $Proxy46.execute(Unknown Source)
        at oracle.dbtools.common.jdbc.JDBCCallImpl.execute(JDBCCallImpl.java:44)
        at oracle.dbtools.rt.plsql.AnonymousBlockGenerator.generate(AnonymousBlockGenerator.java:176)
        at oracle.dbtools.rt.resource.templates.v2.ResourceTemplatesDispatcher$HttpResourceGenerator.response(ResourceTemplatesDispatcher.java:309)
        at oracle.dbtools.rt.web.RequestDispatchers.dispatch(RequestDispatchers.java:88)
        at oracle.dbtools.rt.web.HttpEndpointBase.restfulServices(HttpEndpointBase.java:412)
        at oracle.dbtools.rt.web.HttpEndpointBase.service(HttpEndpointBase.java:162)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059)
        at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999)
        at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434)
        at oracle.dbtools.standalone.SecureServletAdapter.doService(SecureServletAdapter.java:65)
        at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:379)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:196)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:662)
Error during evaluation of resource template: ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
   begin case declare exit for goto if loop mod null pragma
   raise return select update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
   begin case declare end exception exit for goto if loop mod
   null pragma raise return select update while with
   <an identifier> <a double-quoted delimited-idPlease advise.
Regards
Zack

Zack.L wrote:
Hi Andy,
Sorry, forgot to post the Source that's use by both AL1.1.4 and AL2.0.1.
Source
begin
insert into scott.json_demo values(:title,:description);
end;
it's failing during the insert?
Yes, it failed during insert using AL2.0.1.
So the above statement produces the following error message:
The symbol "" was ignored.
ORA-06550: line 2, column 74:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-idThis suggests to me that an unprintable character (notice how there is nothing between the double quotes - "") has worked its way into your PL/SQL Handler. Note how the error is reported to be a column 74 on line 2, yet line 2 of the above block should only have 58 characters, so at a pure guess somehow there's extra whitespace on line 2, that is confusing the PL/SQL compiler, I suggest re-typing the PL/SQL handler manually and seeing if that cures the problem.

Similar Messages

  • Error while insert data using execute immediate in dynamic table in oracle

    Error while insert data using execute immediate in dynamic table created in oracle 11g .
    first the dynamic nested table (op_sample) was created using the executed immediate...
    object is
    CREATE OR REPLACE TYPE ASI.sub_mark AS OBJECT (
    mark1 number,
    mark2 number
    t_sub_mark is a class of type sub_mark
    CREATE OR REPLACE TYPE ASI.t_sub_mark is table of sub_mark;
    create table sam1(id number,name varchar2(30));
    nested table is created below:
    begin
    EXECUTE IMMEDIATE ' create table '||op_sample||'
    (id number,name varchar2(30),subject_obj t_sub_mark) nested table subject_obj store as nest_tab return as value';
    end;
    now data from sam1 table and object (subject_obj) are inserted into the dynamic table
    declare
    subject_obj t_sub_mark;
    begin
    subject_obj:= t_sub_mark();
    EXECUTE IMMEDIATE 'insert into op_sample (select id,name,subject_obj from sam1) ';
    end;
    and got the below error:
    ORA-00904: "SUBJECT_OBJ": invalid identifier
    ORA-06512: at line 7
    then when we tried to insert the data into the dynam_table with the subject_marks object as null,we received the following error..
    execute immediate 'insert into '||dynam_table ||'
    (SELECT

    887684 wrote:
    ORA-00904: "SUBJECT_OBJ": invalid identifier
    ORA-06512: at line 7The problem is that your variable subject_obj is not in scope inside the dynamic SQL you are building. The SQL engine does not know your PL/SQL variable, so it tries to find a column named SUBJECT_OBJ in your SAM1 table.
    If you need to use dynamic SQL for this, then you must bind the variable. Something like this:
    EXECUTE IMMEDIATE 'insert into op_sample (select id,name,:bind_subject_obj from sam1) ' USING subject_obj;Alternatively you might figure out to use static SQL rather than dynamic SQL (if possible for your project.) In static SQL the PL/SQL engine binds the variables for you automatically.

  • Custom Measure - Unable to Submit Data Using Input Schedule

    We have an application that requires storage of data on a job-to-date basis.  To accommodate this, the application was changed to a YTD application and 3 custom measures were added:
    JTD (base data)
    YTD_JOBS (offsets current period against last month of prior period)
    PERIODIC_JOBS (offsets current period against prior period)
    Everything is working and the measures resolve to the correct values.  The system also completes logic (advanced and dimension) properly.  Data may also be submitted through an Import process. 
    However, we are unable to submit data using an input schedule.  We consistently get a "no data to refresh" error message.  When the same schedule is used in the older, periodic version of the application, the submission works as expected.
    I suspect the problem is the naming of the custom measures is the root cause.  I have been unable to find documentation (BPC 5.1M) related to custom measures for 5.1.  Any help resolving this issue and/or tracking down custom measures documentation for v5.1 is much appreciated.
    Cheers,
    Jeff

    Joost,
    I believe what you are describing is the root of the issue.  The application is set to YTD as the data input type both in the web admin section and in the database table.  The problem is that JTD is the input member for this application -- we are loading job-to-date values instead of year-to-date.
    It seems that BPC does not understand JTD as a "base level" measure fort the input method.  I have not been able to find a table in the database that defines PERIODIC and YTD.  My hope was to add JTD to the settings. 
    Unless someone else has made something like this work, I suspect that I'll have to use YTD as the ID of the base member and restructure the custom measures.  We did not start this way since the user community thinks in terms of JTD data.

  • Access pre-insert data using ViewObjects

    Hi,
    I’m trying to access pre-insert data (before super.doCommit() execution) using viewobjects, but I only obtain committed data. Is it possible to obtain pre-insert data using viewobjects?
    Here the Java code:
    String amDef = "oracle.srdemo.model.AppModule";
    String config = "AppModuleLocal";
    ApplicationModule am =
    Configuration.createRootApplicationModule(amDef, config);
    ViewObject vo = am.findViewObject("DatetestView1");
    System.out.println("Query will return "+ vo.getEstimatedRowCount()+" rows...");
    vo.executeQuery();
    while (vo.hasNext()) {
    Row curPerson = vo.next();
    System.out.println(vo.getCurrentRowIndex()+". "+
    curPerson.getAttribute("Id")+" "+
    curPerson.getAttribute("Dataini"));
    Configuration.releaseRootApplicationModule(am, true);
    I'm using JDeveloper 11g, a Fusion Web Application and ADF Business Components
    Thanks in advance.

    Hi Timo,
    According to your instructions, I obtained current ApplicationModule and the issue was solved.
    Here the Java Code to get ApplicationModule from Iterator:
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding dciter = (DCIteratorBinding)bindings.get("DatetestView1Iterator");
    DCDataControl dc = dciter.getDataControl();
    ApplicationModule am = (ApplicationModule)dc.getDataProvider();
    AppModuleImpl am2 = (AppModuleImpl)am;
    ViewObject vo = (DatetestViewImpl)am2.findViewObject("DatetestView1");
    Thank you vey much,
    Olga

  • *Urgent*How to insert data from MS SQL to the table that create at the adobe form?

    Hi,
    I'm using Adobe life cycle designer 8 to do my interactive form. I would like to ask how to insert data from MS SQL to the table that i have created in my adobe interactive form?
    I really need the information ASAP as i need to hand in my project by next week... i really appreciate any one who reply this post.
    Thanks

    Tou need to do a couple of things
    1. On the Essbase server, set up an odbc system connection to your MySQL database
    2. In the load rule , go to the file menu and select open SQL data source and in the data source put in your SQL statement . A couple of hints. Where it says Select, don't put in the word select and where it say from don't put in from. The system adds them for you. The easiest way ti enter a SQL statement is to do it all in the select area So if your SQL would normanlly say select * from mytable just enter the code as * from mytable in the select area
    The click ol/retrieve and enter in your connection info. Itshould bring data back into the load rule. Save the load rule and use it

  • Problem inserting date into MS SQL Server

    I am trying insert date into MS SQL Server database. First I used Statement and when I insert the date only date used to be inserted properly and the time used to be always 12:00:00 AM. I tried PreparedStatement and when I insert I get an error message:
    SQL Error: [Microsoft][ODBC SQL Server Driver]Optional feature not implemented
    I have attached the code.
    GregorianCalendar cal = new GregorianCalendar();
    java.util.Date dtm = (java.util.Date)cal.getTime();
    SimpleDateFormat formatOb = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
    String date= (String)formatOb.format(dtm);
    dateCreated = new java.sql.Date(formatOb.parse(date).getTime());
    PreparedStatement psmt = con.prepareStatement("INSERT INTO Resume (ResumeName, Summary, Skills, OtherInformation, Interests, Memberships, Languages, Category, DateCreated, SupervisorName) VALUES(?,?,?,?,?,?,?,?,?,?)");
    psmt.setString(1, name);
    psmt.setString(2, summary);
    psmt.setString(3, skills);
    psmt.setString(4, info);
    psmt.setString(5, interest);
    psmt.setString(6, member);
    psmt.setString(7, language);
    psmt.setString(8, category);
    psmt.setDate(9, dateCreated);
    psmt.setString(10, loginName);
    psmt.executeUpdate();
    Any suggestions will be really helpful.

    Thanks,
    I changed the field in the database of DateCreated to timestamp, but when I insert the some binary data is inserted into the database. something like 0000000000000017D.
    I installed jtds-0.8.1 driver from source forge. but when try to connect to the database I get an error as:
    Connection refused: connect
    Error: Connection refused: connect
    I have attached the code for setting the driver and url also.
    private String driver = "net.sourceforge.jtds.jdbc.Driver";
    private String url = "jdbc:jtds:sqlserver://TEKKATTE:1433/placement;TDS=7.0";

  • Can we use Data Pump to export data, using a SQL query, doing a join

    Folks,
    I have a quick question.
    Using Oracle 10g R2 on Solaris 10.
    Can Data Pump be used to export data, using a SQL query which is doing a join between 3 tables ?
    Thanks,
    Ashish

    Hello,
    No , this is from expdp help=Y
    QUERY                 Predicate clause used to export a subset of a table.
    Regards

  • Write / store xml data in Xe and retrieve stored data using pl/sql

    Hi to all,
    i'm searching a tutorial on:
    A - how to write / store xml data in Xe and retrieve stored data using pl/sql
    I don't want to use other technologies, because i use htmldb and my best practice is with pl/sql.
    I was reading an ebook (quite old maybe) however it's about oracle 9 and it's talking about xmltype:
    1 - I don't understand if this is a user type (clob/varchar) or it's integrated in Oracle 9 however i will read it (it's chapter 3 titled Using Oracle xmldb).
    Please dont'reply here: i would be glad if someone can suggest me a good tutorial / pdf to achieve task A in Oracle XE.
    Thanx

    Thank you very much Carl,
    However my fault is that i've not tried to create the table via sql plus.
    Infact i was wrong thinking that oracle sql developer allows me to create an xmltype column via the create table tool.
    however with a ddl script like the following the table was created successfully.
    create table example1
    keyvalue varchar2(10) primary key,
    xmlcolumn xmltype
    Thank you very much for your link.
    Message was edited by:
    Marcello Nocito

  • Replace ' with ' in my data using pl/sql

    I want to replace all occurrence of special characters like &apos; with ' in my data using pl/sql.
    How can I achieve this?

    Thank you for your quick reply. My code is:
    DECLARE
    firstname varchar2(200) := 'cccc&a p o s;dddd'; ---> Please remove spaces between a p o s. Combine them as apos
    lastname varchar2(200) := 'eeee';
    BEGIN
    dbms_output.put_line('Before changing : firstname :' || firstname);
    dbms_output.put_line('After changing: firstname :' || replace(LastName, "&apos;" , "'") );
    END;
    When I run this in sqlplus, I see:
    SQL> @EscapeCharTesting.sql
    Enter value for apos:
    So I want to change all occurences of "&a p o s;" to CHR(39)

  • Unable to insert date and time when using date datatype

    Hi
    I am hitting a bit of a problem when using the date datatype. When trying to save a row to the table where the field it throws an error ora 01830 and complains about converting the date format picture ends...etc. Now when I do the insert, I use the to_date function with the format of "dd-mon-yyyy hh24:mi:ss". Of course, when I remove the time element, everything is perfect.
    Checking sysdate, I noticed that the time element wasn't be displayed, and I used alter session set nls_date_format to set the date and time I want to save to the table, which worked!
    Then based on advice in a previous thread to permanently fix the problem, I used alter system set nls_date_format ="dd-mon-yyyy hh24:mi:ss" scope=spfile; This showed that it was altered, and I can see the setting in the em. In sqlplus, I shutdown the database, and restarted with startup mount; alter database open; and then selecting sysdate, it still shows the date as dd-mon-yy, and still no time! Checking the em, and looking up the nls_date_format the setting is still shown as "dd-mon-yyyy hh24:mi:ss".
    So, my question is this - what am I doing wrong? Why can't save date and time using date in Oracle 11g?????
    Thanks

    user633278 wrote:
    Hi
    I am hitting a bit of a problem when using the date datatype. When trying to save a row to the table where the field it throws an error ora 01830 and complains about converting the date format picture ends...etc. Now when I do the insert, I use the to_date function with the format of "dd-mon-yyyy hh24:mi:ss". Of course, when I remove the time element, everything is perfect.
    Checking sysdate, I noticed that the time element wasn't be displayed, and I used alter session set nls_date_format to set the date and time I want to save to the table, which worked!
    Then based on advice in a previous thread to permanently fix the problem, I used alter system set nls_date_format ="dd-mon-yyyy hh24:mi:ss" scope=spfile; This showed that it was altered, and I can see the setting in the em. In sqlplus, I shutdown the database, and restarted with startup mount; alter database open; and then selecting sysdate, it still shows the date as dd-mon-yy, and still no time! Checking the em, and looking up the nls_date_format the setting is still shown as "dd-mon-yyyy hh24:mi:ss".
    So, my question is this - what am I doing wrong? Why can't save date and time using date in Oracle 11g?????
    ThanksYou most certainly can save the time. A DATE column, by definition stores date and time. What you describe is a presentation problem, and setting nls_date_format at the system as an init parm is the weakest of all settings as it is overridden by several other locations.
    without seeing the exact sql that produced the error (not just your description of what you think you were doing) it is impossible to say for sure.
    However, I'd suggest you read http://edstevensdba.wordpress.com/2011/04/07/nls_date_format/

  • Inserting data using stored procedure

    Using SQL Server Express 2014, I'm creating a stored procedure to accept parameters and convert data from a staging table to a production table. The parameters specify the table names and a field to lookup in another table. This is the first stored procedure
    I've tried to create by myself though and I'm basing it on a guide. Here's what I've got so far:
    CREATE PROCEDURE [dbo].[stp_UpdateAggregatePerf]
    @prod_tbl NVARCHAR(250), @stg_tbl NVARCHAR(250), @customer NVARCHAR(20)
    AS
    BEGIN
    DECLARE @p NVARCHAR(250), @s NVARCHAR(250), @c NVARCHAR(20), @cid int, @sql NVARCHAR(MAX)
    SET @p = @prod_tbl
    SET @s = @stg_tbl
    SET @c = @customer
    SET @cid = 'SELECT [dbo].[Customers].[CustomerID]
    FROM dbo.customers
    WHERE [dbo].[Customers].[CustomerName] LIKE ' + @c
    SET @sql = 'INSERT INTO ' + @prod_tbl + '
    SELECT CONVERT (datetime,TimeIndex,103) AS TimeIndex,
    CONVERT(decimal(10,3),user_reads,3) AS Reads,
    CONVERT(decimal(10,3), user_writes,3) AS Writes,
    CONVERT(decimal,10,3),total_transfers,3) AS Total,
    CONVERT(decimal(10,3),cp_reads,3) AS CPReads,
    SUBSTRING(AggregateName,1,25),
    SUBSTRING(ControllerName,1,25),
    SUBSTRING(@cid,1,25)
    FROM' + @stg_tbl
    EXEC sp_executesql @sql
    SET @sql = 'DROP TABLE' + @stg_tbl
    EXEC sp_executesql @sql
    END
    So it should accept the parameters, take the customer name parameter and look up the customer ID field from another table to use in the last column, then generate and run the INSERT INTO statement to convert and transfer data, then drop the staging table.
    I'm not sure how to go about using the INSERT statement with variables though, or even if I'm concatenating the string together correctly.
    Here's my CREATE statements for the tables:
    prod table:
    CREATE TABLE [dbo].[AggregatePerf](
    [AggrPerfID] [int] IDENTITY(1,1) NOT NULL,
    [AggregateName] [varchar](25) NOT NULL,
    [TimeIndex] [datetime] NOT NULL,
    [Reads] [decimal](10, 3) NOT NULL,
    [Writes] [decimal](10, 3) NOT NULL,
    [Total] [decimal](10, 3) NOT NULL,
    [CPReads] [decimal](10, 3) NOT NULL,
    [ControllerName] [varchar](25) NOT NULL,
    [CustomerID] [varchar](10) NOT NULL,
    CONSTRAINT [PK_AggregatePerf] PRIMARY KEY CLUSTERED
    [AggrPerfID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    Staging:
    CREATE TABLE [dbo].[$tablename] (
    [TimeIndex] VARCHAR(100)
    , [user_reads] VARCHAR(100)
    , [user_writes] VARCHAR(100)
    , [cp_reads] VARCHAR(100)
    , [total_transfers] VARCHAR(100)
    , [AggregateName] VARCHAR(100)
    , [ControllerName] VARCHAR(100)
    The staging table is generated from PowerShell to import CSVs but I'm past that stage of the project now. I hope you can help  me get an understanding here as once I wrap my around one table I can apply the same technique to others.
    Thanks in advance
    Adam

    Why do you provide a tables as a parameters? I think you may avoid using dynamic sql and simple use a static one.
    Where do you use @cid
    variable?
    Static SQL may look like
    SELECT @cid=
    [dbo].[Customers].[CustomerID]
    FROM dbo.customers
    WHERE [dbo].[Customers].[CustomerName] LIKE '%'+@c+'%'
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Insert data using peoplesoft webservice gives component API error

    Hi,
    I am using jdeveloper 11g to consume a peoplesoft webservice using the wsdl file and JAX-Ws approach to build the proxy.
    I have been successfull in getting to work the "get", "find" methods for the webservice but while trying to access the create/Update(inserting data) method, it gives me the following exception.
    In CREATE method
    Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Component Interface API.
         at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:197)
         at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:130)
         at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:125)
         at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:95)
         at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
         at $Proxy32.createCompIntfcKCMWEBCASECI(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at weblogic.wsee.jaxws.spi.ClientInstance$ClientInstanceInvocationHandler.invoke(ClientInstance.java:363)
         at $Proxy33.createCompIntfcKCMWEBCASECI(Unknown Source)
         at project1.proxy.KCM_WEB_CASE_CISoapClient.createKCMMethod(KCM_WEB_CASE_CISoapClient.java:318)
         at project1.proxy.KCM_WEB_CASE_CISoapClient.main(KCM_WEB_CASE_CISoapClient.java:116)
    Process exited with exit code 1.
    From the exception it is not clear what is missing or where am i going wrong. I have provided all the mandatory values required by the method.
    The create method generated needs almost 40 parameters, hence i am intializing all of them and sending it.
    Few parameters are INOUT or out mode, depending on that i even created the required holder etc.
    I dont have any access to peoplesoft logs, is there a way to debug this further.
    Basically i am stuck here as i am not able to decode this exception.
    Can anyone tell me where is it failing, is it a some formation error or is it creating a query at db and getting a sql error??
    as mentioned earlier, its very difficult to get access to db resources hence its becmong very difficult to debug the error.
    Any help will be appreciated.
    Thank you in advance
    Ashvini
    Edited by: [email protected] on Jun 7, 2010 7:49 AM
    Edited by: [email protected] on Jun 8, 2010 6:37 AM

    Hi, I have exact the same problem. Have you got any answer for this problem yet? Please forward it to me if you have one. Many thanks.

  • Insert Date Using Text Field

    Hi,
    i have date item ,Can i insert date from text field in dd/mm/yy format.
    My Column for date is DATE type in table.
    How can i ido this with Text field .
    Thanks

    I think you want to have text field for user to input the date? (instead of date picker item type)
    If you are using custom PL/SQL code, it is fine, because you just use to_date(:Px_DATE_ITEM, 'dd/mm/yyyy'); or whatever format you are expecting, in your insert statement.
    If it is a DML process type, I don't think it's possible - apex probably converts the text from the data picker into a date datatype at run time, but not sure it'd do it when its just a text box.
    Ta,
    Trent
    Edited by: trent on Jan 28, 2011 10:57 PM
    I take that back. So long as you have specified the application date format in the globalization attributes, and the format in the text box is the same/valid (otherwise it must be in the format as specified in NLS_DATE_FORMAT), it will insert no trouble in a DML process. http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/bldr.htm#CHDBHCBB

  • Unable to insert dates and blobs with java.sql.PreparedStatement

    I got a problem when i try to insert into a table using Prepared
    statement.
    The table definition is
    TABLE USER_ACCOUNTS
    USER_ACCOUNT NUMBER(12),
    START_DATE DATE,
    END_DATE DATE,
    NB_UNSUCC_LOG_AT NUMBER(2),
    USER_ID VARCHAR2(30),
    CREATION_DATE DATE;
    In my java classes if i do the following code everithing's fine:
    connection = pool.getConnection();
    connection.executeUpdate("
    INSERT INTO USER_ACCOUNTS(
    USER_ACCOUNT,
    START_DATE,
    END_DATE,
    NB_UNSUCC_LOG_AT,
    USER_ID,
    CREATION_DATE)
    VALUES(
    123,
    TO_DATE('2001-11-20','YYYY-MM-DD'),
    NULL,
    0,
    'TOTO',
    TO_DATE('2001-11-20','YYYY-MM-DD')
    but when i do the following, it gives me errors and no rows are
    created! what am i doing wrong?
    connection = pool.getConnection();
    pstmt = connection.prepareStatement(
    "INSERT INTO USER_ACCOUNTS(
    USER_ACCOUNT,
    START_DATE,
    END_DATE,
    NB_UNSUCC_LOG_AT,
    USER_ID,
    CREATION_DATE)
    VALUES(?,?,?,?,?,?)");
    int userAccount = 123;
    java.sql.Date creationDate = new Date(123445566);
    java.sql.Date startDate = new Date(123445566);
    java.sql.Date endDate = null;
    int nbUnsuccessfullLogonAttempt = 0;
    String userid ="TOTO";
    pstmt.setInt(1, userAccount);
    pstmt.setDate(2, startDate);
    pstmt.setDate(3, endDate);
    pstmt.setInt(4, nbUnsuccessfullLogonAttempt);
    pstmt.setString(5, userid);
    pstmt.setDate(6, startDate);
    pstmt.executeUpdate();
    ____________ at this point i receive an SQL Exception that said
    invalid delimiter in string
    i also tried with VALUES
    (?,TO_DATE('?', 'YYYY-MM-DD'),?,?,?,TO_DATE('?', 'YYYY-MM-DD'))
    and the result was invalid month in date
    Thanks for your help!
    Julien De Santis

    > org.hibernate.PropertyValueException: not-null property references a null or transient value: BookOpr.Author.BkBk is null while it should not be, according to the mapping:
    <class name="BookOpr.Author" table="author">
        <many-to-one name="Bk" column="bid" class="BookOpr.Book" not-null="true"/>There are 2 solutions:
    1) Don't null the BookOpr.Author.Bk.
    2) Remove not-null="true" or set it to "false".

  • Unable to fetch data using control-blocks

    Hi,
    I have created two non base table text items(from_date, to_date) and if values are not entered from front end i.e. null then hadrcoded in pre_query trigger to default values as from_date (system date-present month-last year) and to_date(system date-present month-present year).when i have pressed the fetch button without giving values to from_date and to_date,it is retrieving data in default period,which i ahave hardcoded in PRE_QUERY trigger.But even i enter values dynamically from front end and when ever i press fetch button ,it is retrieving data in default period instead giving data in specified duration what i have entered dynamically from front end. i.e. it is not accepting values what i have entered.
    any one please help me.
    oracle forms 10g version:10.1.2.0.2
    Thanks and Regards
    Ram

    hi,
    Thanks for ur feedback.
    here query is executed. My problem is,unable to fetch data in specified period,what i have entered dynamically.Even i entered dynamically,it is fetching data in default period(Which i have hardcoded in PRE_QUERY).
    below code is ,what i have hardcoded in PRE_QUERY
    :GLOBAL.DFROMDT := NULL;
    :GLOBAL.DTODT := NULL;
    IF :HEADER_BLOCK.NBTFROMDT is NULL THEN
    SELECT TO_DATE('10'||'/'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MM')||'/'||
    TO_CHAR(ADD_MONTHS(SYSDATE,-12),'YYYY'),'DD/MM/YYYY')
    INTO :HEADER_BLOCK.NBTFROMDT FROM SYS.DUAL ;
    END IF;
    IF :HEADER_BLOCK.NBTTODT IS NULL THEN           
         SELECT SYSDATE INTO :HEADER_BLOCK.NBTTODT
         FROM SYS.DUAL;
    END IF;
    IF :HEADER_BLOCK.NBTFROMDT IS NOT NULL
    OR :HEADER_BLOCK.NBTTODT IS NOT NULL THEN
    :GLOBAL.DFROMDT := :HEADER_BLOCK.NBTFROMDT;
    :GLOBAL.DTODT := :HEADER_BLOCK.NBTTODT;
    END IF;
    IF :DETAIL_BLOCK.nbtFjdDrCrInd IS NOT NULL THEN
         svWhere_String := 'WHERE FJH_VCHR_DT BETWEEN '''||nvl(:GLOBAL.DFROMDT,TO_DATE(:GLOBAL.DFROMDT,'DD/MM/YYYY'))||''' AND '||
    ''''||NVL(:GLOBAL.DTODT,TO_DATE(SYSDATE,'DD/MM/YYYY'))||''')';
         Set_Block_Property('DETAIL_BLOCK',DEFAULT_WHERE,svWhere_String);
    ELSE
         Set_Block_Property('DETAIL_BLOCK',DEFAULT_WHERE,' ');
    END IF;

Maybe you are looking for