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

Similar Messages

  • Insert record using stored procedure

    Dear all,
    I want to insert record using stored procedure in form6i,
    any help or suggestion will be appreciated.
    regards
    Kashif Ali

    Kashif,
    Could you please explain what you are trying to accomplish? Inserting records into a table from Forms is as simple as executing an INSERT statement in a Forms trigger or as complicated as overriding the Forms default INSERT functionality by defining your own On-Insert trigger. Your requirements will dictate where and how you do your INSERT.
    Craig...

  • Export data using stored procedure to excel

    How to export and save data from SQL Server to MS Excel using stored procedure.
    Thanks in advance
    Abhinav

    You can use multiple options
    1. distributed query like OPENROWSET/OPENDATASOURCE
    http://www.excel-sql-server.com/excel-import-to-sql-server-using-distributed-queries.htm
    2. Using linked server /OPENQUERY
    http://sqlwithmanoj.com/2010/11/12/query-excel-file-source-through-linked-server/
    also see
    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • INSERT'ing using Stored Procedure

    I want to make my VB.NET application performing INSERT's by calling a Stored Procedure. How do I supply the column values (without using numerous IN parameters) ?
    E.g.
    create procedure my_ins(my_row my_tab%rowtype)
    is
    How do I call this procedure from VB.NET ?
    Any help appreciated!
    Runar Emgård
    [email protected]

    It contains multiple datatypes, according to the columns of the underlying table "my_tab".

  • Best approach for performing DMLs using stored procedures

    Hi,
    I have a really general question and would like to hear your say about this.
    I want my application to manipulate or read data using stored procedures (or packages in that manner) and not directly using queries against the DB.
    Let's say I have a table with many columns:
    create table test (pkid number(10),col1 varchar2(30), col2 number(10), col3 date,...);For such a DML procedure, is it best to do something like
    procedure do_update(i_pkid IN number,i_col1 IN varchar2, i_col2 IN number, i_col3 IN date,...) as
    begin
       update test
       set col1=i_col1,
            col2=i_col2,
            col3=i_col3...
       where pkid=i_pkid;
       commit;
    end;Or do a selective update, meaning update only a certain column every time, given only 1 column actually changes? (and how to do that - separate procedures for each column? [columns can be nulls])
    Also, is it better to work with test.col1%type instead of specifying the data type in the procedure?
    And one last question - If I have a table with 100 columns and I don't want to create a procedure with 100 parameters - the best approach would be to use a record?
    I just need to be set on the way I start implementing things in order to do it well from the start.
    Many thanks.
    Edited by: Pyrocks on Nov 17, 2010 1:58 PM

    Pyrocks wrote:
    One last clarification (although it may be more related to c/c++ developers - maybe one of you will know):
    We are working with C++ and VB against a SQLServer and my part is to translate all the existing procedures to Oracle in order to migrate the application to work with Oracle DB.
    The existing procedures use an IN parameter for each column in the table and I would really like to use rowtype like you mentioned.
    Since I'm not a c/c++/vb developer - is there an easy way of working with such types, or even User-Defined Types, from c/c++/vb (as in passing a rowtype record from c++ to a SP ?)
    I'm not looking for the actual way - just want to know how hard it would be and how much code needs to be changed in order to be able to convince the developers that this is the RIGHT way to work.
    PS. none of our developers have experience with ORACLE so they wouldn't know the answer...Not actually an Oracle server-side (SQL language or PL/SQL language) question - but a client one. And it has been a long time since I wrote a fat client using C/C++ or Delphi.
    The OCI (<i>Oracle Call Interface</i>) supports advance (user defined) SQL data types. Has since Oracle 8i. So in that respect, yes the client can support custom SQL data types.
    How well it does depends entirely on that client language's features wrt OCI integration. For example, Delphi 4 was release around Oracle 8i and supported custom SQL types. I would expect that most languages today (like Java and C#) will provide support for it.
    As for usiong +%ROWTYPE+ - this is a PL/SQL clause as far as I know. Unsure whether it is supported by the OCI. What could support it is a pre-compiler like Pro*C. These enable you to mix pseudo SQL source code with client language source code. The pre-compilation step then replaces the pseudo SQL code with native client language calls to the OCI. The code is then compiled by that client language's compiler. Pre-compilers can pull all kinds of interesting "tricks" with their pseudo SQL code support.
    The best would be to consult the applicable client language's manuals that describe the interface it supports (via OCI) to Oracle.

  • How to Insert date in 'DD/MM/YYYY' format in oracle using stored procedure?

    Hi
    How to Insert date in 'DD/MM/YYYY' format in oracle using stored procedure?
    This is my Input data.
    11/25/2007.
    By using below query, it is inserted into database.
    sql>Insert into tblname values(to_date('11/25/2007','MM/DD/YYYY'));
    But using stored procedure, the same query is not running.
    It shows error like
    ORA-01843: not a valid month ORA-06512: at line 1
    Procedure:
    create or replace procedure Date_Test(datejoin in DATE) is
    begin
    insert into datetest values(to_date(datejoin,'MM/DD/YYYY'));
    end Date_Test;
    I had used 'nls_date_language = american' also.
    Prcodeure is created but not worked in jsp. The same error is thrown.
    Pls provide a solution

    This might help you....
    SQL> Create Table DateTest(col1 Date);
    Table created.
    Elapsed: 00:00:00.00
    SQL> create or replace procedure Date_Test(datejoin in DATE) is
    2 begin
    3 insert into datetest values(to_date(datejoin,'MM/DD/YYYY'));
    4 end ;
    5 /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec Date_Test('11/25/2007');
    BEGIN Date_Test('11/25/2007'); END;
    ERROR at line 1:
    ORA-01843: not a valid month
    ORA-06512: at line 1
    Elapsed: 00:00:00.00
    SQL> exec Date_Test(To_Date('11/25/2007','mm/dd/yyyy'));
    BEGIN Date_Test(To_Date('11/25/2007','mm/dd/yyyy')); END;
    ERROR at line 1:
    ORA-01843: not a valid month
    ORA-06512: at "CTBATCH.DATE_TEST", line 3
    ORA-06512: at line 1
    Elapsed: 00:00:00.00
    SQL> create or replace procedure Date_Test(datejoin in DATE) is
    2 begin
    3 insert into datetest values(datejoin);
    4 end ;
    5 /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec Date_Test(To_Date('11/25/2007','mm/dd/yyyy'));
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> Select * from DateTest;
    COL1
    25-NOV-07
    Elapsed: 00:00:00.00
    SQL> create or replace procedure Date_Test(datejoin in VarChar2) is
    2 begin
    3 insert into datetest values(to_date(datejoin,'mm/dd/yyyy'));
    4 end ;
    5 /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec Date_Test('11/25/2007');
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> select * from DateTest;
    COL1
    25-NOV-07
    25-NOV-07
    Elapsed: 00:00:00.00
    SQL>

  • Can we have an example of using update, insert, and delete stored procedure

    I would like to see an example of using retrieve (return resultset), update, insert, and delete stored procedures in JSF. I need to see syntax how JSF can call those stored procedures. This option is absolutely important when building web-application. Currently, I haven't found resource to do for this purpose yet. The database can be any such Oracle, DB2, pointbase, etc that support stored procedures.
    Anyone knows?
    Thanks,
    Tue Vu

    Hi ttv,
    I asked around a bit and here's some more info:
    To bind a ResultSet to a read only Data Table component just set the "value" property of the Data Table component to point at it, and JSF will synthesize a DataModel around it.
    * Note that because we can't call the stored procedure at design time, Creator can't do the fancy table layout stuff it does for rowsets. You'll need to hand craft the columns just like the Google Client example.
    * As I mentioned previously, you will have to manually code the stored procedure access in your java code - see the code clip I mentioned in previous reply (and if this is via a stored procedure, then any textbook about JDBC will undoubtedly have examples). Simplest way might be a getter method on the page bean that contains the call to the stored procedure and returns the resulting ResultSet object.
    * Don't forget to close the result set - we typically do this at the end of the request (i.e. add a close in the afterRenderResponse() method.
    * Don't throw exceptions - or if you have to, make sure you close the result set in a finally clause (thrown exceptions bypass the afterRenderResponse method in the lifecycle).
    * You give up on the caching provided by our RowSetDataModel (which can't be connected to a ResultSet even manually), so I would recommend that you only use datatables to display the data and then go to a single row page to do edits/deletes (similar to the TwoPage example in AppModel and the Update, Insert Delete tutorial).
    And yes please do submit an example - we will gladly post it!!! :) The best way to submit this kind of thing would be through:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    on the right side, Related Links, under Creator Heros, click Submit Content and there you can send it in!
    Hope this helps!
    Val

  • Bulk insert using stored procedure or trigger

    Hi ,
    I have to insert around 40,000 rows in a table querying other database using database link.
    Please advice whether I do using stored procedure or trigger.
    Thanks.

    Here is a basic benchmark that illustrates the difference between maximising SQL, or doing it in PL/SQL instead.
    Care needs to be taken with such a benchmark in order for physical I/O not to negatively impact a test, and then have no impact in the second test as that data read from disk now sits in the cache.
    So I ran it a couple of times in order to "warm up" the cache. I also put the maximise-SQL test first in order to show that it is still faster, despite any physical I/O it may do (which will likely be faster logical I/O with the second test).
    Run on Oracle XE 10.2.0.1.
    SQL> drop table my_objects_copy purge;
    Table dropped.
    SQL> create table my_objects_copy as select * from all_objects;
    Table created.
    SQL>
    SQL> set timing on
    SQL> begin
    2 delete from my_objects_copy;
    3
    4 insert into my_objects_copy
    5 select * from all_objects;
    6
    7 commit;
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:01.11
    SQL> set timing off
    SQL>
    SQL> drop table my_objects_copy purge;
    Table dropped.
    SQL> create table my_objects_copy as select * from all_objects;
    Table created.
    SQL>
    SQL> set timing on
    SQL> declare
    2 cursor c is select * from all_objects;
    3 objRow ALL_OBJECTS%ROWTYPE;
    4 begin
    5 delete from my_objects_copy;
    6
    7 open c;
    8 loop
    9 fetch c into objRow;
    10 exit when c%NOTFOUND;
    11
    12 insert into my_objects_copy
    13 values objRow;
    14
    15 end loop;
    16 commit;
    17 end;
    18 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.21
    SQL>
    The cursor-fetch-loop is almost 3 times slower. The more rows there are to process, the slower the cursor-fetch-loop will become, as it will create more and more context switching and copying data between the SQL and PL engines and back.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Using stored procedures for insert, update and delete

    Hello all;
    We have a question from our customer (who is the DBA), who has not in the past used TopLink, about whether it makes sense to tie TopLink into existing stored procedures to save and retrieve informations.
    Is it possible?
    Is there any circumstance under which it is a good idea?
    Thanks

    In TopLink any operation for which TopLink generates SQL, can be replaced by custom SQL, or a stored procedure call.
    Custom SQL or stored procedures can be used for each of the descriptor's CRUD operations, but also for mapping queries and named queries. The Mapping Workbench only supports defining custom SQL for the descriptor CRUD operations and named queries, so many of the stored procedures call from the descriptor and mappings will need to be done through amendment methods.
    Whether it makes sense or not depends on the application and the company and their requirements. It will add significant overhead to the development process to have to define and maintain all of the stored procedures, and the stored procedure calls in the descriptors. You may wish develop your application using TopLink generated SQL, and once you have the model and queries stabilized then switch to using stored procedures.
    Whether it is a good idea depends on the application and the company and their requirements. Stored procedures may give the DBA more freedom to change the data-model once in production, and may allow for adding database-level security checks. In general using stored procedures will not improve performance if the procedures contain the same SQL that would have be executed anyway, but they may allow for the DBA to tune the SQL better.

  • Sub report using Stored Procedure returns incorrect data

    Post Author: rikleo2001
    CA Forum: Data Connectivity and SQL
    Guys,
    I am using CR 9 in ASP.net application.
    One simple report and one Sub report, sub report is basically linked with Stored procedure accepting one parameter and returns a select query.
    Main report is linked with that sub report using that parameter field.
    Sub report is on demand sub report.
    Now when I execute that main report and click on on demand sub report I am getting Wrong order information.
    Here is out put on main report
    Order 1                                          on demandDetail
    Order 2                                          on demandDetail
    Order 3                                          on demandDetail  
         NOW If I click on Order 3 (On demanddetail link, it displays rondom order details, some time correct on too), I am really stuck and don't know where I am going wrong.
    Please help me to solve this issues.
    Many Thanks

    Post Author: rikleo2001
    CA Forum: Data Connectivity and SQL
    Hi Yangster,
    Thank you so much for your reply.
    On DEMAND Sub report is located in main report, IN DETAIL SECTION
    I am passing Order ID from main report linked to  {?morderid} in subreport under command object, and if I run it in design mode, it works perfectly alright, so problem is isolated to ASP.NET and Crystal report post back method on Crystal report.
    The example I give to you this is a simple example to identify issues in my real application and report.
    My main report contains summary of data base on unique identifier. that summary have 4 differant types of details which has to be on the same report (as Crystal report doesn't provide Nested subreport), so I decided to use 4 subreports on main report and all subreport using Stored procedure command object.(Sub report has it own complex processing requirement to fulfill).
    Please help me with any further ideas? for the sample which I presented to you this is only using one SP on main report with a simple processing.
    Many Thanks

  • How to work on Data Analysis using Stored procedures

    How to work on Data Analysis using Stored procedures any suggestions 

    Carefully?  Precisely?  Tomorrow?  Your question has no context so it means little to an outside reader. Perhaps you should start with some basic research into the data mining features of sql server:
    data mining homepage

  • Using Stored Procedure Universe in Reports

    Hi Friends,
    I got some issues using SP's in Universe and WebI Report.
    Case #1:
    Can we execute dynamic SQL using stored procedure universe..?
    I use SQL server as the DB for my reports.I created a SP which will execute on getting a input value from the user.This input value will frame the SQL dynamically in the SP.for executing the dynamic SQL i use sp_executesql inside the SP.The SP wexecutes successfuly in the DB but when i try executing it in the Universe i get a error message as follows: "Exception : DBD,[Microsoft][SQL SErver Native Client 10.0][SQL Server]Incorrect syntax  nesr 'FROM'.State:42000"
    The script i used for creating SP for your reference:
    CREATE PROCEDURE P_S_GetCodeValueList
              @s_table nvarchar(75)
    as
    begin
              declare @s_sqlCommand nvarchar(1000)
              declare @s_tablename nvarchar(75)
              declare @s_code nvarchar(75)
              set @s_tablename=@s_table
              set @s_code = '*'
              set @s_sqlCommand= 'SELECT ' + @s_code + ' FROM ' + @s_tablename
              exec sp_executesql @s_sqlCommand
    end
    Case #2:
    AIl also tried creating reports using the SP Universe which needs to get the parameter when the user refesh the report.
    But every time the report is refreshed the report fetches the data which was produced when the SP is executed in the Universe for the first time.
    I need to get the prompt in the report , to which the user could give a value and the SP gets executed for that value.
    Is there any option in BO to do this?
    It will be very helpful if you could give me some work arounds on this.
    Regards,
    Sugumar

    Hi Sugumar,
    I can answer you for your 2nd question:
    When you create the Stored procedure in the Universe and test it on retreiving data by inserting variable input you can check if the user could insert new value for the SP parameters.
    Hope this helps!
    Regards
    Giuseppe

  • Help: Using stored procedure to add new record in DB

    I am using stored procedures for a form. In DB, I have select and update procedures work without problems. However, for the insert procedure, it does not seem work right. Here is how things work for the insert procedure:
    1. On the form, I have an add record button, when this button is pressed, it calls the trigger "KEY_CREREC" with "create_record."
    2. A blank record is then shown on form. I then put in some test date. Apparently, this will cause "SYSTEM.STATUS" set to "CHANGED." when calling for commit, it only calls the DB update procedure.
    My question is how to make it call the insert procedure.
    Any suggestions are greatly appreciated.

    I just added to lines in key_commit to check the system.form_status:
    set_alert_property('AL_STOP', alert_message_text,'System Status: '||:system.form_status);
    al_button := show_alert('AL_STOP');
    After do_key('create_record') and some changes in fields, the :system.form_status shows "CHANGED.'
    Just wondering what will make the auto generated insert_procedure for the block to trigger. So far, no problems to do query and update with the DB stored procedure, but the insert does not seem working.
    Any help is greatly appreciated.
    P.S. The new post might be more clear:
    http://forums.oracle.com/forums/thread.jspa?threadID=675578&tstart=0
    Message was edited by:
    WJH

  • 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.

  • SSIS 2012 ETL is failing only at one server (No BIDS) but running successfully from BIDS on different sever . In this ETL, I have used Stored Procedure in OLEDB Source.

    Hi Guys,
    SSIS 2012 ETL is failing only at one server (No BIDS) but running successfully from BIDS on different sever . In this ETL, I have used Stored Procedure in OLEDB Source.
    Note: I have couple of ETLs developed in 2005 using same logic and upgraded to 2012, working perfectly.
    I am getting Error Message:
    SSIS
    Error Code
    DTS_E_OLEDBERROR. 
    An OLE DB
    error has occurred.
    Error code: 0x80004005.
    An
    OLE DB
    record is available. 
    Source: "Microsoft OLE DB Provider for SQL Server" 
    Hresult: 0x80004005 
    Description: "Error converting data type varchar to datetime.".
    Unable
    to retrieve
    column information
    from the data
    source. Make
    sure your target
    table in
    the database is
    available.
    "OLE DB Source"
    failed validation
    and returned
    validation status
    "VS_ISBROKEN".
    I tried below word around and found It is working perfectly.
    I loaded data into a table (dbo.TEMP) using Stored procedure and then I used this dbo.TEMP table in OLEDB source and then found no issue.
    MY SP Details: (This SP I am calling in OLEDB source of ETL) and when I run it from one server IT is working fine and when I run from ETL dedicated Server getting error:   Guys Help me out.
    USE
    [TEST_DB]
    GO
    SET
    ANSI_NULLS ON
    GO
    SET
    QUOTED_IDENTIFIER ON
    GO
    ALTER
    PROCEDURE  [DBO].[SP_TEST]
    --EXEC [DBO].[SP_TEST] '2014-09-30','2014-10-01'
    @FROMDATETIME
    DATETIME,
    @TODATETIME
    DATETIME
    AS
    SET
    NOCOUNT ON
    BEGIN
    DECLARE
    @FROMDATEKEY INT,
    @TODATEKEY INT,
    SET
    @FROMDATEKEY=
    CONVERT(VARCHAR(10),@FROMDATETIME,112)
    SET
    @TODATEKEY=
    CONVERT(VARCHAR(10),@TODATETIME,112)
    IF 1 = 1
    BEGIN
    SELECT
    CAST(NULL
    AS DATETIME) 
    AS TXN_DATE
    , CAST(NULL
    AS DATETIME
    ) AS PROCESS_DATE     
    , CAST(NULL
    AS money)
    AS  S1_AMT
    , CAST(NULL
    AS money)
    AS  S2_AMOUNT
    , CAST(NULL
    AS money)
    AS  S2_INVALID_AMOUNT
    , CAST(NULL
    AS money)
    AS  INVALID_MOVED_IN_VALID_S2_AMOUNT
    , CAST(NULL
    AS VARCHAR(20))
    AS SYSTEM_ID
    , CAST(NULL
    AS money)
    AS  S3_AMT
    END
    SELECT
    TXN_DATE
    ,PROCESS_DATE
    ,S1_AMT
    ,S2_AMOUNT
    ,S2_INVALID_AMOUNT
    ,INVALID_MOVED_IN_VALID_S2_AMOUNT
    ,SYSTEM_ID
    S3_AMT
    FROM
    DBO.TABLE_1
    WHERE TNX_DATE_KEY
    BETWEEN @FROMDATEKEY
    and @TODATEKEY
    UNION
    ALL
    SELECT
    TXN_DATE
    ,PROCESS_DATE
    ,S1_AMT
    ,S2_AMOUNT
    ,S2_INVALID_AMOUNT
    ,INVALID_MOVED_IN_VALID_S2_AMOUNT
    ,SYSTEM_ID
    S3_AMT
    FROM
    DBO.TABLE_2
    WHERE TNX_DATE_KEY
    BETWEEN @FROMDATEKEY
    and @TODATEKEY
    UNION
    ALL
    SELECT
    TXN_DATE
    ,PROCESS_DATE
    ,S1_AMT
    ,S2_AMOUNT
    ,S2_INVALID_AMOUNT
    ,INVALID_MOVED_IN_VALID_S2_AMOUNT
    ,SYSTEM_ID
    S3_AMT
    FROM
    DBO.TABLE_3
    WHERE TNX_DATE_KEY
    BETWEEN @FROMDATEKEY
    and @TODATEKEY
    END
    Data Source Mode: SQL Command for Variable
    "EXEC [DBO].[SP_TEST]  '"+ (DT_WSTR, 24) @[User::V_EXTRACT_FROM_DT]  +"','"+ (DT_WSTR, 24) @[User::V_EXTRACT_TO_DT]  +"'"
    Where variable @[User::V_EXTRACT_FROM_DT] and @[User::V_EXTRACT_TO_DT] is defined as DATETIME 
    Thanks Shiven:) If Answer is Helpful, Please Vote

    Hi,
    Yes you are right. At one sever where I was getting error, DateTime was in USA format and Where It was running successfully was in AUS format.
    I changed from USA to AUS and I did another changes:
    Data Source Mode: SQL
    Command
    EXEC  [DBO].[SP_TEST] 
    @FROMDATETIME = ?,
    @TODATETIME = ?
    and It is working fine.
    Thanks Shiven:) If Answer is Helpful, Please Vote

Maybe you are looking for