INSERT INTO QUERY AGAINST ORACLE

I've tested the INSERTINTO query where it successfully pulls data from one table in SQL DB and inserts into another SQL DB.
However, when I use the same script to pull data from one table in Oracle DB to another table in Oracle DB, I get an error.
I'm assuming the syntax is a little different for Oracle?
Added debugging and the query looks like this...
** Begin FDM Runtime Error Log Entry [2012-06-27-21:20:57] **
ERROR:
Code............................................. 1
Description...................................... INSERT INTO tWadmin30284128092 (PartitionKey, CatKey, PeriodKey, DataView, CalcAcctType, Entity, Account, UD1, UD2, UD4, Amount) SELECT 752, 12, '31-Mar-2008', 'YTD', 9, Entity, Account, UD1, UD2, UD4, Amount FROM tdataseg4
Error Message...
** Begin FDM Runtime Error Log Entry [2012-06-27-21:10:52] **
ERROR:
Code............................................. -2147217900
Description...................................... ORA-02291: integrity constraint (FDM1113ORCL.FKC_DS6_TCTRLPERIOD) violated - parent key not found
INSERT /*+ Append */ INTO tDataSeg6 ( PartitionKey, CatKey, PeriodKey, DataView, CurKey, CalcAcctType, ChangeSign, JournalID, Amount, AmountX, Account, AccountX, AccountR, AccountF, Entity, EntityX, EntityR, EntityF, ICP, ICPX, ICPR, ICPF, UD1, UD1X, UD1R, UD1F, UD2, UD2X, UD2R, UD2F, UD3, UD3X, UD3R, UD3F, UD4, UD4X, UD4R, UD4F, DESC1, DESC2, ATTR1, ATTR2, ATTR3, ATTR4, ATTR5, ATTR6, ATTR7, ATTR8, ATTR9, ATTR10, ATTR11, ATTR12, ATTR13, ATTR14, ArchiveID, HasMemoItem, StaticDataKey ) SELECT PartitionKey, CatKey, PeriodKey, DataView, CurKey, CalcAcctType, ChangeSign, JournalID, Amount, AmountX, Account, AccountX, AccountR, AccountF, Entity, EntityX, EntityR, EntityF, ICP, ICPX, ICPR, ICPF, UD1, UD1X, UD1R, UD1F, UD2, UD2X, UD2R, UD2F, UD3, UD3X, UD3R, UD3F, UD4, UD4X, UD4R, UD4F, DESC1, DESC2, ATTR1, ATTR2, ATTR3, ATTR4, ATTR5, ATTR6, ATTR7, ATTR8, ATTR9, ATTR10, ATTR11, ATTR12, ATTR13, ATTR14, ArchiveID, HasMemoItem, StaticDataKey From tWadmin436038889587
Procedure........................................ clsDataManipulation.fExecuteDML
Component........................................ upsWDataWindowDM
Version.......................................... 1111
Thread........................................... 3888
Function INSERTINTO(strLoc, lngCatKey, dblPerKey, strWorkTableName)
'Oracle Hyperion FDM IMPORT Integration Script:
'Created By:       admin
'Date Created:       2012-06-27-21:01:10
'Purpose:
Dim objSS 'ADODB.Connection
Dim strSQL 'SQL String
Dim rs 'Recordset
Dim rsAppend 'tTB table append rs Object
Dim strPeriod
Dim strYear
'Period
'strPeriod=MonthName(Month(RES.PdtePerKey))
a=CStr(FormatDateTime(RES.PdtePerKey,1))
'Tuesday,January 30, 2012
b=Right(a,(Len(a)-Len(DW.Utilities.fParseString(a,1,1,",")))) '7
c=DW.Utilities.fParseString(b,2,2,",")
strPeriod=Left(c,3)
'Year
'strYear=Year(RES.PdtePerKey)
strYear=Right(b,4)
DW.DBTools.mLogError 1, CStr(strPeriod), CStr(strYear), Nothing
'Initialize objects
Set cnSS = CreateObject("ADODB.Connection")
'Connect To SQL Server database
cnss.open "Provider=OraOLEDB.Oracle.1;Password=password;Persist Security Info=True;User ID=fdm1113orcl;Data Source=orcl"
'DW.DBTools.mLogError 1, CStr(strSQL), CStr(strSQL), Nothing
'Initialize common SQL statement
strSQL = "INSERT INTO " & _
        strWorkTableName & " " & _
        "(PartitionKey, CatKey, PeriodKey, DataView, CalcAcctType, Entity, Account, UD1, UD2, UD4, Amount) " & _
        "SELECT  " & RES.PlngLocKey & ", " & RES.PlngCatKey & ", " & _
        "'" & Day(RES.PdtePerKey) & "-" & MonthName(Month(RES.PdtePerKey), True) & "-" & Year(RES.PdtePerKey) & "', " & _
        "'YTD', 9, Entity, Account, UD1, UD2, UD4, Amount " & _
        "FROM tdataseg4 " '& _
