BareCode reader and insert String into actual selected JTextField

Hi everyone,
I can't invent anything appropriate about my concept. I would like to write a program for BareCode reading. I have working code witch gets a text string from reader which is connected over RS232. But I have to send this String to actual selected JTextField in other java program. I think to use clipboard to overcome this problem but I'm not sure if it's a good solution. Copy this String to clipboard and auto Paste... Any ideas ?
Please help me!
Many thanks for any advices :)

Hmm... I missed that bit about having to poke it into
another Java program. In that case I would
look into modifying the other Java program instead of
trying to write a separate program to deal with it.
Otherwise you run into management issues like making
sure the other program is running, and not minimized,
and located at the right place on the screen, and has
the JTextField in question in focus, and so on.In most cases, I would agree. But if his java program is header-less and just responds to the serial events and calls Robot.keyPress() and Robot.keyRelease() he will just be imitating the keyboard, which is exactly what most barcode readers can already do. And this would work in any program that can get keyboard input, no matter what the language was written in.
We are currently doing this with a web-based application. The web page just has a text field and when they scan the barcode it submits the page. Of course the barcode reader we are using just imitates the keyboard, no mucking around converting serial data into keyboard events.
I bet if the OP looks around he could find software that will already convert the barcode RS232 data into keyboard events.

