Inserting from .txt to table

Hi all,
I am trying to insert from text file into the table using the following pl/sql procedure
everything is working on fine but the table into which i want to insert is not reflecting...
SQL> create or replace procedure loademployee(
2 p_filedir in varchar2,
3 p_filename in varchar2) as
4 v_filehandle UTL_FILE.FILE_TYPE;
5 v_newline varchar2(500);
6 --Input line
7
8 v_First_name emp1.first_name%TYPE;
9 v_last_name emp1.last_name%TYPE;
10 begin
11 v_filehandle:=UTL_FILE.FOPEN(p_filedir,p_filename,'r');
12
13 insert into emp1(first_name,last_name) values(v_first_name,v_last_name);
14 UTL_FILE.FCLOSE(v_filehandle);
15 COMMIT;
16 EXCEPTION
17 WHEN UTL_FILE.INVALID_OPERATION THEN
18 UTL_FILE.FCLOSE(V_FILEHANDLE);
19 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
20 UTL_FILE.FCLOSE(V_FILEHANDLE);
21 RAISE_APPLICATION_ERROR(-20052,'LOADemployee:INVALID FILE HANDLE');
22 WHEN UTL_FILE.READ_ERROR THEN
23 UTL_FILE.FCLOSE(V_FILEHANDLE);
24 RAISE_APPLICATION_ERROR(-20053,'loademployee:READ ERROR');
25 WHEN OTHERS THEN
26 DBMS_OUTPUT.PUT_LINE('ERROR OCCURED ' || SQLCODE || ' ' || SQLERRM);
27
28 UTL_FILE.FCLOSE(V_FILEHANDLE);
29 END LOADemployee;
30 /
Procedure created.
SQL> DECLARE
2 P_FILEDIR VARCHAR2(200);
3 P_FILENAME VARCHAR2(200);
4
5 BEGIN
6 P_FILEDIR := 'c:\Temp\UTL_FILE';
7 P_FILENAME := 'test.txt';
8
9 SCOTT.LOADEMPLOYEE ( P_FILEDIR, P_FILENAME );
10 END;
11 /
PL/SQL procedure successfully completed.
SQL> select * from emp1;
no rows selected

Pratik.L wrote:
i just went through the content is the following line used to write text from the content file to the tables into the database
v_filehandle:=UTL_FILE.fopen(p_filedir, p_filename, 'W');
Thanks & Regards
Pratik LakhpatwalaNo, that simply opens the file in the selected mode. It doesn't read or write anything. And your selected mode is "W", which means you are opening the file with the intent of writing to the file, not reading from it. Better go back and read the docs again.
And as pointed out, you'd be better off using this file as an external table.

