Internal Behaviour of Truncate Table Command in Oracle Database

Hi,
Can anyone let me know the internal behaviour of Truncate Table Command in Oracle Database?
Thanks,
Harshad.

Hi Tuhinshoor,
I know the functioning of Truncate Command.
But, I needed to know whether it drops the table before recreating it, maintaining all the indexes and constraints intact??
Thanks,
Harshad.

Similar Messages

  • Reg: Truncate table command in Stored Procedures

    Hi All,
    I wrote one procedure in which i used 'Truncate Table command' and while compiling I am getting an error. I searched on google but again many queries has been asked there but no suitable solution is there. So please help me in understanding this matter.I will be really obliged of you.
    Gursimran Singh

    Hi thanks for your reply. The error I am getting is here
    PLS-00103: Encountered the symbol "TABLE" when expecting one of the following:
    := . ( @ % ;
    The symbol ":= was inserted before "TABLE" to continue.
    I appreciate your step to use 'execute immediate 'truncate table table_name';. but the thing is that the system is not allowing my to use TRUNCATE than how come i use the above expression.
    Second thing is that there is no error in syntax, everything is fit and fine.
    Gursimran

  • I want to know when we issue truncate table statement in oracle .

    i want to know when we issue truncate table statement in oracle .No log will be write in redo log .But we can recover data using flashback or scn.I want to know where is the actually truncate table statement log is stored in oracle database.Please explain me in detail step by step .

    Hi,
    I have truncated table after that i have restored that data.See below the example.I want to know from where it's restored.
    From which log file it's restored.
    create table mytab (n number, x varchar2(90), d date);
    alter table mytab enable row movement;
    Table altered.
    SQL> insert into mytab values (1,'Monsters of Folk',sysdate);
    1 row created.
    SQL> insert into mytab values (2,'The Frames',sysdate-1/24);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select CURRENT_SCN from v$database;
    CURRENT_SCN
    972383
    SQL> select * from mytab;
    N
    X
    D
    1
    Monsters of Folk
    30-DEC-12
    2
    The Frames
    30-DEC-12
    N
    X
    D
    SQL> set lines 10000
    SQL> /
    N X D
    1 Monsters of Folk 30-DEC-12
    2 The Frames 30-DEC-12
    SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
    TO_CHAR(SYSDATE,'
    20121230 09:29:24
    SQL> set timing on
    SQL> truncate table mytab;
    Table truncated.
    Elapsed: 00:00:15.75
    SQL> select * from mytab as of timestamp TO_TIMESTAMP('20121230 09:29:24','yyyymmdd hh24:mi:ss');
    N X D
    1 Monsters of Folk 30-DEC-12
    2 The Frames 30-DEC-12
    Elapsed: 00:00:00.28
    SQL> insert into mytab select * from mytab as of timestamp TO_TIMESTAMP('20121230 09:29:24','yyyymmdd hh24:mi:ss');
    2 rows created.
    Elapsed: 00:00:00.01
    SQL>

  • How to import a table from another oracle database ?

    Hi all ,
    i could like to use pl/sql to import one table from another oracle database server ?
    is it possible to do this ?
    A server B server
    table: test <------------------------> table : newtest
    the tns profile already configurated . the connection is ready .
    thanks a lot !
    Best Regards,
    Carlos

    if i don't have TEST table on server B whether COPY command will create this table on server B with the same structure ? If you specify CREATE as a clause the table will be created:
    SQL> help copy
    COPY
    COPY copies data from a query to a table in a local or remote
    database. COPY supports CHAR, DATE, LONG, NUMBER and VARCHAR2.
    COPY {FROM database | TO database | FROM database TO database}
                APPENDCREATE|INSERT|REPLACE} destination_table
                [(column, column, column, ...)] USING query
    where database has the following syntax:
         username[password]@connect_identifier

  • Interrupted TRUNCATE TABLE command

    Hello,
    I've made very dangerous mistake today: TRUNCATE TABLE on production database. :-(
    But in several seconds (2 or 3), I managed to break the operation (Before the execution ended).
    It was quite a big table, now (after the accident) there are more then 32 million records.
    We need to know, are there any records deleted?
    We have no proper backup, to compare the records with it.
    And I could not find any in-depth description of how TRUNCATE works.
    Please can you:
    1. Tell, about any method to check if there are deleted records?
    2. Link, to any resource, where I can read in details, about how TRUNCATE TABLE works.
    Thanks, in advance, for help

    My understanding is that the TRUNCATE TABLE table statement is atomic. It either fails or succeeds. Truncates all rows or no rows at all. Therefore if you interrupt a TRUNCATE TABLE statement your table should remain in its original state.
    This can be shown below:
    SQL > CREATE TABLE TEST AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    12421 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    24842 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    49684 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    99368 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    198736 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    397472 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    794944 rows created.
    SQL > INSERT INTO TEST SELECT * FROM TEST;
    1589888 rows created.
    SQL > SELECT COUNT(*) FROM TEST;
      COUNT(*)
       3179776
    SQL > TRUNCATE TABLE TEST;
    ^C
    H:\>sqlplus /@testdb
    SQL*Plus: Release 10.2.0.4.0 - Production on Mon Aug 3 08:20:11 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter password:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL > SELECT COUNT(*) FROM TEST;
      COUNT(*)
       3179776HTH!

  • Auto Increment ID Field Table in the Oracle Database (insert new record)

    I have been using the MySQL. And the ID field of the database table is AUTO INCREMENT. When I insert a new record into a database table, I can have a statement like:
       public void createThread( String receiver, String sender, String title,
                                 String lastPostMemberName, String threadTopic,
                                 String threadBody, Timestamp threadCreationDate,
                                 Timestamp threadLastPostDate, int threadType,
                                 int threadOption, int threadStatus, int threadViewCount,
                                 int threadReplyCount, int threadDuration )
                                 throws MessageDAOSysExceptionand I do not have to put the ID variable in the above method. The table will give the new record an ID number that is equivalent to the ID number of the last record plus one automatically.
    Now, I am inserting a new record into an Oracle database table. I am told that I cannot do what I am used to doing with the MySQL database.
    How do I revise the createThread method while I have no idea about what the next sequence number shall be?

    I am still very confused; in particular, the Java part. Let me try again.
    // This part is for the database table creation
    -- Component primary key sequence
    CREATE SEQUENCE dhsinfo_page_content_seq
        START WITH 0;
    -- Trigger for updating the Component primary key
    CREATE OR REPLACE TRIGGER DHSInfoPageContent_INSERT_TRIGGER
        BEFORE INSERT ON DHSInfoPageContent //DHSInfoPageContent is the table name
        FOR EACH ROW WHEN (new.ID IS NULL) // ID is the column name for auto increment
        BEGIN
            SELECT dhsinfo_page_content_seq.Nextval
            INTO :ID
            FROM DUAL;
        END;/I am uncertain what to do with my Java code. (I have been working with the MySQL. Changing to the Oracle makes me very confused.
       public void updateContent( int groupID, String pageName, int componentID,
                                  String content, Timestamp contentCreationDate )
                                   throws contentDAOSysException
       // The above Java statement does not have a value to insert into the ID column
       // in the DHSInfoPageContent table
          Connection conn = null;
          PreparedStatement stmt = null;
          // what to do with the INSERT INTO below.  Note the paramether ID.
          String insertSQL = "INSERT INTO DHSInfoPageContent( ID, GroupID, Name, ComponentID, Content, CreationDate ) VALUES (?, ?, ?, ?, ?, ?)";
          try
             conn = DBConnection.getDBConnection();
             stmt = conn.prepareStatement( insertSQL );
             stmt.setInt( 1, id ); // Is this Java statement redundant?
             stmt.setInt( 2, groupID );
             stmt.setString( 3, pageName );
             stmt.setInt( 4, componentID );
             stmt.setString( 5, content );
             stmt.setTimestamp( 6, contentCreationDate );
             stmt.executeUpdate();
           catch
           finally

  • Can't access tables in other Oracle database schemas

    Hi. We got our Oracle database admin to install APEX in our Oracle database. She created a login and schema for my Oracle database user so that I could work with APEX a little. Here's the information on the version of APEX we have installed:
    Database Version Information
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE 11.2.0.2.0 Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    I've found that my user is only able to access Oracle tables within my own Oracle database schema. Most of our main tables are in 3 other schemas and I'd need access to all tables in all these schemas. Right now whenever I encounter a drop list of values for Schema, only by own schema is available in the list of values.
    Is there something our Admin can do to make these tables in other schemas available to my user account?

    Sharpe,
    This documentation should point you in the right direction. It will show you how to add multiple schemas to a workspace.
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21678/adm_mg_wrkspc.htm#CHDBDCCJ
    Cheers,
    Tyson Jouglet

  • Use Host command in Oracle Database Trigger

    I need to run Host command from a database trigger in order to execute a sh file in a Solaris, Unix, environment. How can I do it? The database environment is in Solaris and the database is 10g.
    Please let me know as soon as possible.

    Hi,
    read this <http://devtrigger.blogspot.com.br/2012/08/svn-backup-on-unix-or-solaris.html>
    Or
    you can to run in nohup. For example
    You can a script with the command vi about your trigger and run with the sintaxe bellow:
    nohup sqlplus "/as sysdba" @script.sql &
    Where "script.sql" is the name of the your file.
    Kind regards,
    Bruno Reis.
    www.brunors.com

  • Xml Data into Table Within an Oracle Database

    With no oracle or database background, I have been tasked to figure out how to analyze reading values within xml files. I initially started by writing c# code to read through the xml files, pull out the values I need and summarize the results. Unfortunately, this took atleast 5 hours to open all the xml files and summarize the results for a small portion of EndPointChannelId's and xml files. I decided to store all the reading values within the xml files into a table so I can use SQL queries to do the analysis instead of having to process through all the files each time. Using the same c# code as before, I have used insert and update sql statements to insert the reading values into a table. To my dismay, it takes about 3 and a half hours to import 1 file where there is 20 files a day :S. There are over 19,000 ChannelID's per file. I am currently using SQL Developer to view the data and have noticed XML Schemas and XML DB Repository but am not sure if that would be the best approach to my problem. I need to increase the efficiency of the import process but I am having difficulties trying to figure out how to go about it. Do you have any suggestions on where I should go from here? What is the most efficient way you have used to import xml files into a table structure. I would greatly appreciate any ideas!
    Below is a portion of the xml file that I am working with.
    - <Channel ReadingsInPulse="false" IsRegister="false" IsReadingDecoded="true" MarketType="Electric" IntervalLength="60">
    <ChannelID EndPointChannelID="57432:1" />
    - <ContiguousIntervalSets>
    - <ContiguousIntervalSet NumberOfReadings="6">
    <TimePeriod EndRead="22467.80" EndTime="2013-05-09T13:00:00Z" StartTime="2013-05-09T07:00:00Z" />
    - <Readings>
    <Reading Value="0.31" />
    <Reading Value="0.4" />
    <Reading Value="0.16" />
    <Reading Value="0.32" />
    <Reading Value="0.09" />
    <Reading Value="0.35" />
    </Readings>
    </ContiguousIntervalSet>
    </ContiguousIntervalSets>
    </Channel>

    Hi,
    Welcome to the forums,
    what i understand from your Post, You want to read/analyze some value from xml files. and for this you want to import it in database and then perform some Query on that file for easy work.
    you can choose the External table concept for reading/ Query those files
    check this link may it help you
    Creation of External table by using XML files.
    http://docs.oracle.com/cd/B28359_01/server.111/b28310/tables013.htm

  • XML to table mapping in oracle database

    Hi,
    I am having 2 modules in my application:
    First module takes the XML file, parse it, fetches data, creates a table in database and stores the data into that table.
    Second module does vice versa. it takes a table, retrives data and write out an XML file.
    In first module I use DOM parser. But I want to use Oracle XSU for the second module. But it seems that I can not use oracle XSU and DOM togather.
    when I include xmlparserv2.jar in class path I can not run my first module.
    Is it possible that I can use dom for first module and XSU for second module?
    It gives me error like ..
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: oracle/xml/parser/v2/XMLText
    at oracle.xml.parser.v2.NonValidatingParser.<init>(NonValidatingParser.java:139)
    at oracle.xml.parser.v2.XMLParser.<init>(XMLParser.java:122)
    at oracle.xml.parser.v2.DOMParser.<init>(DOMParser.java:82)
    at oracle.xml.jaxp.JXDocumentBuilder.<init>(JXDocumentBuilder.java:71)
    at oracle.xml.jaxp.JXDocumentBuilderFactory.newDocumentBuilder(JXDocumentBuilderFactory.java:72)
    BUT if I remove xmlparserv2.jar from classpath then it works fine...
    I would really appreciate if anyone can throw light ...
    Thanks in advance
    rp

    Hi,
    I had somewhat a similar problem.
    Did you use oracle.xdb.XMLType.getDOM()?
    getDOM() needs xmlparserv2.jar, which only provides a DOM implementation that is DOM 1.0 and Core 2.0 compliant.
    In my case, when I used DOM 3.0 methods in org.w3c.dom, I ran into the "method not found" type of error.
    My solution was to use the DocumentBuilder that comes with the JDK to create the DOM instance in the code.
    P.

  • Cannot access columns in a result set using table alias in Oracle database

    I have a query which joins a few tables. There are a few columns in various tables with identical names. In the query, I have assigned table aliases for each table thinking it'll be the manner in which I access a specific column in a specific database table. However, when trying to retrieve the column, I'm getting an exception stating "Invalid column name". I had no problem doing so in my last project when I was coding against MySQL database so this is likely to be a driver implementation issue. My current workaround is to assign a column alias though I find this to be annoying and it does make the query very verbose.
    My question is whether this option is perhaps a configuration issue, a bug, or something that I'm missing. Also, I would like to know if anybody has an elegant workaround without accessing columns using their numeric index.
    I'm querying an Oracle 10i database in a managed environment (database connection is obtained from a Weblogic data source).
    Sample query:
    select
    a.address1,
    d.address1
    from
    account a
    inner join
    department d on a.department_id = d.department_id
    where
    a.account_id = 1000;
    When trying to access a ResultSet instance in the following manner, I will get an exception:
    rs.getString("d.address1");
    Retrieving "address1" will return the first column in the select clause.

    jonathan3 wrote:
    My question is whether this option is perhaps a configuration issue, a bug, or something that I'm missing. Since you already figured out that you can use an alias one can suppose that it is the last in that you are missing that you already have a solution.
    You can try extracting the meta data to see if it has a name without the alias. Probably not.
    Also, I would like to know if anybody has an elegant workaround without accessing columns using their numeric index.One can only suppose that you consider using names "elegant".

  • How to trace drop command in oracle database.

    Dear All,
    As a DBA how can we trace the drop cammand in database to know who droped , deleted the tables or deleted data from tables or droped directory from dba_directories.
    Thanks,

    Thanks Kamran,
    see for me audit file is not creating at OS level.
    SQL> CONN audit_test/password
    Connected.
    SQL>
    SQL> CREATE TABLE test_tab (id NUMBER 3 );
    Table created.
    SQL>
    SQL> INSERT INTO test_tab (id) VALUES (1);
    1 row created.
    SQL> UPDATE test_tab SET id = id;
    1 row updated.
    SQL> SELECT * FROM test_tab;
    ID
    1
    SQL> DELETE FROM test_tab;
    1 row deleted.
    SQL> DROP TABLE test_tab;
    Table dropped.
    SQL> conn /as sysdba
    Connected.
    SQL> show parameter audit
    NAME TYPE VALUE
    audit_file_dest string C:\ORACLE\PRODUCT\10.2.0\ADMIN
    \TEST1\ADUMP
    audit_sys_operations boolean TRUE
    audit_trail string OS
    SQL> host
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    C:\Documents and Settings\sherkhan>cd c:\oracle\product\10.2.0\admin\test1\adump
    C:\oracle\product\10.2.0\admin\test1\adump>dir
    Volume in drive C has no label.
    Volume Serial Number is F855-F548
    Directory of C:\oracle\product\10.2.0\admin\test1\adump
    05/19/2011 09:07 AM <DIR> .
    05/19/2011 09:07 AM <DIR> ..
    0 File(s) 0 bytes
    2 Dir(s) 1,414,656,000 bytes free
    Thankss

  • Setting priority of order of DELETE -vs- INSERT commands in Oracle database

    Hi,
    I have an .NET application which has a DELETE command (e.g. Delele from MyTable where id = 1) immediately followed by an INSERT command (e.g. INSERT INTO MyTable (id, field1, field2) values (1, 'x', 'y').
    We are not using transactions, so the commands are independent.
    MyTable has a unique constraint on the id column.
    On occasion, I am getting an error "ORA-00001 : unique constraint ... violated."
    I speculate that the INSERT command is being processed by the database before the DELETE command.
    Would you know if the priority of INSERT commands can be set higher to DELETE commands? How could I set this on my database (for testing purposes)?
    Thanks!

    One piece of the puzzle that I nelgected to mention...
    This DELETE/INSERT scenario is happening in an ASP.NET application going through Oracle's .NET driver (ODP.NET).
    The DELETE and INSERT are run with the autocommit feature of ODP.NET (I assume this translates into a separate transaction for each of these two statements).
    We have the "connection pooling" enabled (for the ODP.NET). Maybe because of the connection pooling, might ODP.NET be reversing the order of the DELETE and UPDATE commands?
    A problem I have is that I cannot see this problem occur on my server: the problem only occurs on the customer's server. He has reported several occurances of the problem.
    Do you think the Oracle session tracing will be of help if I cannot reproduce the problem (on my machine)?
    Thanks for you help so far!
    (clarification: The DELETE is run and "auto-committed", the immediately, the INSERT is run and "auto-committed")
    Edited by: user8267059 on Oct 15, 2008 6:00 AM

  • Putting Partition in tables in the Oracle database

    How do I create partitions in the various SAP datases running on Oracle?

    Hi,
    I'm sorry to say you've reached the wrong forum, as this one's for MaxDB and liveCache only. I'll try to find a more suited one.
    Can you maybe tell us which:
    - SAP Application plattform (Netweaver, BI ...) you are using?
    - operating system (OS) your Oracle DB is running on?
    Regards,
    Roland

  • Data extraction into sap table  from legacy oracle database

    Hello All,
        I have a scenario where I have two different software systems (SAP and xyz systems), where a intermediate table will be created in between the two systems that is shared. Data will be updated by the xyz systems into this shared table. Now, my questions regarding this shared table.
       1) Can we write some program or something to get the data from shared table to update the SAP?
       2) If possible send me the suggestions
       3) Please also send me the sample code to get the data from the shared table
    Thanks in advance,
      SDN powered

    this shared table should be compatiable to sap fields...write code to fetch data from this table and assign data to appropriate fields in SAP and insert the data into sap.
    1. Push mechanism
    Write a RFC on SAP side to insert entries into the table.
    Call the RFC from xyz application passing the data you want to insert.
    2. Pull mechanism
    Write a ABAP Program, where you can somehow read the data of the xyz application and insert data into the table.
    3. Flat file
    Dump the data from xyz application into the file.
    Write a ABAP program to read the file and update the table.

Maybe you are looking for