Similar Messages

  • Please recommend if we have options to read xml file and insert data into table without a temporary table.

    Please recommend if we have options to read xml file and insert data into table without a temporary table. 

    DECLARE @data XML;
    SET @data =N'<Root>
    <List RecordID="946236" />
    <List RecordID="946237" />
    <List RecordID="946238" />
    <List RecordID="946239" />
    <List RecordID="946240" />
    </Root>'
    INSERT INTO t (id) SELECT T.customer.value('@RecordID', 'INT') AS id
    FROM @data.nodes('Root/List')
     AS T(customer);
    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

  • Drop, create and insert data into few intermediate tables

    Hi All,
    I need to schedule a process to drop, create and insert data into few intermediate tables on a weekly basis. Here is what i need to do in the stored procedure, which can be scheduled weekly.
    DROP TABLE TABLE_NAME1;
    DROP TABLE TABLE_NAME2;
    DROP TABLE TABLE_NAME3;
    CREATE TABLE TABLE_NAME1
    CREATE TABLE TABLE_NAME2
    CREATE TABLE TABLE_NAME3
    INSERT INTO TABLE_NAME1 SELECT ....;
    INSERT INTO TABLE_NAME2 SELECT ....;
    INSERT INTO TABLE_NAME3 SELECT ....;
    Any suggestions, examples or code on how to accomplish this task would be very helpful. Any question pls let me know.
    Thanks in advance.

    I am using the intermediate tables in an extract process. The idea was that the table would be created prior to calling the extract procedure and once the data written to the intermediate table had been processed the table would be dropped. This would be repeated each time the extract process is run. From a DBA's point or view, would it be better to just leave the table on the database and truncate it after each run or is removing it entirely best?

  • Data from table in xml Format and Inserting it into  Table

    Hi All
    I have table where xml data is stored in long format with xml tag know i have read the entire xml xoulmn which is xml tag and insert it into diffrent table can any suggest me the code
    Thanks & Regards

    I believe you are on the wrong forum. You want the XML DB forum.
    See:
    XML DB

  • I want to cut out a head from a photo and insert it into another photo again. In the head hair flying in the wind and the blue sky can be seen between the hairs. This blue sky I want to remove, so I can only use the head with hair flying in another photo.

    I want to cut out a head from a photo and insert it into another photo again. In the head hair flying in the wind and the blue sky can be seen between the hairs. This blue sky I want to remove, so I can only use the head with hair flying in another photo. Is it possible to simply delete this blue color of the sky?

    Make your selection and then use Refine Edge.
    See this video tutorial from Bob Gager.
    https://www.youtube.com/watch?v=xrl3Qwg6zSc

  • PHP/MySQL: Get value from one field, subtract 2, multiply by 20,   and insert value into another column on form submit

    Hello all,
    I'm pulling my hair out--thank you for any help you can give
    me.
    I have a form that a person fills out that has a field that
    asks "How
    many visitors including you" and I'd like them to type in a
    number, and
    on submit of the form, have that value -2 multiplied by 20
    and inserted
    into a "total cost" column.
    I'm using the standard DW server behaviors and I've searched
    the
    internet. How do I perform basic math on that value and
    insert it into
    the database?
    If you have any pointers, that would be great.
    Thank you!
    -John

    John R. Lenz wrote:
    > Your code below works great, and I just noticed links to
    your book were
    > available on your web site, and it's in the mail to me.
    Looking forward
    > to it.
    Thanks, hope you find it useful.
    > After the form is posted, I'd like to address the person
    who posted it
    > by their first name and last name, as well as some of
    the details. How
    > would you go about doing this in the best way? Would you
    set a variable
    > and echo it on the 'Thank you' page, or are there better
    ways of doing
    > it with a recordset and filtering it on form submit?
    To pass the details to a thank you page, you would need to
    store the
    information in $_SESSION variables. You could amend the
    earlier script
    like this:
    <?php
    session_start();
    if (isset($_POST['visitors'])) {
    if ($_POST['visitors'] < 3) {
    $num = 0;
    } else {
    $num = $_POST['visitors'] - 2;
    $_POST['total_cost'] = $num * 20;
    $_SESSION['total_cost'] = $_POST['total_cost'];
    $_SESSION['first_name'] = $_POST['first_name'];
    $_SESSION['last_name'] = $_POST['last_name'];
    ?>
    In the thank you page, put the following at the top of the
    page:
    <?php session_start(); ?>
    It must go before anything is output to the browser, so put
    it above the
    DOCTYPE declaration, and make sure there's no space before
    it.
    You can then use the $_SESSION variables in the thank you
    page.
    At the end of the page, add this to clear up the session
    variables:
    <?php
    $_SESSION = array();
    destroy_session();
    ?>
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Maint. Status in Dictionary: Maintain View- setting read and insert only.

    I am creating a maint. view for a custom table I have created.  Say the view was accessed via sm30, the user should be able to view existing records and insert new records, but not delete or change existing records.
    When in the Dictionary:Maintain View (from se11), I am on the Maint. Status tab and I see several options for access:
    -read only
    -read, change, insert, delete
    -read and change
    -read and change (time specific)
    The problem is, there is no option for READ and INSERT.  Does anyone know how to limit the access to this?
    Thanks,
    Aaron

    A workaround is to allow everything in DDIC and modify the function's PAI (se30 generation) to disallow whatever you want.
    Best!
    Jim

  • Select records from one database and insert it into another database

    Hi
    I need to write a statement to select records from one database which is on machine 1 and insert these records on a table in another database which is on machine 2. Following is what I did:
    1. I created the following script on machine 2
    sqlplus remedy_intf/test@sptd @load_hrdata.sql
    2. I created the following sql statements in file called load_hrdata.sql:
    rem This script will perform the following steps
    rem 1. Delete previous HR data/table to start w/ clean import tables
    rem 2. Create database link to HR database, and
    rem 3. Create User Data import table taking info from HR
    rem 4. Drop HRP link before exiting
    SET COPYCOMMIT 100
    delete from remedy.remedy_feed;
    commit;
    COPY FROM nav/donnelley@hrp -
    INSERT INTO remedy.remedy_feed -
    (EMPLID, FIRST_NAME, MI, LAST_NAME, BUSINESS_TITLE, WORK_PHONE, -
    RRD_INTRNT_EMAIL, LOCATION, RRD_OFFICE_MAIL, RRD_BUS_UNIT_DESCR) -
    USING SELECT EMPLID, FIRST_NAME, MI, LAST_NAME, BUSINESS_TITLE, WORK_PHONE, -
    RRD_INTRNT_EMAIL, LOCATION, RRD_OFFICE_MAIL, RRD_BUS_UNIT_DESCR -
    FROM ps_rrd_intf_medium -
    where empl_status IN ('A', 'L', 'P', 'S', 'X')
    COMMIT;
    EXIT;
    However, whenever I run the statement I keep getting the following error:
    SP2-0498: missing parenthetical column list or USING keyword
    Do you have any suggestions on how I can fix this or what am I doing wrong?
    Thanks
    Ali

    This doesn't seem to relate to Adobe Reader. Please let us know the product you are using so we may redirect you or refer to the list of forums at http://forums.adobe.com/

  • How to read a CSV file and Insert data into an Oracle Table

    Hi All,
    I have a Clob file as a in parameter in my PROC. . File is comma separated.need procedure that would parse this CLOB variable and populate in oracle table .
    Please let me some suggestions on this.
    Thanks,
    Chandra R

    jeneesh wrote:
    And, please don't "hijack" 5 year old thread..Better start a new one..I've just split it off to a thread of it's own. ;)
    @OP,
    I have a Clob file as a in parameter in my PROC. . File is comma separated.need procedure that would parse this CLOB variable and populate in oracle table .You don't have a "clob file" as there's no such thing. CLOB is a datatype for storing large character based objects. A file is something on the operating system's filesystem.
    So, why have you stored comma seperated data in a CLOB?
    Where did this data come from? If it came from a file, why didn't you use SQL*Loader or, even better, External Tables to read and parse the data into structured format when populating the database with it?
    If you really do have to parse a CLOB of data to pull out the comma seperated values, then you're going to have to write something yourself to do that, reading "lines" by looking for the newline character(s), and then breaking up the "lines" into the component data by looking for commas within it, using normal string functions such as INSTR and SUBSTR or, if necessary, REGEXP_INSTR and REGEXP_SUBSTR. If you have string data that contains commas but uses double quotes around the string, then you'll also have the added complexity of ignoring commas within such string data.
    Like I say... it's much easier with SQL*Loader of External Tables as these are designed to parse such CSV type data.

  • How can I read an ID-value from the LMS and insert this into an URL?

    Hi
    Right now I am struggling with a little problem. Hopefully anyone here knows the answer. For the latest course I am building (Captivate 6), it is necessary that at one point the course reads an ID-value from the LMS. After that, this ID should be inserted into an URL.
    To be more precisely: the ID must be read (getValue) from cmi.archive_id and inserted into an URL like that: http://.../archive.php?action=pdf&objectID=ARCHIVE_ID.
    Unfortunately I am more of a designer und less of a javascript-maestro (well...I am a javascript-noob to be precisely), therefore I am pretty clueless how to do that. I tried a simple executed action (run Javascript: cpEIGetValue('cmi.archive_id'); and after that open URL http://.../archive.php?action=pdf&objectID=ARCHIVE_ID), but...well...that didn't work.
    Any ideas?
    Thanks a lot in advance

    Think you'll find help looking at Jim Leichliter's website:
    http://captivatedev.com/
    He has great tutorials about JavaScript and also a widget that allows to enter a variable in URL's
    Lilybiri

  • How to parse XML Column and insert values into a table

    Hello,
    I am working on a simple project to demonstrate how to load and extract XML using SQL, I have already made a table that contains a column of XMLTYPE and loaded an XML file into it (code below)
    create or replace directory XMLSRC as 'C:\XMLSRC';
    drop table Inventory;
    create table Inventory(Inv XMLTYPE);
    INSERT INTO Inventory VALUES (XMLTYPE(bfilename('XMLSRC', 'Inventory.xml'),nls_charset_id('AL32UTF')));
    select * from Inventory;
    I now however need to get the XML data back out of that and loaded into a new table. Troubleshooting guides I have read online seem to only be dealing with parsing an external XML document and loading it into a table, and not what I need to do which is parse a column of XML data and load that into a table. The project trivial with simple tables containing only 3 columns.
    The table that needs to be loaded is as follows:
    create table InventoryOut(PartNumber Number(10), QTY Number(10), WhLocation varchar2(500));
    The XML document is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Inventory.xsd" generated="2012-04-09T17:36:30">
    <Inventory>
    <PartNumber>101</PartNumber>
    <QTY>12</QTY>
    <WhLocation>WA</WhLocation>
    </Inventory>
    </dataroot>
    Thank you for any help you can offer.

    First of all, thank you for your help!! Still stunned that you actually took the time to write out an eample using my tables/names/etc. Thank you!!
    Attached is the code, there seems to be an issue with referencing the other table, Inventory.Inv, I checked and that table and the Inv column are showing up in the database so I am not sure why it is having issues locating them, take a look at the code I wrote as well as the output (*I included the real version number for you this time :)
    EDIT: In your code right here:
    select xt.*
    3 from Inventory inve,
    4 XMLTable('/dataroot/Inventory'
    5 PASSING inve.Inv
    I think is where I am messing it up, perhaps not understanding fully what is going on, as you write "Inventory inve" and "inve.Inv" ---- Is inve a keyword that I am just not familiar with? I think this is where the issues lies in my code.
    END EDIT
    EDIT2: Well that looks like it was it, changed that to how you have it and it now works!!! Could you please explain what that few lines is doing, and what the xt.* and inve are doing? Thanks again!!!
    END EDIT2
    drop table InventoryOut;
    create table InventoryOut (PartNumber number(10), QTY number(10), WhLocation varchar2(500));
    insert into InventoryOut (PartNumber, QTY, WhLocation)
    select xt.*
    from Inventory Inv,
    XMLTable('/dataroot/Inventory'
    PASSING Inventory.Inv COLUMNS
    PartNumber number path 'PartNumber',
    QTY number path 'QTY',
    WhLocation path 'WhLocation')xt;
    select * from InventoryOut;
    select * from v$version;
    table INVENTORYOUT dropped.
    table INVENTORYOUT created.
    Error starting at line 4 in command:
    insert into InventoryOut (PartNumber, QTY, WhLocation)
    select xt.*
    from Inventory Inv,
    XMLTable('/dataroot/Inventory'
    PASSING Inventory.Inv COLUMNS
    PartNumber number path 'PartNumber',
    QTY number path 'QTY',
    WhLocation path 'WhLocation')xt
    Error at Command Line:8 Column:12
    Error report:
    SQL Error: ORA-00904: "INVENTORY"."INV": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    PARTNUMBER QTY WHLOCATION
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    If this helps here is the code and output for the creation of the Inventory table itself:
    create or replace directory XMLSRC as 'C:\XMLSRC';
    drop table Inventory;
    create table Inventory(Inv XMLTYPE);
    INSERT INTO Inventory VALUES (XMLTYPE(bfilename('XMLSRC', 'Inventory.xml'),nls_charset_id('AL32UTF')));
    select * from Inventory;
    directory XMLSRC created.
    table INVENTORY dropped.
    table INVENTORY created.
    1 rows inserted.
    INV
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Inventory.xsd" generated="2012-04-09T17:36:30">
    <Inventory>
    <PartNumber>101</PartNumber>
    <QTY>12</QTY>
    <WhLocation>WA</WhLocation>
    </Inventory>
    </dataroot>
    Thanks again for your help so far! Hope we can get this working :)
    Edited by: 926502 on Apr 11, 2012 2:47 PM
    Edited by: 926502 on Apr 11, 2012 2:49 PM
    Edited by: 926502 on Apr 11, 2012 2:54 PM
    Edited by: 926502 on Apr 11, 2012 2:54 PM
    Updated issue to solved - Edited by: 926502 on Apr 11, 2012 2:55 PM

  • Open an Excel file to read and load it into Oracle - Oracle COM Automation

    Hello All,
    Please I need your help for this problem:
    I need to load Excel sheet data (read the data) and load it into Oracle database (insert into a table), the excel file created and has data before, and saved with xls format. and I need to do that using the Oracle® COM Automation (ordcom package). The examples I found open and create a new workbook and deletes the old saved data, so I need to open (edit) the sheet just for reading.
    I appreciate ans sample code to help me do that, Please help me out. This is very urgent.
    Thanks alot and best regards,
    Nabil

    For reading from Excel, there are some easy ways like Oracle Heterogenious Services. If you want to use COM then:
    My orawpcom.dll file exists in the directory C:\oracle\product\10.2.0\db_2\bin
    C:\oracle\product\10.2.0\db_2\bin>dir orawpco*.dll
    Volume in drive C is C_Drive
    Volume Serial Number is 8A93-1441
    Directory of C:\oracle\product\10.2.0\db_2\bin
    03/20/2006  05:06 PM            61,440 orawpcom.dll
    10/11/2006  03:20 PM            81,920 orawpcom10.dll
                   2 File(s)        143,360 bytes
                   0 Dir(s)  65,407,717,376 bytes free
    C:\oracle\product\10.2.0\db_2\bin>Information about my database version.
    SQL> /* My databaser version */
    SQL> SELECT * FROM v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    SQL> Preparing the user SCOTT for COM automation.
    Now, I will run comwrap.sql from scott user. I have edited the comwrap.sql to adjust my library path here:
    create library utils_lib as 'C:\oracle\product\10.2.0\db_3\bin\orawpcom.dll';Running comwrap.sql and ExcelSolution.sql .....
    SQL> conn scott@orclsb
    Enter password: *****
    Connected.
    SQL> @c:\comwrap.sql
    drop library utils_lib
    ERROR at line 1:
    ORA-04043: object UTILS_LIB does not exist
    Library created.
    drop package ORDCOM
    ERROR at line 1:
    ORA-04043: object ORDCOM does not exist
    drop TYPE OAArgTable
    ERROR at line 1:
    ORA-04043: object OAARGTABLE does not exist
    Type created.
    drop TYPE OAArgTypeTable
    ERROR at line 1:
    ORA-04043: object OAARGTYPETABLE does not exist
    Type created.
    drop function OAgetNumber
    ERROR at line 1:
    ORA-04043: object OAGETNUMBER does not exist
    Function created.
    drop function OAgetStr
    ERROR at line 1:
    ORA-04043: object OAGETSTR does not exist
    Function created.
    drop function OAgetBool
    ERROR at line 1:
    ORA-04043: object OAGETBOOL does not exist
    Function created.
    drop function OAsetNumber
    ERROR at line 1:
    ORA-04043: object OASETNUMBER does not exist
    Function created.
    drop function OAsetString
    ERROR at line 1:
    ORA-04043: object OASETSTRING does not exist
    Function created.
    drop function OAsetBoolean
    ERROR at line 1:
    ORA-04043: object OASETBOOLEAN does not exist
    Function created.
    drop function OAInvokeDouble
    ERROR at line 1:
    ORA-04043: object OAINVOKEDOUBLE does not exist
    Function created.
    drop function OAInvokeBoolean
    ERROR at line 1:
    ORA-04043: object OAINVOKEBOOLEAN does not exist
    Function created.
    drop function OAInvokeString
    ERROR at line 1:
    ORA-04043: object OAINVOKESTRING does not exist
    Function created.
    drop function OACreate
    ERROR at line 1:
    ORA-04043: object OACREATE does not exist
    Function created.
    drop function OADestroy
    ERROR at line 1:
    ORA-04043: object OADESTROY does not exist
    Function created.
    drop function OAGetLastError
    ERROR at line 1:
    ORA-04043: object OAGETLASTERROR does not exist
    Function created.
    drop function OAQueryMethods
    ERROR at line 1:
    ORA-04043: object OAQUERYMETHODS does not exist
    Function created.
    Package created.
    Package body created.
    SQL>
    SQL> @c:\ExcelSolution.sql
    drop package ORDExcel
    ERROR at line 1:
    ORA-04043: object ORDEXCEL does not exist
    Package created.
    Package body created.
    SQL>
    I have modified ORDExcel a little bit and renamed it as ORDExcelSB. You need this version for reading the excel.
    SQL> @C:\ExcelSolutionSB.sql
    Package dropped.
    Package created.
    Package body created.
    SQL> The actual code of ORDExcelSB (ExcelSolutionSB.sql) Is:
    set serveroutput on;
    drop package ORDExcelSB;
    CREATE PACKAGE ORDExcelSB AS
       /* Declare externally callable subprograms. */
       FUNCTION CreateExcelApplication(servername VARCHAR2) RETURN binary_integer;
       FUNCTION OpenExcelFile(filename VARCHAR2, sheetname VARCHAR2) RETURN binary_integer;
       FUNCTION CreateExcelWorkSheet(servername varchar2) return binary_integer;
       FUNCTION InsertData(range varchar2, data binary_integer, type varchar2) return binary_integer;
       FUNCTION InsertDataReal(range varchar2, data double precision, type varchar2) return binary_integer;
       FUNCTION GetDataNum(range varchar2) return binary_integer;
       FUNCTION GetDataStr(range varchar2) return varchar2;
       FUNCTION GetDataReal(range varchar2) return double precision;
       FUNCTION GetDataDate(range varchar2) return date;
       FUNCTION InsertData(range varchar2, data varchar2, type varchar2) return binary_integer;
       FUNCTION InsertData(range varchar2, data Date, type varchar2) return binary_integer;
       FUNCTION InsertChart(xpos binary_integer, ypos binary_integer, width binary_integer,
                                  height binary_integer, range varchar2, type varchar2) return binary_integer;
       FUNCTION SaveExcelFile(filename varchar2) return binary_integer;
       FUNCTION ExitExcel return binary_integer;
    END ORDExcelSB;
    CREATE PACKAGE BODY ORDExcelSB AS
       DummyToken          binary_integer;     
       applicationToken binary_integer:=-1;
       WorkBooksToken     binary_integer:=-1;
       WorkBookToken     binary_integer:=-1;
       WorkSheetToken     binary_integer:=-1;
       WorkSheetToken1     binary_integer:=-1;
       RangeToken          binary_integer:=-1;
       ChartObjectToken     binary_integer:=-1;
       ChartObject1          binary_integer:=-1;
       Chart1Token          binary_integer:=-1;
       i                    binary_integer;
       retNum               binary_integer;
       retReal               double precision;
       retStr               varchar2(255);
       retDate               DATE;
    error_src varchar2(255);
    error_description varchar2(255);
    error_helpfile varchar2(255);
    error_helpID binary_integer;
    FUNCTION CreateExcelApplication(servername VARCHAR2) RETURN binary_integer IS
      BEGIN
        dbms_output.put_line('Creating Excel application...');
        i := OrdCOM.CreateObject('Excel.Application',
                                 0,
                                 servername,
                                 applicationToken);
        IF (i != 0) THEN
          ORDCOM.GetLastError(error_src,
                              error_description,
                              error_helpfile,
                              error_helpID);
          dbms_output.put_line(error_src);
          dbms_output.put_line(error_description);
          dbms_output.put_line(error_helpfile);
        END IF;
        dbms_output.put_line('Invoking Workbooks...');
        i := ORDCOM.GetProperty(applicationToken,
                                'WorkBooks',
                                0,
                                WorkBooksToken);
        IF (i != 0) THEN
          ORDCOM.GetLastError(error_src,
                              error_description,
                              error_helpfile,
                              error_helpID);
          dbms_output.put_line(error_src);
          dbms_output.put_line(error_description);
          dbms_output.put_line(error_helpfile);
        END IF;
        RETURN i;
      END CreateExcelApplication;
      FUNCTION OpenExcelFile(filename VARCHAR2, sheetname VARCHAR2)
        RETURN binary_integer IS
      BEGIN
        dbms_output.put_line('Opening Excel file ' || filename || ' ...');
        ORDCOM.InitArg();
        ORDCOM.SetArg(filename, 'BSTR');
        i := ORDCOM.Invoke(WorkBooksToken, 'Open', 1, DummyToken);
        IF (i != 0) THEN
          ORDCOM.GetLastError(error_src,
                              error_description,
                              error_helpfile,
                              error_helpID);
          dbms_output.put_line(error_src);
          dbms_output.put_line(error_description);
          dbms_output.put_line(error_helpfile);
        END IF;
        dbms_output.put_line('Opening WorkBook');
        i := ORDCOM.GetProperty(applicationToken,
                                'ActiveWorkbook',
                                0,
                                WorkBookToken);
        IF (i != 0) THEN
          ORDCOM.GetLastError(error_src,
                              error_description,
                              error_helpfile,
                              error_helpID);
          dbms_output.put_line(error_src);
          dbms_output.put_line(error_description);
          dbms_output.put_line(error_helpfile);
        END IF;
        dbms_output.put_line('Invoking WorkSheets..');
        i := ORDCOM.GetProperty(applicationToken,
                                'WorkSheets',
                                0,
                                WorkSheetToken1);
        IF (i != 0) THEN
          ORDCOM.GetLastError(error_src,
                              error_description,
                              error_helpfile,
                              error_helpID);
          dbms_output.put_line(error_src);
          dbms_output.put_line(error_description);
          dbms_output.put_line(error_helpfile);
        END IF;
        dbms_output.put_line('Invoking WorkSheet');
        ORDCOM.InitArg();
        ORDCOM.SetArg(sheetname, 'BSTR');
        i := ORDCOM.GetProperty(WorkBookToken, 'Sheets', 1, WorkSheetToken);
        IF (i != 0) THEN
          ORDCOM.GetLastError(error_src,
                              error_description,
                              error_helpfile,
                              error_helpID);
          dbms_output.put_line(error_src);
          dbms_output.put_line(error_description);
          dbms_output.put_line(error_helpfile);
        END IF;
        dbms_output.put_line('Opened ');
        RETURN i;
      END OpenExcelFile;
    * Invoke the Excel Automation Server and create a Workbook object as
    * well as a worksheet object
    FUNCTION CreateExcelWorkSheet(servername varchar2) return binary_integer IS
    BEGIN
         dbms_output.put_line('Creating Excel application...');
         i:=ORDCOM.CreateObject('Excel.Application', 0, servername,applicationToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         dbms_output.put_line('Invoking Workbooks...');
         /*i:=ORDCOM.Invoke(applicationToken, 'WorkBooks',0, WorkBooksToken);*/
         i:=ORDCOM.GetProperty(applicationToken, 'WorkBooks', 0, WorkBooksToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         dbms_output.put_line('Invoking Add to WorkBooks...');
         ORDCOM.InitArg();
         ORDCOM.SetArg(-4167,'I4');
         i:=ORDCOM.Invoke(WorkBooksToken, 'Add', 1, WorkBookToken);
    IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         dbms_output.put_line('Invoking WorkSheets..');
         ORDCOM.InitArg();
         ORDCOM.SetArg('Sheet 1','BSTR');
    /*     i:=ORDCOM.Invoke(applicationToken, 'WorkSheets', 1, WorkSheetToken);*/
    i:=ORDCOM.GetProperty(applicationToken, 'WorkSheets', 0, WorkSheetToken1);
    IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
    i:=ORDCOM.Invoke(WorkSheetToken1, 'Add', 0, WorkSheetToken);
    IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         return i;
    END CreateExcelWorkSheet;
    * Invoke the Range method to obtain a range token. Then set the property value
    * at the specified range to the data required
    FUNCTION InsertData( range varchar2,
                             data binary_integer,
                             type varchar2)
                             RETURN binary_integer IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.SetProperty(RangeToken, 'Value', data, type);
         IF (i=0) THEN
               i:=ORDCOM.SetProperty(RangeToken, 'ColumnWidth', 15, 'I2');
         END IF;
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN i;
    END InsertData;
    * Invoke the Range method to obtain a range token. Then set the property value
    * at the specified range to the data required
    FUNCTION GetDataNum( range varchar2)
                             RETURN binary_integer IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.GetProperty(RangeToken, 'Value', 0, retNum);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN retNum;
    END GetDataNum;
    FUNCTION GetDataReal( range varchar2)
                             RETURN double precision IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.GetProperty(RangeToken, 'Value', 0, retReal);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN retReal;
    END GetDataReal;
    FUNCTION GetDataStr( range varchar2)
                             RETURN varchar2 IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.GetProperty(RangeToken, 'Value', 0, retStr);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN retStr;
    END GetDataStr;
    FUNCTION GetDataDate( range varchar2)
                             RETURN Date IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.GetProperty(RangeToken, 'Value', 0, retDate);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN retDate;
    END GetDataDate;
    FUNCTION InsertData( range varchar2,
                             data DATE,
                             type varchar2)
                             RETURN binary_integer IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         i:=ORDCOM.SetProperty(RangeToken, 'Value', data, type);
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN i;
    END InsertData;
    FUNCTION InsertDataReal( range varchar2,
                             data double precision,
                             type varchar2)
                             RETURN binary_integer IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         i:=ORDCOM.SetProperty(RangeToken, 'Value', data, type);
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN i;
    END InsertDataReal;
    FUNCTION InsertData( range varchar2,
                             data varchar2,
                             type varchar2)
                             RETURN binary_integer IS
    BEGIN
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
         i:=ORDCOM.SetProperty(RangeToken, 'Value', data, type);
         i:=ORDCOM.DestroyObject(RangeToken);
         RETURN i;
    END InsertData;
    * Insert a chart at the x and y position of the spreadsheet with the desired
    * height and width. Then also uses the ChartWizard to draw the graph with data
    * in a specified range area with a specified charting type.
    FUNCTION InsertChart(xpos binary_integer, ypos binary_integer,
                              width binary_integer, height binary_integer,
                              range varchar2, type varchar2) RETURN binary_integer IS
         charttype binary_integer:= -4099;
    BEGIN
         ORDCOM.InitArg();
         i:=ORDCOM.GetProperty(WorkSheetToken, 'ChartObjects', 0, ChartObjectToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         ORDCOM.InitArg();
         ORDCOM.SetArg(xpos,'I2');
         ORDCOM.SetArg(ypos,'I2');
         ORDCOM.SetArg(width,'I2');
         ORDCOM.SetArg(height,'I2');
         i:=ORDCOM.Invoke(ChartObjectToken, 'Add', 4, ChartObject1);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.GetProperty(ChartObject1, 'Chart', 0,Chart1Token);
         ORDCOM.InitArg();
         ORDCOM.SetArg(range, 'BSTR');
         i:=ORDCOM.GetProperty(WorkSheetToken,'Range', 1, RangeToken);
         ORDCOM.InitArg();
         ORDCOM.SetArg(RangeToken, 'DISPATCH');
         IF type='xlPie' THEN
              charttype := -4102;
         ELSIF type='xl3DBar' THEN
              charttype := -4099;
         ELSIF type='xlBar' THEN
              charttype := 2;
         ELSIF type='xl3dLine' THEN
              charttype:= -4101;
         END IF;
         ORDCOM.SetArg(charttype,'I4');
         i:=ORDCOM.Invoke(Chart1Token,'ChartWizard', 2, DummyToken);
         i:=ORDCOM.DestroyObject(RangeToken);
         i:=ORDCOM.DestroyObject(ChartObjectToken);
         i:=ORDCOM.DestroyObject(ChartObject1);
         i:=ORDCOM.DestroyObject(Chart1Token);
         RETURN i;
    END InsertChart;
    * Save the Excel File. WARNING: Do not specify a filename that already exist
    * since there is no graphical context, Oracle would not be able to pop
    * out a warning message for existing file. This causes Excel to hang
    FUNCTION SaveExcelFile(filename varchar2) return binary_integer IS
    BEGIN
         dbms_output.put_line('Saving Excel file...');
         ORDCOM.InitArg();
         ORDCOM.SetArg(filename,'BSTR');
         i:=ORDCOM.Invoke(WorkBookToken, 'SaveAs', 1, DummyToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         RETURN i;     
    END SaveExcelFile;
    * Close the Excel spreadsheet and exit from it
    FUNCTION ExitExcel return binary_integer is
    BEGIN
         dbms_output.put_line('Closing workbook and quitting...');
         ORDCOM.InitArg();
         ORDCOM.InitArg();
         ORDCOM.SetArg(FALSE,'BOOL');
         dbms_output.put_line('Closing workbook...');
         i:=ORDCOM.Invoke(WorkBookToken, 'Close', 0, DummyToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(WorkBookToken);     
         ORDCOM.InitArg();
         dbms_output.put_line('Closing workbooks...');
         i:=ORDCOM.Invoke(WorkBooksToken, 'Close', 0, DummyToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(WorkBooksToken);
         i:=ORDCOM.Invoke(applicationToken, 'Quit', 0, DummyToken);
         IF (i!=0) THEN
         ORDCOM.GetLastError(error_src, error_description, error_helpfile, error_helpID);
         dbms_output.put_line(error_src);
         dbms_output.put_line(error_description);
         dbms_output.put_line(error_helpfile);
         END IF;
         i:=ORDCOM.DestroyObject(WorkSheetToken);     
         i:=ORDCOM.DestroyObject(WorkSheetToken1);     
         i:=ORDCOM.DestroyObject(applicationToken);
         i:=ORDCOM.DestroyObject(ChartObjectToken);
         i:=ORDCOM.DestroyObject(Chart1Token);
         i:=ORDCOM.DestroyObject(ChartObject1);
         i:=ORDCOM.DestroyObject(dummyToken);
         RETURN i;
    END ExitExcel;
    END ORDExcelSB;
    /I have created an excel named as C:\Example.xls.
    Name     SlNo     Job     Dept     Salary     Bonus
    Saubhik Banerjee     706090     IT Specialist     GBS     100     10
    Partha S Mohanty     706091     Pogrmmer     APPS     70     20
    Partha Sarkar     889300     Condultant     FIN     200     30
    Useless     98009     PM     PM     900     90
    SQL> SET SERVEROUT ON
    SQL> DECLARE
      2 
      3    v_Name          varchar2(90);
      4    v_SlNo          varchar2(100);
      5    v_Job           varchar2(200);
      6    v_Dept          varchar2(100);
      7    v_recon_remark  varchar2(50);
      8    v_sal_amt_usd   number;
      9    v_Bonus_amt_usd number;
    10 
    11    result INTEGER;
    12 
    13    i        binary_integer;
    14    filename varchar2(255);
    15 
    16  BEGIN
    17 
    18    filename := 'C:\Example.xls';
    19 
    20    result := ORDExcelSB.CreateExcelApplication('');
    21    result := ORDExcelSB.OpenExcelFile(filename, 'Sheet1');
    22 
    23    /* Excluding the header row and reading the first 5 row */
    24    FOR n in 2 .. 5 LOOP
    25   
    26      v_Name          := ORDExcelSB.GetDataStr('A' || n);
    27      v_SlNo          := ORDExcelSB.GetDataReal('B' || n);
    28      v_Job           := ORDExcelSB.GetDataStr('C' || n);
    29      v_Dept          := ORDExcelSB.GetDataStr('D' || n);
    30      v_sal_amt_usd   := ORDExcelSB.GetDataNum('E' || n);
    31      v_Bonus_amt_usd := ORDExcelSB.GetDataNum('F' || n);
    32   
    33      dbms_output.put_line(v_Name || '  ' || v_SlNo || '  ' || v_Job || '  ' ||
    34                           v_Dept || '  ' || v_sal_amt_usd || '  ' ||
    35                           v_Bonus_amt_usd);
    36   
    37    END LOOP;
    38 
    39    result := ORDExcelSB.ExitExcel();
    40  EXCEPTION
    41    WHEN OTHERS THEN
    42      result := ORDExcelSB.ExitExcel();
    43      RAISE;
    44  END;
    45  /
    Creating Excel application...
    Invoking Workbooks...
    Opening Excel file C:\Example.xls ...
    Opening WorkBook
    Invoking WorkSheets..
    Invoking WorkSheet
    Opened
    Saubhik Banerjee  706090  IT Specialist  GBS  100  10
    Partha S Mohanty  706091  Pogrmmer  APPS  70  20
    Partha Sarkar  889300  Condultant  FIN  200  30
    Useless  98009  PM  PM  900  90
    Closing workbook and quitting...
    Closing workbook...
    Closing workbooks...
    PL/SQL procedure successfully completed.
    SQL> Although, You haven't asked, but you can use this code to write to excel file (.xls)
    DECLARE
    CURSOR c1 IS     
         SELECT empno, ename, dname, sal, hiredate
         FROM emp e, dept d
         WHERE e.deptno = d.deptno;
    error_message varchar2(1200);
    n binary_integer:=2;
    i binary_integer;
    filename varchar2(255);
    cellIndex varchar2(40);
    cellValue varchar2(40);
    cellColumn varchar2(10);
    returnedTime varchar2(20);
    currencyvalue double precision;
    datevalue DATE;
    empno binary_integer;
    looptext varchar2(20);
    error_src varchar2(255);
    error_description varchar2(255);
    error_helpfile varchar2(255);
    error_helpID binary_integer;
    begin
    filename:='c:\example2.xls';
    i:=ORDExcel.CreateExcelWorkSheet('');
    i:=ORDExcel.InsertData('A1', 'EmpNo', 'BSTR');
    i:=ORDExcel.InsertData('B1', 'Name', 'BSTR');
    i:=ORDExcel.InsertData('C1', 'Dept', 'BSTR');
    i:=ORDExcel.InsertData('D1', 'Salary', 'BSTR');
    i:=ORDExcel.InsertData('E1', 'HireDate', 'BSTR');
    For c1_rec IN c1 LOOP
    cellColumn:=TO_CHAR(n);
    cellIndex:=CONCAT('A',cellColumn);
    cellValue:=TO_CHAR(c1_rec.empno);
    empno:=cellValue;
    i:=ORDExcel.InsertData(cellIndex, empno, 'I2');
    cellIndex:=CONCAT('B',cellColumn);
    cellValue:=c1_rec.ename;
    i:=ORDExcel.InsertData(cellIndex, cellValue, 'BSTR');
    cellIndex:=CONCAT('C',cellColumn);
    cellValue:=c1_rec.dname;
    i:=ORDExcel.InsertData(cellIndex, cellValue, 'BSTR');
    cellIndex:=CONCAT('D',cellColumn);
    cellValue:=c1_rec.sal;
    currencyValue:=cellValue;
    i:=ORDExcel.InsertData(cellIndex, currencyValue, 'CY');
    cellIndex:=CONCAT('E',cellColumn);
    dateValue:=c1_rec.hiredate;
    i:=ORDExcel.InsertData(cellIndex, dateValue, 'DATE');
    n:=n+1;
    END LOOP;
    i:=ORDExcel.SaveExcelFile(filename);
    i:=ORDExcel.ExitExcel();
    EXCEPTION
    WHEN OTHERS THEN
      i:=ORDExcel.ExitExcel();
      RAISE;
    END;

  • Sequence and INSERT ALL INTO with parallelism problem

    I want to use the INSERT ALL INTO style of multiple-inserts (with 10gR2) to normalize a wide table into a skinny table. The large table has a few fk columns and 100 numeric columns. I want to insert them into another table as 100 rows in a single SQL pass.
    CREATE TABLE WIDE_SOURCE(
    FKEY_1 INTEGER,
    FKEY_2 INTEGER,
    FKEY_3 INTEGER,
    AMT001 INTEGER,
    AMT002 INTEGER,
    AMT100 INTEGER);
    CREATE TABLE SKINNY_DEST(
    PKEY INTEGER NOT NULL,
    FKEY_1 INTEGER,
    FKEY_2 INTEGER,
    FKEY_3 INTEGER,
    AMT INTEGER,
    CONSTRAINT PK_SKINNY_DEST PRIMARY KEY(PKEY)
    CREATE SEQUENCE KEY_GEN MINVALUE 1 INCREMENT BY 100 START WITH 1;
    INSERT ALL
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+001, FKEY_1, FKEY_2, FKEY_3, AMT001)
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+002, FKEY_1, FKEY_2, FKEY_3, AMT002)
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+003, FKEY_1, FKEY_2, FKEY_3, AMT003)
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+100, FKEY_1, FKEY_2, FKEY_3, AMT100)
    SELECT * FROM WIDE_SOURCE;
    With this query, each row in WIDE_SOURCE will generate 100 rows in SKINNY_DEST. I know that works. Unfortunately, it appears that the sequence isn't working the way I thought it should- with multiple nodes and parallel insert, there's some overlap in the generated key.
    Is there a better way? I've considered 100 separate sequences, but that just seems plain silly. Am I trying to have my cake (the parallelism) and eat it too (by disregarding limitations of Oracle's sequence construct)?

    Have not tested this on a RAC, but it seems to work fine - as expected without any overlaps. (version 10.2.0.1.0)
    SQL> create sequence seq_id start with 1 increment by 10 nomaxvalue nocycle;
    Sequence created.
    SQL> create table skinny ( id number, fk_key1 number );
    Table created.
    SQL> create table wide( fk_key1 number, name varchar2(32) ) parallel( degree 2 );
    Table created.
    SQL> insert into wide select object_id, object_name from all_objects where rownum < 100000;
    51853 rows created.
    SQL> commit;
    Commit complete.
    SQL> exec DBMS_STATS.Gather_Table_Stats( USER, 'WIDE' );
    PL/SQL procedure successfully completed.
    SQL> alter session enable parallel dml;
    Session altered.
    SQL> set autotrace on
    SQL> insert all
    2 into skinny values( seq_id.nextval+0, fk_key1 )
    3 into skinny values( seq_id.nextval+1, fk_key1 )
    4 into skinny values( seq_id.nextval+2, fk_key1 )
    5 into skinny values( seq_id.nextval+3, fk_key1 )
    6 into skinny values( seq_id.nextval+4, fk_key1 )
    7 into skinny values( seq_id.nextval+5, fk_key1 )
    8 into skinny values( seq_id.nextval+6, fk_key1 )
    9 into skinny values( seq_id.nextval+7, fk_key1 )
    10 into skinny values( seq_id.nextval+8, fk_key1 )
    11 into skinny values( seq_id.nextval+9, fk_key1 )
    12 select
    13 /*+ FULL(o) PARALLEL(w,2) */
    14 fk_key1
    15 from wide w
    16 /
    518530 rows created.
    Execution Plan
    Plan hash value: 1585486391
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
    | 0 | INSERT STATEMENT | | 51853 | 253K| 37 (14)| 00:00:01 | | | |
    | 1 | MULTI-TABLE INSERT | | | | | | | | |
    | 2 | INTO | SKINNY | | | | | | | |
    | 3 | INTO | SKINNY | | | | | | | |
    | 4 | INTO | SKINNY | | | | | | | |
    | 5 | INTO | SKINNY | | | | | | | |
    | 6 | INTO | SKINNY | | | | | | | |
    | 7 | INTO | SKINNY | | | | | | | |
    | 8 | INTO | SKINNY | | | | | | | |
    | 9 | INTO | SKINNY | | | | | | | |
    | 10 | INTO | SKINNY | | | | | | | |
    | 11 | INTO | SKINNY | | | | | | | |
    | 12 | SEQUENCE | SEQ_ID | | | | | | | |
    | 13 | PX COORDINATOR | | | | | | | | |
    | 14 | PX SEND QC (RANDOM)| :TQ10000 | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
    | 15 | PX BLOCK ITERATOR | | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | PCWC | |
    | 16 | TABLE ACCESS FULL| WIDE | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | PCWP | |
    Statistics
    37168 recursive calls
    26542 db block gets
    7610 consistent gets
    0 physical reads
    12696752 redo size
    498 bytes sent via SQL*Net to client
    1084 bytes received via SQL*Net from client
    6 SQL*Net roundtrips to/from client
    3 sorts (memory)
    0 sorts (disk)
    518530 rows processed
    SQL> set autotrace off
    SQL> commit;
    Commit complete.
    SQL> select
    2 id, count(*)
    3 from skinny
    4 group by id
    5 having count(*) > 1
    6 /
    no rows selected
    SQL>
    I checked the PQ V$ views and PQ slaves were used.

  • Dequeue XML from Oracle AQ and insert data into table

    Using PL/SQL in a stored procedure, I need to dequeue a message from an Oracle AQ queue, parse the XML content and insert the data in an Oracle table. This is being done in Oracle 9.2.x.
    The payload for the message consists of 2 attributes, APPLICATION_DATA (VARCHAR2(32) and MESSAGE_BODY (CLOB). The MESSAGE_BODY is an XML document. A sample of the message is shown below:
    (M_NAME=MSG_LAW_WR_CRE_UPD, <?xml version = "1.0"?>
    <MSG_LAW_WR_CRE_UPD ID = "WMIS-4744" SRC_SYSTEM_CODE = "WMIS" SRC_SYSTEM_INSTANCE = "WMIS">
    <WR:CMP_LAW_WR_CRE_UPD xmlns:WR = "WR" >
    <WR:DATETIME>12/19/2005</WR:DATETIME>
    <WR:RUSCODE>100</WR:RUSCODE>
    <WR:WRNO>38213</WR:WRNO>
    </WR:CMP_LAW_WR_CRE_UPD>
    </MSG_LAW_WR_CRE_UPD>)
    This message needs to be dequeued from a queue named INBOUND, parsed and inserted into a table named INFO_TO_ACCT (CREATEDATE date, RUSCODE varchar2(10), WRNO number).
    Any help would be appreciated.

    SELECT EXTRACTVALUE(xmltype('<?xml version = "1.0"?>
    <MSG_LAW_WR_CRE_UPD ID = "WMIS-4744" SRC_SYSTEM_CODE = "WMIS" SRC_SYSTEM_INSTANCE = "WMIS">
    <CMP_LAW_WR_CRE_UPD>
    <DATETIME>12/19/2005</DATETIME>
    <RUSCODE>100</RUSCODE>
    <WRNO>38213</WRNO>
    </CMP_LAW_WR_CRE_UPD>
    </MSG_LAW_WR_CRE_UPD>'),'//DATETIME/text()') FROM DUAL;
    hope this helps.

  • Problem inserting String into postgresql.

    Hello,
    I have this code in postgresql:
    select merge_db(3, 1, '1901-1-1', '1901-1-1', '1901-1-1', 1, 1, 1, 1, 1, 1 , 1, 'hola', 1);
    That calls the function merge_db and inserts data, but it wont work in my java program:
    String queryPostgresql = "select merge_db("+ oid +", "+ uid +", to_timestamp("+ etime +"), to_timestamp("+ pstime +"), to_timestamp("+ rstime +"), "+ elapsed +", "+ espera +", "+ numcpu +", "+ numcpu +", "+ memory +", "+ error +", "+ memory +", "+ etiqueta +", "+ finalizado +")";
    The main problem is in the field "etiqueta" which is varchar in sql and String in java. It throws "ERROR: the column (content of the variable) does not exist"
    Also I'm not completely confident about the timestamp fields, I think they are causing problems too.
    This is the merge_db function:
    create function merge_db(key int, data1 int, data2 timestamp with time zone , data3 timestamp with time zone, data4 timestamp with time zone, data5 int, data6 int, data7 int, data8 int, data9 int, data10 int, data11 int, data12 text, data13 int) returns void as
    $$
    begin
    loop
    update trabajos set time_elapsed = data5 where oid = key;
    if found then
    return;
    end if;
    begin insert into trabajos(oid,uid,fecha_fin,fecha_acept,fecha_exec,time_elapsed,espera,ncpu,rec_ncpu,rec_memoria,error,memoria,etiqueta,finalizado) values (key, data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12, data13);
    return;
    exception when unique_violation then
    end;
    end loop;
    end;
    $$
    language plpgsql;
    Thank you!

    Here is my code then:
    Connection connPostgresql = DriverManager.getConnection(myUrlPostgresql, "database", "pass");
    Statement StmtPostgresql = connPostgresql.createStatement();
    String queryPostgresql = "select merge_db("+ oid +", "+ uid +", to_timestamp("+ etime +"), to_timestamp("+ pstime +"), to_timestamp("+ rstime +"),
    "+ elapsed +", "+ espera +", "+ numcpu +", "+ numcpu +", "+ memory +", "+ error +", "+ memory +", "+ etiqueta +", "+ finalizado +")";
    StmtPostgresql.executeUpdate(queryPostgresql);The function in postgresql is this one:
    create function merge_db(key int, data1 int, data2 timestamp with time zone , data3 timestamp with time zone,
    data4 timestamp with time zone, data5 int, data6 int, data7 int, data8 int, data9 int, data10 int, data11 int, data12 text, data13 int)
    returns void as
    $$
    begin
    loop
    update trabajos set time_elapsed = data5 where oid = key;
    if found then
    return;
    end if;
    begin
    insert into trabajos(oid,uid,fecha_fin,fecha_acept,fecha_exec,time_elapsed,espera,ncpu,rec_ncpu,rec_memoria,error,memoria,etiqueta,finalizado)
    values (key, data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12, data13);
    return;
    exception when unique_violation then
    end;
    end loop;
    end;
    $$
    language plpgsql;The problem is when i try to use preparedstatement i won't work and throw that exception.
    And another question (I'm a pain in the ass): Java is throwing an exception regarding postgresql that says "org.postgresql.util.PSQLException: A result was returned when none was expected"
    Thank you very much.
    Edited by: 850264 on 13/04/2011 08:31

Maybe you are looking for