DW.DBTools.mLogError 1, CStr(strSQL), CStr(strWorkTableName), Nothing
DW.DataManipulation.fExecuteDML(strSQL)
'cnss.Execute strSQL
'Records loaded
RES.PlngActionType = 6
RES.PstrActionValue = "SQL Import successful!"
'Assign Return value
INSERTINTO = True
cnss.Close
Set cnss = Nothing
End FunctionEdited by: user12152138 on Jun 27, 2012 6:29 PM
Edited by: user12152138 on Jun 27, 2012 6:33 PM
Edited by: user12152138 on Jun 27, 2012 6:36 PM
Edited by: user12152138 on Jun 27, 2012 6:37 PM
Edited by: user12152138 on Jun 27, 2012 6:46 PM

Hi together,
I fixed the problem. I multiply the origin number with 10. The result is a number without any comma. During the insert into MSSql I divide by 10.
I now, this is a very strange solution but it works.
Yes I know this helps only, because the column can only save number with one decimal place. For higher decimal places you have to multiple it with 100 or 1000 or......
Hope this helps also other peoples.
kind regards
Joe

Similar Messages

  • SELECT * cannot be used in an INSERT INTO query when the source or destination table contains a multivalued field

    Hi,
    I am using Access 2013 and I have the following VBA code, 
    strSQL = "INSERT INTO Master SELECT * from Master WHERE ID = 1"
     DoCmd.RunSQL (strSQL)
    when the SQL statement is run, I got this error.
    SELECT * cannot be used in an INSERT INTO query when the source or destination table contains a multivalued field
    Any suggestion on how to get around this?
    Please advice and your help would be greatly appreciated!

    Rather than modelling the many-to-many relationship type by means of a multi-valued field, do so by the conventional means of modelling the relationship type by a table which resolves it into two one-to-many relationship types.  You give no indication
    of what is being modelled here, so let's assume a generic model where there is a many-to-many relationship type between Masters and Slaves, for which you'd have the following tables:
    Masters
    ....MasterID  (PK)
    ....Master
    Slaves
    ....SlaveID  (PK)
    ....Slave
    and to model the relationship type:
    SlaveMastership
    ....SlaveID  (FK)
    ....MasterID  (FK)
    The primary key of the last is a composite one of the two foreign keys SlaveID and MasterID.
    You appear to be trying to insert duplicates of a subset of rows from the same table.  With the above structure, to do this you would firstly have to insert rows into the referenced table Masters for all columns bar the key, which, presuming this to be
    an autonumber column, would be assigned new values automatically.  To map these new rows to the same rows in Slaves as the original subset you would then need to insert rows into SlaveMastership with the same SlaveID values as those in Slaves referenced
    by those rows in Slavemastership which referenced the keys of the original subset of rows from Masters, and the MasterID values of the rows inserted in the first insert operation.  This would require joins to be made between the original and the new subsets
    of rows in two instances of Masters on other columns which constitute a candidate key of Masters, so that the rows from SlaveMastership can be identified.
    You'll find examples of these sort of insert operations in DecomposerDemo.zip in my public databases folder at:
    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.
    In this little demo file non-normalized data from Excel is decomposed into a set of normalized tables.  Unlike your situation this does not involve duplication of rows into the same table, but the methodology for the insertion of rows into a table which
    models a many-to-many relationship type is broadly the same.
    The fact that you have this requirement to duplicate a subset of rows into the same table, however, does make me wonder about the validity of the underlying logical model.  I think it would help us if you could describe in detail just what in real world
    terms is being modelled by this table, and the purpose of the insert operation which you are attempting.
    Ken Sheridan, Stafford, England

  • How do I get "#" round dates in an "Insert into " query

    I am trying to use the "Insert Into" type "CFQUERY" and insert a date into a field.This date has been input by the user on a web form using the syntax "<input type="text" name="DateInTheatres"...>
    The query is
    <CFQuery datasource="blah">
    Insert into Films(<other fields>,DateInTheatres)
    values(<other fields>,#CreateODBCDate(Form.DateInTheatres)#)
    </CFQuery>
    The above code does not seem to work because the "#" are not automatically put to the left & right of the date so when the sql resolves you get 12/10/2009 (for example) no quotes, nothing.
    How can I fix this?
    many thanks
    Paul 

    Try something like this:
    <cfquery name="someName" datasource="someDatasource">
    INSERT INTO Films
    (SomeField, DateInTheatres)
    VALUES
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.SomeField#">,
    <cfqueryparam cfsqltype="cf_sql_date" value="#FORM.DateInTheatres#">
    </cfquery>
    Ken Ford

  • Complex insert into query

    I have a table named eps95_contributions:
    emp_code curr_mon due_month contr_amt
    100 200902 201001 400
    100 200903 201001 500
    100 200904 201001 600
    200 200902 201002 200
    200 200903 201002 300
    200 200904 201002 400
    I have another table: year_amt
    I want to insert into this table such that it appears in the following manner:
    emp_code year amt
    100 2009 1500
    200 2009 900
    Please help me with the insert query.
    Edited by: user9027633 on Mar 29, 2010 2:27 AM

    Hi,
    Try This one:
    INSERT INTO year_amt
    (emp_code, year, amt)
    VALUES
    SELECT emp_code,SUBSRT(curr_mon,1,4), SUM(contr_amt) FROM  eps95_contributions
    GROUP BY emp_code,SUBSRT(curr_mon,1,4));

  • Insert into MSSQL from Oracle

    Hello together,
    I'm a little bit frustrated. The follwoing is my problem:
    I want to insert some values from an Oracle 10gR2 database into a MSSQL database (SQL Server 2008 R2).
    Therefor I'm using DG4ODBC 11.2.0.3. The connection is working absolutly fine.
    I want to insert five values from five columns from oracle.table-a into a msssql table-b.
    But I'm hitting the error:
    Invalid character value for cast specification.
    Two columns from the oracle table are chars size 12 and 40, and three are number size 5.1, 5.1 and 4.
    The MSSQL column definitions are varchar40, varchar50, 2x float8 and int.
    The column assignments are:
    Oralce -> MSSQL
    a. char 12 -> varchar40
    b. char 40 -> varchar50
    c. number 5.1 -> float8
    d. number 5.1 -> float8
    e. number 4 -> int4
    The insert works greate for a,b and e but nor for c and d.
    I tried so many solutions (cast, to_binary_float, nls_character_format, nls_theritpory etc..) but nothing helps.
    I always hitting this error.
    Can anyone help me with this problem?
    cheers
    Joe

    Hi together,
    I fixed the problem. I multiply the origin number with 10. The result is a number without any comma. During the insert into MSSql I divide by 10.
    I now, this is a very strange solution but it works.
    Yes I know this helps only, because the column can only save number with one decimal place. For higher decimal places you have to multiple it with 100 or 1000 or......
    Hope this helps also other peoples.
    kind regards
    Joe

  • PHP-MySQL "INSERT INTO" query not working

    Hi,
    The code below fails to update a MySQL table I have made called "tampa."  I'm not sure why.  The field "id" is an index field, auto-increment, and primary-type.  The field "site" is also an index field, but just unique-type.  Does the fact that these two fields are index fields have anything to do with why the code below won't update the table?
    Thanks in advance,
    John
    <form action="process.php" method="post">
    Add a blog to this category: <input name="site" type="text" size="50">
    <input type="submit" value="Submit">
    </form>
    PHP code in a file called "process.php":
    <?
    $site=$_POST['site'];
    mysql_connect("mysqlv3", "username", "password") or die(mysql_error());
    mysql_select_db("sand2") or die(mysql_error());
    mysql_query("INSERT INTO `tampa` ('id', 'site', 'value') VALUES (NULL, '$site',1)");
    $result = mysql_query("INSERT INTO `tampa` ('id', 'site', 'value') VALUES (NULL, '$site',1)");
    ?>

    The reason it fails is because you have surrounded the column names with quotes. You are also running the insert query twice. And yet another problem: you are inserting a form value into the database without filtering it.
    <?php
    mysql_connect("mysqlv3", "username", "password") or die(mysql_error());
    mysql_select_db("sand2") or die(mysql_error());
    // strip slashes if magic quotes are enabled
    $site = get_magic_quotes_gpc() ? stripslashes($_POST['site'] : $_POST['site'];
    // make form value safe to insert in DB
    $site = mysql_real_escape_string($site);
    mysql_query("INSERT INTO `tampa` (id, site, value) VALUES (NULL, '$site',1)");
    ?>

  • Issue inserting into USER_SDO_GEOM_METADATA via Oracle Apex

    G'day All,
    I've originally riased my issue in "Application Express - http://forums.oracle.com/forums/thread.jspa?threadID=537922&tstart=45 " but have not had any solutions provided yet.
    Just a quick summary, when I insert a record into user_sdo_geom_metadata using Oracle Apex SQL Command tool and run a select on the view no records appear. After a bit of investigating I found it is wrongly being given a SDO_OWNER value of ANONYMOUS instead of the value from sys_context('userenv', 'CURRENT_SCHEMA') which in my case would be "TEST".
    When I run SELECT sys_context('userenv', 'CURRENT_SCHEMA') FROM DUAL it correctly returns "TEST".
    If anyone could let me know whats going wrong I would be most appreciated :)
    Cheers
    Mark

    try to
    grant select on table1 to schema2....
    Once you have granted the access to teh schema...you should be able to access the MDSYS schema.
    This should be OK.

  • Create and insert into table from Oracle to MS SQL server.

    Hello,
    Oracle Database 11g and Red hat 5
    I have a very different kind of issue. I am handling the ORACLE db(remote db with all the important data). On the other side their is a MS SQL server db(local db with some testing data in it). All the users will access the ORACLE db for the actual processing but for sometime they need to apply some of their own concepts. So they will transfer the data from ORACLE to MS sql server.
    I want to create a code in ORACLE db like a procedure , which will create a table in MS sql server , insert data into it,Also create some metadata table to keep some of my table's info on MS SQL serve db,If the table is present it should append the data, .... like many things ...
    Overall my question is , how can i write a code to make these operation on a remote db, that to these operations are DDL and on MS SQL Server(Non-Oracle) ???
    Please guide me with some ideas or solutions ...
    Also provide if you have some good links to study ...
    thanks in advance.

    I'm not sure why you never visit http://tahiti.oracle.com prior to asking any question. Is it forbidden in your locale? Are you afraid of it? Will your salary be decreased when you visit the documentation?
    http://www.oracle.com/pls/db111/search?word=sql+server&partno=
    should provide sufficient information.
    Your doc question must be considered a violation of Forum Etiquette and an abuse of this forum.
    Sybrand Bakker
    Senior Oracle DBA

  • Looking data from more than one table and inserting into another.

    Hello,
    I am giving you the Table structures as per my requirement..
    CREATE TABLE TEMP_A
    (NAME VARCHAR2(100) primary key);
    CREATE TABLE TEMP_B
    (STRUCTURE VARCHAR2(10));
    CREATE TABLE TEMP_C
    ( NAME VARCHAR2(100),
    STRUCTURE VARCHAR2(10),
    VALUE VARCHAR2(10));
    Alter table TEMP_C
    add constraint fk_name_tempc foreign key(name) references TEMP_A(name)
    INSERT INTO TEMP_A VALUES('SMITH');
    INSERT INTO TEMP_A VALUES('ALLEN');
    INSERT INTO TEMP_A VALUES('WARD');
    INSERT INTO TEMP_A VALUES('JONES');
    COMMIT;
    INSERT INTO TEMP_B VALUES('IN');
    INSERT INTO TEMP_B VALUES('IN_MIN');
    INSERT INTO TEMP_B VALUES('IN_TYP');
    INSERT INTO TEMP_B VALUES('IN_MAX');
    INSERT INTO TEMP_B VALUES('DIP');
    INSERT INTO TEMP_B VALUES('TIM');
    COMMIT;
    INSERT INTO TEMP_c VALUES('SMITH','C1','');
    INSERT INTO TEMP_c VALUES('SMITH','C2','');
    INSERT INTO TEMP_c VALUES('SMITH','D1','');
    INSERT INTO TEMP_c VALUES('ALLEN','D2','');
    INSERT INTO TEMP_c VALUES('ALLEN','R1','');
    INSERT INTO TEMP_c VALUES('WARD','R2','');
    COMMIT;
    i want to say is it should insert into table 'TEMP_C' values as :
    For 'SMITH' there should be (6 * 3) = 18 records.
    ( 6 distinct values of TEMP_B for SMITH to be inserted into TEMP_C against 'C1')
    ( 6 distinct values of TEMP_B for SMITH to be inserted into TEMP_C against 'C2')
    ( 6 distinct values of TEMP_B for SMITH to be inserted into TEMP_C against 'D1')
    For 'ALLEN' there should be (6 * 2) = 12 records.
    ( 6 distinct values of TEMP_B for ALLEN to be inserted into TEMP_C against 'D2')
    ( 6 distinct values of TEMP_B for ALLEN to be inserted into TEMP_C against 'R1')
    For 'WARD' there should be (6 * 1) = 6 records.
    ( 6 distinct values of TEMP_B for WARD to be inserted into TEMP_C against 'R2')
    Like this if there are records for JONES also , it should also do the same way( Depending on the No. of records present
    in the table 'TEMP_C' for 'JONES').
    Thanks in advance,
    Amkotz

    Is this what you are looking for?
    SQL> insert into temp_c (name, structure, value)
      2  select c.name, c.structure, b.structure
      3  from temp_a a, temp_c c, temp_b b
      4  where a.name = c.name
      5  ;
    36 rows created.
    SQL> select * from temp_c;
    NAME    STRUCTURE  VALUE
    SMITH   C1
    SMITH   C2
    SMITH   D1
    ALLEN   D2
    ALLEN   R1
    WARD    R2
    SMITH   C1         IN
    SMITH   C1         IN_MIN
    SMITH   C1         IN_TYP
    SMITH   C1         IN_MAX
    SMITH   C1         DIP
    SMITH   C1         TIM
    SMITH   C2         IN
    SMITH   C2         IN_MIN
    SMITH   C2         IN_TYP
    SMITH   C2         IN_MAX
    SMITH   C2         DIP
    SMITH   C2         TIM
    SMITH   D1         IN
    SMITH   D1         IN_MIN
    SMITH   D1         IN_TYP
    SMITH   D1         IN_MAX
    SMITH   D1         DIP
    SMITH   D1         TIM
    ALLEN   D2         IN
    ALLEN   D2         IN_MIN
    ALLEN   D2         IN_TYP
    ALLEN   D2         IN_MAX
    ALLEN   D2         DIP
    ALLEN   D2         TIM
    ALLEN   R1         IN
    ALLEN   R1         IN_MIN
    ALLEN   R1         IN_TYP
    ALLEN   R1         IN_MAX
    ALLEN   R1         DIP
    ALLEN   R1         TIM
    WARD    R2         IN
    WARD    R2         IN_MIN
    WARD    R2         IN_TYP
    WARD    R2         IN_MAX
    WARD    R2         DIP
    WARD    R2         TIM
    42 rows selected.
    SQL>

  • Reg: read excel column and insert into table.

    hi Friends,
          i wanted to read the data from Excel and insert into in my oracle tables.
          can you provide the link or example script.
        how to read the column value from excel and insert into table.
      please help.

    < unnecessary reference to personal blog removed by moderator >
    Here are the steps:
    1) First create a directory and grant read , write , execute to the user from where you want to access the flat files and load it.
    2) Write a generic function to load PIPE delimited flat files:
    CREATE OR REPLACE FUNCTION TABLE_LOAD ( p_table in varchar2,
    p_dir in varchar2 DEFAULT ‘YOUR_DIRECTORY_NAME’,
    P_FILENAME in varchar2,
    p_ignore_headerlines IN INTEGER DEFAULT 1,
    p_delimiter in varchar2 default ‘|’,
    p_optional_enclosed in varchar2 default ‘”‘ )
    return number
    is
    – FUNCTION TABLE_LOAD
    – PURPOSE: Load the flat files i.e. only text files to Oracle
    – tables.
    – This is a generic function which can be used for
    – importing any text flat files to oracle database.
    – PARAMETERS:
    – P_TABLE
    – Pass name of the table for which import has to be done.
    – P_DIR
    – Name of the directory where the file is been placed.
    – Note: The grant has to be given for the user to the directory
    – before executing the function
    – P_FILENAME
    – The name of the flat file(a text file)
    – P_IGNORE_HEADERLINES
    – By default we are passing 1 to skip the first line of the file
    – which are headers on the Flat files.
    – P_DELIMITER
    – Dafault “|” pipe is been passed.
    – P_OPTIONAL_ENCLOSED
    – Optionally enclosed by ‘ ” ‘ are been ignored.
    – AUTHOR:
    – Slobaray
    l_input utl_file.file_type;
    l_theCursor integer default dbms_sql.open_cursor;
    l_lastLine varchar2(4000);
    l_cnames varchar2(4000);
    l_bindvars varchar2(4000);
    l_status integer;
    l_cnt number default 0;
    l_rowCount number default 0;
    l_sep char(1) default NULL;
    L_ERRMSG varchar2(4000);
    V_EOF BOOLEAN := false;
    begin
    l_cnt := 1;
    for TAB_COLUMNS in (
    select column_name, data_type from user_tab_columns where table_name=p_table order by column_id
    ) loop
    l_cnames := l_cnames || tab_columns.column_name || ‘,’;
    l_bindvars := l_bindvars || case when tab_columns.data_type in (‘DATE’, ‘TIMESTAMP(6)’) then ‘to_date(:b’ || l_cnt || ‘,”YYYY-MM-DD HH24:MI:SS”),’ else ‘:b’|| l_cnt || ‘,’ end;
    l_cnt := l_cnt + 1;
    end loop;
    l_cnames := rtrim(l_cnames,’,');
    L_BINDVARS := RTRIM(L_BINDVARS,’,');
    L_INPUT := UTL_FILE.FOPEN( P_DIR, P_FILENAME, ‘r’ );
    IF p_ignore_headerlines > 0
    THEN
    BEGIN
    FOR i IN 1 .. p_ignore_headerlines
    LOOP
    UTL_FILE.get_line(l_input, l_lastLine);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_eof := TRUE;
    end;
    END IF;
    if not v_eof then
    dbms_sql.parse( l_theCursor, ‘insert into ‘ || p_table || ‘(‘ || l_cnames || ‘) values (‘ || l_bindvars || ‘)’, dbms_sql.native );
    loop
    begin
    utl_file.get_line( l_input, l_lastLine );
    exception
    when NO_DATA_FOUND then
    exit;
    end;
    if length(l_lastLine) > 0 then
    for i in 1 .. l_cnt-1
    LOOP
    dbms_sql.bind_variable( l_theCursor, ‘:b’||i,
    ltrim(rtrim(rtrim(
    regexp_substr(l_lastLine,’([^|]*)(\||$)’,1,i),p_delimiter),p_optional_enclosed),p_optional_enclosed));
    end loop;
    begin
    l_status := dbms_sql.execute(l_theCursor);
    l_rowCount := l_rowCount + 1;
    exception
    when OTHERS then
    L_ERRMSG := SQLERRM;
    insert into BADLOG ( TABLE_NAME, ERRM, data, ERROR_DATE )
    values ( P_TABLE,l_errmsg, l_lastLine ,systimestamp );
    end;
    end if;
    end loop;
    dbms_sql.close_cursor(l_theCursor);
    utl_file.fclose( l_input );
    commit;
    end if;
    insert into IMPORT_HIST (FILENAME,TABLE_NAME,NUM_OF_REC,IMPORT_DATE)
    values ( P_FILENAME, P_TABLE,l_rowCount,sysdate );
    UTL_FILE.FRENAME(
    P_DIR,
    P_FILENAME,
    P_DIR,
    REPLACE(P_FILENAME,
    ‘.txt’,
    ‘_’ || TO_CHAR(SYSDATE, ‘DD_MON_RRRR_HH24_MI_SS_AM’) || ‘.txt’
    commit;
    RETURN L_ROWCOUNT;
    end TABLE_LOAD;
    Note: when you run the function then it will also modify the source flat file with timestamp , so that we can have the track like which file was loaded .
    3) Check if the user is having UTL_FILE privileges or not :
    SQL> SELECT OWNER,
    OBJECT_TYPE
    FROM ALL_OBJECTS
    WHERE OBJECT_NAME = ‘UTL_FILE’
    AND OWNER =<>;
    If the user is not having the privileges then grant “UTL_FILE” to user from SYS user:
    SQL> GRANT EXECUTE ON UTL_FILE TO <>;
    4) In the function I have used two tables like:
    import_hist table and badlog table to track the history of the load and another to check the bad log if it occurs while doing the load .
    Under the same user create an error log table to log the error out records while doing the import:
    SQL> CREATE TABLE badlog
    errm VARCHAR2(4000),
    data VARCHAR2(4000) ,
    error_date TIMESTAMP
    Under the same user create Load history table to log the details of the file and tables that are imported with a track of records loaded:
    SQL> create table IMPORT_HIST
    FILENAME varchar2(200),
    TABLE_NAME varchar2(200),
    NUM_OF_REC number,
    IMPORT_DATE DATE
    5) Finally run the PLSQL block and check if it is loading properly or not if not then check the badlog:
    Execute the PLSQL block to import the data from the USER:
    SQL> declare
    P_TABLE varchar2(200):=<>;
    P_DIR varchar2(200):=<>;
    P_FILENAME VARCHAR2(200):=<>;
    v_Return NUMBER;
    BEGIN
    v_Return := TABLE_LOAD(
    P_TABLE => P_TABLE,
    P_DIR => P_DIR,
    P_FILENAME => P_FILENAME,
    P_IGNORE_HEADERLINES => P_IGNORE_HEADERLINES,
    P_DELIMITER => P_DELIMITER,
    P_OPTIONAL_ENCLOSED => P_OPTIONAL_ENCLOSED
    DBMS_OUTPUT.PUT_LINE(‘v_Return = ‘ || v_Return);
    end;
    6) Once the PLSQL block is been executed then check for any error log table and also the target table if the records are been successfully imported or not.

  • Insert into oracle DB using vb2005

    I have a form that has click button1. The problem with this code is after insert command something should be inserted into oracle DB but nothing there(so how to execute insert command and commit it using VB2005), any suggestion should refer to the code.
    Imports System
    Imports System.Data ' VB.NET
    Imports Oracle.DataAccess.Client ' ODP.NET Oracle data provider
    Imports Excel = Microsoft.Office.Interop.Excel
    Public Class Form1
    'System.Data.OracleClient lets you access Oracle databases.
    Public con As System.Data.OracleClient.OracleConnection = New System.Data.OracleClient.OracleConnection() 'Oracle.DataAccess.Client.OracleConnection()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim range As Excel.Range
    Dim rCnt As Integer
    Dim cCnt As Integer
    Dim Obj As Object
    xlApp = New Excel.ApplicationClass
    xlApp.Visible = True
    xlWorkBook = xlApp.Workbooks.Open("c:\employee.xls")
    xlWorkSheet = xlWorkBook.Worksheets("sheet1")
    range = xlWorkSheet.UsedRange
    For rCnt = 2 To range.Rows.Count
    For cCnt = 1 To range.Columns.Count
    Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
    'MsgBox(Obj.value)
    Next
    Next
    xlWorkBook.Close()
    xlApp.Quit()
    releaseObject(xlApp)
    releaseObject(xlWorkBook)
    releaseObject(xlWorkSheet)
    End Sub
    Private Sub releaseObject(ByVal obj As Object)
    Try
    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
    obj = Nothing
    Catch ex As Exception
    obj = Nothing
    Finally
    GC.Collect()
    End Try
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim daOracle As New OracleDataAdapter
    Dim InsertCommand As New OracleCommand
    daOracle.InsertCommand = New OracleCommand
    '1.Create connection object to Oracle database
    Dim con As OracleConnection = New OracleConnection()
    Try
    '2.Specify connection string
    con.ConnectionString = ("Data Source=mgra;User Id=tmar; Password=grams")
    '3. Open the connection through ODP.NET
    con.Open()
    Catch ex As Exception
    '4.display if any error occurs
    MsgBox(ex.Message, Microsoft.VisualBasic.MsgBoxStyle.Exclamation, "OraScan")
    '3.Create command object to perform a query against the database:
    Dim cmdQuery As String = "SELECT * FROM employee"
    InsertCommand.CommandText = "insert into meta_objecttypes values(4,'table','table','ERStudio','Demo')"
    daOracle.InsertCommand = InsertCommand
    ' Create the OracleCommand object to work with select
    Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
    cmd.Connection = con
    cmd.CommandType = CommandType.Text
    'get the DataReader object from command object
    Dim rdr As OracleDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    cmd.ExecuteNonQuery()
    'check if it has any row
    While rdr.Read()
    rdr.Close()
    End While
    Finally
    ' Close and Dispose OracleConnection object
    con.Close()
    con.Dispose()
    End Try
    End Sub
    End Class

    For best results, please repost this to the ODP.NET forum.

  • SQL Query produces different results when inserting into a table

    I have an SQL query which produces different results when run as a simple query to when it is run as an INSERT INTO table SELECT ...
    The query is:
    SELECT   mhldr.account_number
    ,        NVL(MAX(DECODE(ap.party_sysid, mhldr.party_sysid,ap.empcat_code,NULL)),'UNKNWN') main_borrower_status
    ,        COUNT(1) num_apps
    FROM     app_parties ap
    SELECT   accsta.account_number
    ,        actply.party_sysid
    ,        RANK() OVER (PARTITION BY actply.table_sysid, actply.loanac_latype_code ORDER BY start_date, SYSID) ranking
    FROM     activity_players actply
    ,        account_status accsta
    WHERE    1 = 1
    AND      actply.table_id (+) = 'ACCGRP'
    AND      actply.acttyp_code (+) = 'MHLDRM'
    AND      NVL(actply.loanac_latype_code (+),TO_NUMBER(SUBSTR(accsta.account_number,9,2))) = TO_NUMBER(SUBSTR(accsta.account_number,9,2))
    AND      actply.table_sysid (+) = TO_NUMBER(SUBSTR(accsta.account_number,1,8))
    ) mhldr
    WHERE    1 = 1
    AND      ap.lenapp_account_number (+) = TO_NUMBER(SUBSTR(mhldr.account_number,1,8))
    GROUP BY mhldr.account_number;      The INSERT INTO code:
    TRUNCATE TABLE applicant_summary;
    INSERT /*+ APPEND */
    INTO     applicant_summary
    (  account_number
    ,  main_borrower_status
    ,  num_apps
    SELECT   mhldr.account_number
    ,        NVL(MAX(DECODE(ap.party_sysid, mhldr.party_sysid,ap.empcat_code,NULL)),'UNKNWN') main_borrower_status
    ,        COUNT(1) num_apps
    FROM     app_parties ap
    SELECT   accsta.account_number
    ,        actply.party_sysid
    ,        RANK() OVER (PARTITION BY actply.table_sysid, actply.loanac_latype_code ORDER BY start_date, SYSID) ranking
    FROM     activity_players actply
    ,        account_status accsta
    WHERE    1 = 1
    AND      actply.table_id (+) = 'ACCGRP'
    AND      actply.acttyp_code (+) = 'MHLDRM'
    AND      NVL(actply.loanac_latype_code (+),TO_NUMBER(SUBSTR(accsta.account_number,9,2))) = TO_NUMBER(SUBSTR(accsta.account_number,9,2))
    AND      actply.table_sysid (+) = TO_NUMBER(SUBSTR(accsta.account_number,1,8))
    ) mhldr
    WHERE    1 = 1
    AND      ap.lenapp_account_number (+) = TO_NUMBER(SUBSTR(mhldr.account_number,1,8))
    GROUP BY mhldr.account_number;      When run as a query, this code consistently returns 2 for the num_apps field (for a certain group of accounts), but when run as an INSERT INTO command, the num_apps field is logged as 1. I have secured the tables used within the query to ensure that nothing is changing the data in the underlying tables.
    If I run the query as a cursor for loop with an insert into the applicant_summary table within the loop, I get the same results in the table as I get when I run as a stand alone query.
    I would appreciate any suggestions for what could be causing this odd behaviour.
    Cheers,
    Steve
    Oracle database details:
    Oracle Database 10g Release 10.2.0.2.0 - Production
    PL/SQL Release 10.2.0.2.0 - Production
    CORE 10.2.0.2.0 Production
    TNS for 32-bit Windows: Version 10.2.0.2.0 - Production
    NLSRTL Version 10.2.0.2.0 - Production
    Edited by: stevensutcliffe on Oct 10, 2008 5:26 AM
    Edited by: stevensutcliffe on Oct 10, 2008 5:27 AM

    stevensutcliffe wrote:
    Yes, using COUNT(*) gives the same result as COUNT(1).
    I have found another example of this kind of behaviour:
    Running the following INSERT statements produce different values for the total_amount_invested and num_records fields. It appears that adding the additional aggregation (MAX(amount_invested)) is causing problems with the other aggregated values.
    Again, I have ensured that the source data and destination tables are not being accessed / changed by any other processes or users. Is this potentially a bug in Oracle?Just as a side note, these are not INSERT statements but CTAS statements.
    The only non-bug explanation for this behaviour would be a potential query rewrite happening only under particular circumstances (but not always) in the lower integrity modes "trusted" or "stale_tolerated". So if you're not aware of any corresponding materialized views, your QUERY_REWRITE_INTEGRITY parameter is set to the default of "enforced" and your explain plan doesn't show any "MAT_VIEW REWRITE ACCESS" lines, I would consider this as a bug.
    Since you're running on 10.2.0.2 it's not unlikely that you hit one of the various "wrong result" bugs that exist(ed) in Oracle. I'm aware of a particular one I've hit in 10.2.0.2 when performing a parallel NESTED LOOP ANTI operation which returned wrong results, but only in parallel execution. Serial execution was showing the correct results.
    If you're performing parallel ddl/dml/query operations, try to do the same in serial execution to check if it is related to the parallel feature.
    You could also test if omitting the "APPEND" hint changes anything but still these are just workarounds for a buggy behaviour.
    I suggest to consider installing the latest patch set 10.2.0.4 but this requires thorough testing because there were (more or less) subtle changes/bugs introduced with [10.2.0.3|http://oracle-randolf.blogspot.com/2008/02/nasty-bug-introduced-with-patch-set.html] and [10.2.0.4|http://oracle-randolf.blogspot.com/2008/04/overview-of-new-and-changed-features-in.html].
    You could also open a SR with Oracle and clarify if there is already a one-off patch available for your 10.2.0.2 platform release. If not it's quite unlikely that you are going to get a backport for 10.2.0.2.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Urgent! How to insert into and query video from database in forms???

    In forms 6i demos CD, There is a demo form ocxvideo.fmb,
    but it just for video in file system.
    I want to read *.avi file from file system, and insert into
    database, and query from my forms.
    I create table with long raw, with default forms wizard,
    long raw for [image] item in forms.
    I change item type to ActiveX ,and right_click mouse
    ==>[Insert object]==>Oracle Veideo control.
    still can not insert avi data into database and query from my forms.
    Please give me some advice to solve this problem?
    Thank you very much!
    Ming-An
    [email protected]

    In forms 6i demos CD, There is a demo form ocxvideo.fmb,
    but it just for video in file system.
    I want to read *.avi file from file system, and insert into
    database, and query from my forms.
    I create table with long raw, with default forms wizard,
    long raw for [image] item in forms.
    I change item type to ActiveX ,and right_click mouse
    ==>[Insert object]==>Oracle Veideo control.
    still can not insert avi data into database and query from my forms.
    Please give me some advice to solve this problem?
    Thank you very much!
    Ming-An
    [email protected]

  • How to Select from Oracle 8i database and insert into Sql Server 2005 datab

    Hi how to Select from Oracle 8i and insert into Sql Server 2005.
    Source db as Oracle 8i
    Target db as Sql Server 2005.
    I need to select one table data from Oracle 8i & insert into Sql Server 2005
    Thanks

    Thanks Khan..
    Is there is any query (OPENQUERY) available for that?
    Regards..

  • Unable to insert into oracle db using times ten

    I have a times ten 6.0 installation on my m/c connected to an oracle 10.2.0.2 database. The database is a remote database. My application is deployed to oracle application server (10.1.3.1 SOA). I am getting the following SQLException when I try to insert.the first row.
    java.sql.SQLException: [TimesTen][TimesTen 6.0.4 ODBC Driver][TimesTen]TT5105: OCI initialization failed. -- file "bdbEnv.c", lineno 275, procedure "ttBDbEnvAlloc"
    My env is as follows
    OS = Windows 2000
    DataSource = User DSN
    First Connection
    Permanent Data Store = 100
    Temporary Data Store = 50
    Connections = 20
    Synchronous write through cache
    I tried a select on the table before insert and it worked. Using ttisql I can insert into this table without any problem. Using a standalone java program I am able to insert data into this table. But from within an appserver I am facing this issue.
    Thanks in advance for any help.
    Regards,
    Mahesh.

    Jimmyb,
    Are you logged in as the user that owns that table?
    Yes.
    If yes, then there are no triggers on this table.
    That is true.
    You will need to populate the ID column with your insert statement.
    Just did that.
    Usually, the sequence is very similar to the table name.
    Yes I tried few of them in my sql query and it said "sequence cannot be found"
    Isn't there some way that it will list the name of the sequence currently being used in a table?

Maybe you are looking for

  • Crystal Report not taking parameter propery

    Hi, I am facing a unique issue in reports.The report is not taking the parameter entered by the user instead it is taking the value which was used for testing the report initially. Save data with report in uncheked. The report is shwing correct data

  • Adobe 6 professional Versus Adobe 8 professional

    I work in the insurance field and it seems to be an issue where an Adobe 6 .pdf file is opened with Adobe 8 professional the formatting seems to be different.  Is there away not to have that changed so it will not change automatically?

  • Encore won't encode some PSD files in Flash

    I have succesfully completed a DVD project on Encore (4.0)  with mpg elements edited in Premier Pro (4.0). A number of slide sequences constructed from jpgs converted to pds files in Photoshop (cs5) have been used, plus some (individual, single) text

  • BI Statistics

    Hi Im trying to activate the Technical Content Process Chain in BI Statistics. 0TCT_MD_C_FULL_P01 - Content Master Data 0TCT_C2_INIT_P01 - Data Load Statistics - Init 0TCT_C2_DELTA_P01 - Data Load Statistics – Delta 0TCT_STATISTIC_DELTA_LOAD - Load S

  • WAAS 4.1

    I was wondering if anyone knew if the new WAAS software version 4.1 gets rid of the idea of connectivity groups and having to identify a WAE as a core, or edge rather than it operating as either without extra confgiuration? I have tried looking in th