Similar Messages

  • Bulk copy from a temp table

    My input is from a file. Since I do not have an ETL tool, I am using a stored proc to do the ETL (which also gives me an advantage, I do not have to unload the target table to do the join). So, I dump the file contents into a temp table and use it in proc.
    The query is like
    Insert into <target table1> (Select fields and some transformation from <temp table> where <key> not in target table and <some joins with other tables in database>
    Like this I have four queries for four target tables.
    The inserts from the temp table into the target table is very slow because the target has a lot of index and RI. I cannot drop & create the index since the application requirements does not give me that liberty.
    My only option is to insert in a temp table similar to the target but without any index/RI/PK and then dump it into a file and then use SQL loader to load the file contents into target table. This is relatively faster but is a very cumbersome route to me.
    Is there any other way to do bulk insert from one table to another table like SQL loader without using a file? Is there anyway to bypass the index update operation without dropping the index?
    My source will be almost 500,000 rows and target is having 9 million rows.

    Posts like this one are better avoided.
    Because
    - You don't post a version
    - You don't post the SQL
    - You don't post the EXPLAIN PLAN
    It is your assertion the INSERT is to blame, yet it can equally be the SELECT statement involved.
    Basically your post boils down to
    'It doesn't work. Please help', without any relevant information.
    I'm saying this because INSERT SELECT is the fastest method available. OK, you could try the APPEND hint, but in that case you would have to rebuild all indices. Something you state you can not do.
    BULK INSERTs will be slower, SQL*Loader will be slower too, as it involves SQLnet. INSERT SELECT is a server side operation.
    And the 'solution' to do this by means of a file... Ahem, let's not talk about it. It just doesn't work.
    Sybrand Bakker
    Senior Oracle DBA

  • Insert Data into Table from TXT or CSV file !!!!!

    Dear All,
    Recently I have started working on APEX. In Oracle Forms, we used to use TEXT_IO for inserting records into tables from txt files. Now I want to do the same thing in apex 3.2. How can I insert data into tables from txt of csv files.
    Waiting of your valuable suggestions.
    With kind regards,
    Yousuf.

    Yousuf
    wwv_flow_files is used by APEX to hold uploaded files.
    If you incorporate a file browse item on you page, browse for the selected file, then submit the page (having the PL/SQL process described as an on suibmit process) then what I detailed should work.
    If you don't need users to have access to this then just go to Home>Utilities>Data Load/Unload in APEX and there is a handy load utility there that does it all for you.
    Cheers
    Ben

  • How to convert from SQL Server table to Flat file (txt file)

    I need To ask question how convert from SQL Server table to Flat file txt file

    Hi
    1. Import/Export wizened
    2. Bcp utility
    3. SSIS 
    1.Import/Export Wizard
    First and very manual technique is the import wizard.  This is great for ad-hoc and just to slam it in tasks.
    In SSMS right click the database you want to import into.  Scroll to Tasks and select Import Data…
    For the data source we want out zips.txt file.  Browse for it and select it.  You should notice the wizard tries to fill in the blanks for you.  One key thing here with this file I picked is there are “ “ qualifiers.  So we need to make
    sure we add “ into the text qualifier field.   The wizard will not do this for you.
    Go through the remaining pages to view everything.  No further changes should be needed though
    Hit next after checking the pages out and select your destination.  This in our case will be DBA.dbo.zips.
    Following the destination step, go into the edit mappings section to ensure we look good on the types and counts.
    Hit next and then finish.  Once completed you will see the count of rows transferred and the success or failure rate
    Import wizard completed and you have the data!
    bcp utility
    Method two is bcp with a format file http://msdn.microsoft.com/en-us/library/ms162802.aspx
    This is probably going to win for speed on most occasions but is limited to the formatting of the file being imported.  For this file it actually works well with a small format file to show the contents and mappings to SQL Server.
    To create a format file all we really need is the type and the count of columns for the most basic files.  In our case the qualifier makes it a bit difficult but there is a trick to ignoring them.  The trick is to basically throw a field into the
    format file that will reference it but basically ignore it in the import process.
    Given that our format file in this case would appear like this
    9.0
    9
    1 SQLCHAR 0 0 """ 0 dummy1 ""
    2 SQLCHAR 0 50 "","" 1 Field1 ""
    3 SQLCHAR 0 50 "","" 2 Field2 ""
    4 SQLCHAR 0 50 "","" 3 Field3 ""
    5 SQLCHAR 0 50 ""," 4 Field4 ""
    6 SQLCHAR 0 50 "," 5 Field5 ""
    7 SQLCHAR 0 50 "," 6 Field6 ""
    8 SQLCHAR 0 50 "," 7 Field7 ""
    9 SQLCHAR 0 50 "n" 8 Field8 ""
    The bcp call would be as follows
    C:Program FilesMicrosoft SQL Server90ToolsBinn>bcp DBA..zips in “C:zips.txt” -f “c:zip_format_file.txt” -S LKFW0133 -T
    Given a successful run you should see this in command prompt after executing the statement
    Starting copy...
    1000 rows sent to SQL Server. Total sent: 1000
    1000 rows sent to SQL Server. Total sent: 2000
    1000 rows sent to SQL Server. Total sent: 3000
    1000 rows sent to SQL Server. Total sent: 4000
    1000 rows sent to SQL Server. Total sent: 5000
    1000 rows sent to SQL Server. Total sent: 6000
    1000 rows sent to SQL Server. Total sent: 7000
    1000 rows sent to SQL Server. Total sent: 8000
    1000 rows sent to SQL Server. Total sent: 9000
    1000 rows sent to SQL Server. Total sent: 10000
    1000 rows sent to SQL Server. Total sent: 11000
    1000 rows sent to SQL Server. Total sent: 12000
    1000 rows sent to SQL Server. Total sent: 13000
    1000 rows sent to SQL Server. Total sent: 14000
    1000 rows sent to SQL Server. Total sent: 15000
    1000 rows sent to SQL Server. Total sent: 16000
    1000 rows sent to SQL Server. Total sent: 17000
    1000 rows sent to SQL Server. Total sent: 18000
    1000 rows sent to SQL Server. Total sent: 19000
    1000 rows sent to SQL Server. Total sent: 20000
    1000 rows sent to SQL Server. Total sent: 21000
    1000 rows sent to SQL Server. Total sent: 22000
    1000 rows sent to SQL Server. Total sent: 23000
    1000 rows sent to SQL Server. Total sent: 24000
    1000 rows sent to SQL Server. Total sent: 25000
    1000 rows sent to SQL Server. Total sent: 26000
    1000 rows sent to SQL Server. Total sent: 27000
    1000 rows sent to SQL Server. Total sent: 28000
    1000 rows sent to SQL Server. Total sent: 29000
    bcp import completed!
    BULK INSERT
    Next, we have BULK INSERT given the same format file from bcp
    CREATE TABLE zips (
    Col1 nvarchar(50),
    Col2 nvarchar(50),
    Col3 nvarchar(50),
    Col4 nvarchar(50),
    Col5 nvarchar(50),
    Col6 nvarchar(50),
    Col7 nvarchar(50),
    Col8 nvarchar(50)
    GO
    INSERT INTO zips
    SELECT *
    FROM OPENROWSET(BULK 'C:Documents and SettingstkruegerMy Documentsblogcenzuszipcodeszips.txt',
    FORMATFILE='C:Documents and SettingstkruegerMy Documentsblogzip_format_file.txt'
    ) as t1 ;
    GO
    That was simple enough given the work on the format file that we already did.  Bulk insert isn’t as fast as bcp but gives you some freedom from within TSQL and SSMS to add functionality to the import.
    SSIS
    Next is my favorite playground in SSIS
    We can do many methods in SSIS to get data from point A, to point B.  I’ll show you data flow task and the SSIS version of BULK INSERT
    First create a new integrated services project.
    Create a new flat file connection by right clicking the connection managers area.  This will be used in both methods
    Bulk insert
    You can use format file here as well which is beneficial to moving methods around.  This essentially is calling the same processes with format file usage.  Drag over a bulk insert task and double click it to go into the editor.
    Fill in the information starting with connection.  This will populate much as the wizard did.
    Example of format file usage
    Or specify your own details
    Execute this and again, we have some data
    Data Flow method
    Bring over a data flow task and double click it to go into the data flow tab.
    Bring over a flat file source and SQL Server destination.  Edit the flat file source to use the connection manager “The file” we already created.  Connect the two once they are there
    Double click the SQL Server Destination task to open the editor.  Enter in the connection manager information and select the table to import into.
    Go into the mappings and connect the dots per say
    Typical issue of type conversions is Unicode to non-unicode.
    We fix this with a Data conversion or explicit conversion in the editor.  Data conversion tasks are usually the route I take.  Drag over a data conversation task and place it between the connection from the flat file source to the SQL Server destination.
    New look in the mappings
    And after execution…
    SqlBulkCopy Method
    Sense we’re in the SSIS package we can use that awesome “script task” to show SlqBulkCopy.  Not only fast but also handy for those really “unique” file formats we receive so often
    Bring over a script task into the control flow
    Double click the task and go to the script page.  Click the Design script to open up the code behind
    Ref.
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • Insert /delete data from SAP Z table to Oracle table and opposite

    Hi,
    Can u help me write this FM from the SAP side?
    So, I have two tables ZTABLE in SAP and Oracle table ORAC.
    Let's put three columns in each of them, for example
    TEL1
    TEL2
    ADRESS
    NAME
    where TEL field is primary from ZTABLE to ORAC...
    (in FM there shoud be abap code for writing data in ZTABLE after we press some pushbutton made in sap screen painter..)
    for example, when we write new record in ZTABLE
    00
    112233
    Street 4
    Name1
    this data shoud be inserted in Oracle table ORAC.
    when we write new record in Oracle table for example
    01
    445566
    New Street
    Name2
    this data shoud be inserted in ZTABLE.
    Field TEL1 can be only of two values 01 or 02, other combination is not valid...
    I must have all data from Oracle table ORAC in ZTABLE and opposite.
    It should be the same scenario for DELETE...
    And this communication should be online between sap and table in oracle database...
    Can u help me from sap side? and give idea how to configure on oracle side??
    Thanks a lot,
    Nihad

    I dont know if we can directly connect to a oracle database ( wait for the answers from others on this )
    but in XI we have the JDBC adaptor to insert and retrieve data.
    so for the outbound from SAP the flow can be something like this (with XI in landscape):
    1) You have a screen to maintain a new entry / delete an entry
    2) On save , this record gets saved or deleted from the Ztable in SAP
    3)) In the same screen you can call a proxy class-method (generated using SPROXY transaction ) to send the record to XI.
    4) XI to format it and insert into the oracle table
    Mathews

  • Insert statement does not insert all records from a partitioned table

    Hi
    I need to insert records in to a table from a partitioned table.I set up a job and to my surprise i found that the insert statement is not inserting all the records on the partitioned table.
    for example when i am using select statement on to a partitioned table
    it gives me 400 records but when i insert it gives me only 100 records.
    can anyone help in this matter.

    INSERT INTO TABLENAME(COLUMNS)
    (SELECT *
    FROM SCHEMA1.TABLENAME1
    JOIN SCHEMA2.TABLENAME2a
    ON CONDITION
    JOIN SCHEMA2.TABLENAME2 b
    ON CONDITION AND CONDITION
    WHERE CONDITION
    AND CONDITION
    AND CONDITION
    AND CONDITION
    AND (CONDITION
    HAVING SUM(COLUMN) > 0
    GROUP BY COLUMNS

  • How to insert data into a table from an xml document

    using the XmlSql Utility, how do I insert data into a table from an xml document, using the sqlplus prompt.
    if i use the xmlgen.insertXML(....)
    requires a CLOB file, which i dont have, only the xml doc.
    Cant i insert directly from the doc to the table?
    the xmlgen examples I have seen first convert a table to a CLOB xmlString and then insert it into another table.
    Isnt there any other way?

    Your question is little perplexing.
    If you're using XML SQL Utility from
    the commandline, just use putXML.
    java OracleXML putXML
    null

  • Insert records from a single table to two related tables

    DB - 10G
    OS - XP
    We have many thousands of comma delimited records that we want to insert into a normalised table structure.
    I have created a test dataset that can be found at the end of this post.
    I have csv records that look like this;
    donald, huey
    donald, dewey
    donald, louie
    And I want the data to be inserted into two separate table like this;
    table named PARENTS
    pk parent_name
    1  donald
    Table named CHILDRENS
    pk fk child_name
    1  1 huey
    1  2 dewey
    1  3 louie
    I constructed an insert statement that looks like this;
    INSERT ALL
      INTO parents (parent_id, parent_name) VALUES (parents_seq.nextval, parent_name)
      INTO children (children_id, parent_id, child_name) VALUES(children_seq.nextval, parents_seq.nextval, child_name )
    SELECT parent_name, child_name
      FROM sources;
    And this resulted in the following;
    Table named PARENTS
    pk child_name
    1  DONALD
    2  DONALD
    3  DONALD
    Table named PARENTS
    pk fk child_name
    1  1  HUEY
    2  2  DEWEY
    3  3  LOUIE
    Would anyone have any ideas on how I could accomplish this task?
    This is some example data;
    [code]
    DROP SEQUENCE parents_seq;
    DROP SEQUENCE sources_seq;
    DROP SEQUENCE children_seq;
    DROP TABLE sources;
    DROP TABLE children;
    DROP TABLE parents;
    CREATE SEQUENCE PARENTS_SEQ MINVALUE 1 MAXVALUE 1000000000000000000000000000 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE;
    CREATE TABLE PARENTS
    ( PARENT_ID      NUMBER(8) NOT NULL
    , PARENT_NAME    VARCHAR2 (50 CHAR) NOT NULL
    , CONSTRAINT     PARENTS_PK PRIMARY KEY (PARENT_ID)
    create or replace
    TRIGGER PARENTS_BI
    BEFORE
      INSERT OR UPDATE ON PARENTS
      FOR EACH ROW BEGIN
      IF INSERTING THEN
        IF :NEW.PARENT_ID IS NULL THEN
          SELECT PARENTS_SEQ.nextval INTO :NEW.PARENT_ID FROM dual;
        END IF;
      END IF;
    END;
    CREATE SEQUENCE SOURCES_SEQ MINVALUE 1 MAXVALUE 1000000000000000000000000000 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE;
    CREATE TABLE SOURCES
    ( SOURCE_ID      NUMBER(8) NOT NULL
    , PARENT_NAME    VARCHAR2 (50 CHAR) NOT NULL
    , CHILD_NAME    VARCHAR2 (50 CHAR) NOT NULL
    , CONSTRAINT     SOURCES_PK PRIMARY KEY (SOURCE_ID)
    create or replace
    TRIGGER SOURCES_BI
    BEFORE
      INSERT OR UPDATE ON SOURCES
      FOR EACH ROW BEGIN
      IF INSERTING THEN
        IF :NEW.SOURCE_ID IS NULL THEN
          SELECT SOURCES_SEQ.nextval INTO :NEW.SOURCE_ID FROM dual;
        END IF;
      END IF;
    END;
    INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'HUEY');
    INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'DEWEY');
    INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'LOUIE');
    Commit;
    CREATE SEQUENCE CHILDREN_SEQ MINVALUE 1 MAXVALUE 1000000000000000000000000000 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE;
    PROMPT *** CREATE TABLE ***
    CREATE TABLE CHILDREN
    ( CHILDREN_ID    NUMBER NOT NULL
    , PARENT_ID      NUMBER NOT NULL
    , CHILD_NAME     VARCHAR2 (50 CHAR) NOT NULL
    , CONSTRAINT     CHILDREN_PK PRIMARY KEY (CHILDREN_ID)
    create or replace
    TRIGGER CHILDREN_BI
    BEFORE
      INSERT OR UPDATE ON CHILDREN
      FOR EACH ROW BEGIN
      IF INSERTING THEN
        IF :NEW.CHILDREN_ID IS NULL THEN
          SELECT CHILDREN_SEQ.nextval INTO :NEW.CHILDREN_ID FROM dual;
        END IF;
      END IF;
    END;
    [code]

    Looks like this is one way of achieving it:
    insert into parents (parent_name) select distinct parent_name from sources;
    select *
      from parents;
    PARENT_ID              PARENT_NAME                                       
    1                      DONALD
    insert into children (parent_id, child_name)
    select p.parent_id, s.child_name
      from sources s
      join parents p
        on (s.parent_name = p.parent_name);
    select *
      from children;
    CHILDREN_ID            PARENT_ID              CHILD_NAME                                        
    1                      1                      HUEY                                              
    2                      1                      DEWEY                                             
    3                      1                      LOUIE

  • How to Insert 3 Column details in a single table from the parent table.

    From the Parent Table i need to insert rows which are all under this column {(TradeIn_1_VIN),(TradeIn_2_VIN),(TradeIn_3_VIN) } into SALES_TRADEIN Table .
    I have used the below Query,
    But it reads only (TradeIn _1_Vin) Column in the SALES_TRADEIN table rest 2 records got skipped..
    INSERT INTO SALES_TRADEIN
    SalesID,
    TradeIn_VIN,
    TradeIn_Make,
    TradeIn_Model,
    TradeIn_ExteriorColor,
    TradeIn_Year,
    TradeIn_Mileage,
    TradeIn_Gross,
    TradeIn_Payoff,
    TradeIn_ACV,
    TradeIn_InteriorColor
    VALUES
    @SalesID,
    case when @TradeIn_1_VIN is null then @TradeIn_2_VIN else @TradeIn_1_VIN end,
    case when @TradeIn_1_Make is null then @TradeIn_2_Make else @TradeIn_1_Make end,
    case when @TradeIn_1_Model is null then @TradeIn_2_Model else @TradeIn_1_Model end,
    case when @TradeIn_1_ExteriorColor is null then @TradeIn_2_ExteriorColor else @TradeIn_1_ExteriorColor end,
    case when @TradeIn_1_Year is null then @TradeIn_2_Year else @TradeIn_1_Year end,
    case when @TradeIn_1_Mileage is null then @TradeIn_2_Mileage else @TradeIn_1_Mileage end,
    case when @TradeIn_1_Gross is null then @TradeIn_2_Gross else @TradeIn_1_Gross end,
    case when @TradeIn_1_Payoff is null then @TradeIn_2_Payoff else @TradeIn_1_Payoff end,
    case when @TradeIn_1_ACV is null then @TradeIn_2_ACV else @TradeIn_1_ACV end,
    case when @TradeIn_1_InteriorColor is null then @TradeIn_2_InteriorColor else @TradeIn_1_InteriorColor end
    END TRY
    Actually my problem is
     If  [(TradeIn_1_VIN),(TradeIn_2_VIN),(TradeIn_3_VIN)] these 3 columns have details i need all the 3 columns  details need to be read to SALES_TRADEIN table.
    Suppose if we have data only in [(TradeIn_1_VIN),(TradeIn_2_VIN)] then these column details need to loaded in the SALES_TRADEIN table.
    If any columns are blank no problem it can move next process.
    Please help me change those particular lines to insert all the 3 records  (TradeIn_1_VIN) (TradeIn_2_VIN) (TradeIn_3_VIN) in to the table.

    you've not given us the full info about the tables. The posted code also makes not much sense to me as all I can see are values getting inserted from some variables which is not required here as your values come from a table and variables can handle only
    one set of values a time which would require unnecessary iteration logic.
    I think what you need is something like below
    INSERT INTO SALES_TRADEIN
    SalesID,
    TradeIn_VIN,
    TradeIn_Make,
    TradeIn_Model,
    TradeIn_ExteriorColor,
    TradeIn_Year,
    TradeIn_Mileage,
    TradeIn_Gross,
    TradeIn_Payoff,
    TradeIn_ACV,
    TradeIn_InteriorColor
    SELECT t.TradeIn_VIN,
    t.TradeIn_Make,
    t.TradeIn_Model,
    t.TradeIn_ExteriorColor,
    t.TradeIn_Year,
    t.TradeIn_Mileage,
    t.TradeIn_Gross,
    t.TradeIn_Payoff,
    t.TradeIn_ACV,
    t.TradeIn_InteriorColor
    FROM Parent p
    CROSS APPLY (VALUES
    (TradeIn_1_VIN,
    TradeIn_1_Make,
    TradeIn_1_Model,
    TradeIn_1_ExteriorColor,
    TradeIn_1_Year,
    TradeIn_1_Mileage,
    TradeIn_1_Gross,
    TradeIn_1_Payoff,
    TradeIn_1_ACV,
    TradeIn_1_InteriorColor),
    (TradeIn_2_VIN,
    TradeIn_2_Make,
    TradeIn_2_Model,
    TradeIn_2_ExteriorColor,
    TradeIn_2_Year,
    TradeIn_2_Mileage,
    TradeIn_2_Gross,
    TradeIn_2_Payoff,
    TradeIn_2_ACV,
    TradeIn_2_InteriorColor),
    (TradeIn_3_VIN,
    TradeIn_3_Make,
    TradeIn_3_Model,
    TradeIn_3_ExteriorColor,
    TradeIn_3_Year,
    TradeIn_3_Mileage,
    TradeIn_3_Gross,
    TradeIn_3_Payoff,
    TradeIn_3_ACV,
    TradeIn_3_InteriorColor)
    )t(TradeIn_VIN,
    TradeIn_Make,
    TradeIn_Model,
    TradeIn_ExteriorColor,
    TradeIn_Year,
    TradeIn_Mileage,
    TradeIn_Gross,
    TradeIn_Payoff,
    TradeIn_ACV,
    TradeIn_InteriorColor)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to insert  data from different internal  table  into a data base table

    hi all,
             I want to insert a particular field in an internal table to a field in a data base table.Note that the fields in the internal table and database table are not of the same name since i need to insert data from different internal tables.can some one tell me how to do this?
    in short i want to do something like the foll:
    INSERT  INTO ZMIS_CODES-CODE VALUE '1'.
    *INSERT INTO ZMIS_CODES-COL1 VALUE DATA_MTD-AUFNR .(zmis_codes is the db table and data_mtd is the int.table)

    REPORT  ZINSERT.
    tables kna1.
    data: itab LIKE KNA1.
    data lv_kUNAG LIKE KNA1-KUNNR.
    lv_kuNAG =  '0000010223'.
    ITAB-kuNNR = lv_kuNAG.
    ITAB-name1 = 'XYZ'.
    INSERT INTO KNA1 VALUES ITAB.
    IF SY-SUBRC = 0.
    WRITE:/ 'SUCCESS'.
    ELSE.
    WRITE:/ 'FAILED'.
    ENDIF.
    Here lv_kunag is ref to kna1 kunnr passed in different name
    In internal table .
    Try and let me know if this logic dint work.

  • How can i open a DOC or TXT file and insert the data into table?

    How can i open a DOC or TXT file and insert the data into table?
    I have a doc file . the doc include some columns and some rows.(for example 'ID,Name,Date,...').
    I'd like open DOC file and I'd like insert them into the table with same columns.
    Thanks.

    Use the SQL*Loader utility or the UTL_FILE package.

  • How do I run a database procedure that inserts data into a table from withi

    How do I run a database procedure that inserts data into a table from within a Crystal report?
    I'm using CR 2008 with an Oracle 10i database containing a number of database tables, procedures and packages that provide the data for the reports I'm developing for my department.  However, I'd like to know when a particular report is run and by whom.  To do this I have created a database table called Report_Log and an associated procedure called prc_Insert_Entry that inserts a new line in the table each time it's called.  The procedure has 2 imput parameters (Report_Name & Username), the report name is just text and I'd like the username to be the account name of the person logged onto the PC.  How can I call this procedure from within a report when it's run and provide it with the 2 parameters?  I know the procedure works, I just can't figure out how to call it from with a report.
    I'd be grateful for any help.
    Colin

    Hi Colin, 
    Just so I'm clear about what you want: 
    You have a Stored procedure in your report.  When the report runs, you want that same procedure to write to a table called Report_Log. 
    If this is what you want the simple answer is cannot be done.  Crystal's fundamental prupose is to read only, not write.  That being said, there are ways around this. 
    One way is to have a trigger in your database that updates the Report_Log table when the Stored Procedure is executed.  This would be the most efficient.
    The other way would be to have an application run the report and manage the entry. 
    Good luck,
    Brian

  • Inserting data into a column from 2 different tables

    Hi,
    I need to insert data into a table using 2 other tables. The tables that contain data have identical column names.
    Is using a UNION statement the only option?
    Also, if I need to insert data into columns from only one of the either tables, how do i do it?
    Thanks.

    For future reference, "doesn't seem to work" is a rather generic description... Posting the particular error message will be quite helpful, though I'm reasonably confident that I know the particular problem here.
    First, if only for sanity, you probably want to explicitly list the columns of the destination table in your INSERT statement.
    Second, it doesn't make sense to have DISTINCT clauses in queries that are UNION-ed together. A UNION has to do a sort to remove duplicates already.
    Third, the two queries you are UNIONing together have to return the same number of columns, with the same names, in the same order.
    You probably want something like
    INSERT INTO new_table( col1, col2, col3, col4, col5 )
      SELECT 'ABC'  col1,
             a.colA col2,
             a.colB col3,
             a.colC col4
             a.colD col5
        FROM table1 a
      UNION
      SELECT 'ABC'  col1,
             b.colA col2,
             b.colB col3,
             b.colC col4
             NULL   col5
        FROM table2 bJustin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How to Insert data from notepad to Table

    Hi,
    I have one table with nodata.i need to insert data into table.but i have records in one notepad.if i enter manually
    like using insert statement it will take more time.
    Any one know insert data from notepad to table or i need sql script that will use for all the records.Here im using sqldeveloper.

    Hi dude,
    We can use below 2 types.
    1) Sql loader
    2) utl file
    SQL*Loader utility?
    One can load data into an Oracle database by using the sqlldr (sqlload on some platforms) utility. Invoke the utility without arguments to get a list of available parameters. Look at the following example:
    sqlldr username@server/password control=loader.ctl
    sqlldr username/password@server control=loader.ctlThis sample control file (loader.ctl) will load an external data file containing delimited data:
    load data
    infile 'c:\data\mydata.csv'
    into table emp
    fields terminated by "," optionally enclosed by '"'           
    ( empno, empname, sal, deptno )
    {code}
    The mydata.csv file may look like this:
    {code}
    10001,"Scott Tiger", 1000, 40
    10002,"Frank Naude", 500, 20
    {code}
    Optionally, you can work with tabulation delimited files by using one of the following syntaxes:
    {code}
    fields terminated by "\t"
    fields terminated by X'09'
    {code}
    Additionally, if your file was in Unicode, you could make the following addition.
    {code}
    load data
    CHARACTERSET UTF16
    infile 'c:\data\mydata.csv'
    into table emp
    fields terminated by "," optionally enclosed by '"'           
    ( empno, empname, sal, deptno )Another Sample control file with in-line data formatted as fix length records. The trick is to specify "*" as the name of the data file, and use BEGINDATA to start the data section in the control file:
    load data
    infile *
    replace
    into table departments
    (  dept     position (02:05) char(4),
        deptname position (08:27) char(20)
    begindata
    COSC  COMPUTER SCIENCE
    ENGL  ENGLISH LITERATURE
    MATH  MATHEMATICS
    POLY  POLITICAL SCIENCEPlease refer the below link.. it will useful for you.
    http://psoug.org/reference/sqlloader.html
    http://docs.oracle.com/cd/B10500_01/server.920/a96652/ch05.htm
    Regards,
    N.Senthil.

  • How to insert select columns from one internal table to another

    Hi,
    How to insert select columns from one internal table to another based on condition as we do from a standart table to internal table.
    regards,
    Sriram

    Hi,
    If your question is for copying data from 1 int table to other ;
    we can use
    APPEND LINES OF it_1 TO it_2.
    or if they have different columns then:
    loop at it_1 into wa_it1.
    move wa_it1-data to wa_it2-d1.
    apped wa_it2 to it_2.
    clear wa_it2.
    endloop.
    thnxz

Maybe you are looking for

  • In Powerdesigner repository, can we limit access for any user to one particular model?

    Hi I have this requirement in Powerdesigner repository to setup a user and give him/her access to check in and check out only one model? In otherwords, when he logs into repostiory, he can't see any other folders except the folder that was assigned t

  • XSLT to convert CALS tables into html?

    This may be the wrong forum to post this, but I don't know where else I can, so I would very much appreciate if anyone can suggest where I can find such information. I need to write XSLT code that will transform CALS tables that InDesign exports in X

  • How to hyperlink a word in one pdf to open another pdf?

    Hi, I have been trying to find a program or app on my mac that will enable me to click on a word in one pdf file from my documents which would then open another pdf file in my documents. I can't seem to be able to do it on preview via the hyperlink o

  • Activate(maximize) Indesign Window

    Hi scripters, I have two window's minimized one is Adobe Indesign another one is Adobe Photoshop. Now I want to bring front or focus(maximize) Adobe Indesign. How can I do this? I am working with VB script windows xp. Thanks in advance regards a r u

  • No icon for the Hard Drive on my desktop, new MacBook, i7

    Brand new MacBook, Core i7... Right out of the box, there's no HD icon on my desktop(!) I did a clean reinstall & permission repair, but it's still not there. Is there something in System Preferences that I'm not finding? Suggestions?