Truncate Table after 20 rows?

Hi there!
Is it possible to truncate a table after 20 rows?
(Has it something to do with ROWNUM?)

declare
rowCount NUMBER := 0;
BEGIN
SELECT COUNT(1)
INTO rowCount
FROM taba;
IF rowCount = 1 THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE taba';
END IF;
END;
This code first count number or records in "taba" table. If number or records is 1 (only in this example. There should be >=20 for purpose of this thread) then execute statement using EXECUTE IMMEDIATE statement. All data inside table taba will be deleted.
Peter D.

Similar Messages

  • Default value for first row in table after row has rendered

    I have a master-detail type page where the first row in the detail table appears with no values when the page first renders. After the user enters some data in the master area, the default value is available. I then use something like this to set the default in one column of the first row:
    MyVOImpl vo = (MyVOImpl)am.getMyVO1();
    MyRowImpl voRow = (MyRowImpl)vo.first();
    voRow.setMyAttribute("some value");
    When I do this and run the code in the debugger, I can see that the default value is stored somewhere in the row object. However, the value is not displayed in the screen.
    What must I do to get the default value to display after the user has tabbed out of the master data area, and before the user attempts to enter data in the row?

    Hi. Thanks again.
    Here is more detail of the code:
    if (pageContext.isLovEvent())
    * Form was submitted because the user selected
    * a value from the LOV modal window,
    * or because the user tabbed out of the LOV input.
    * This code executes when the event is either
    * LOV_UPDATE or LOV_VALIDATE
    String lovInputSourceId = pageContext.getParameter(SOURCE_PARAM)
    // Find out the result values of the LOV.
    Hashtable lovResults =
    pageContext.getLovResultsFromSession(lovInputSourceId);
    // Find out which LOV input triggered the event.
    if (lovInputSourceId.equals("myLovItemId"))
    String myDefaultVar = null;
    if (lovResults != null)
    myDefaultVar = "some stuff " + (String)lovResults.get("myResultItemId")
    if (myDefaultVar != null && myDefaultVar != "") // yes, this is always true in this case
    // now set the default for the first line.
    // Added lines will be defaulted by the
    // EO.create() method.
    MyVOImpl myVo = (MyVOImpl)am.getMyVO1();
    MyVORowImpl myVoRow = (MyVORowImpl)myVo.first();
    myVoRow.setAttribute("myRowItemId", myDefaultVar); // THIS LINE DOES NOT CAUSE DISPLAY TO CHANGE
    The problem, as noted in the code, is that setAtrribute() does not cause the default value to display in the field.
    What can cause this, and what can fix it?
    Edited by: user522137 on Nov 9, 2010 12:06 PM

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

  • Release of space after delete/truncate table

    Hello,
    How does release of space after delete/truncate table works? Is the space used before deletion released once delete is complete or not? Will I see the space occupied by deleted table as free in dba_segments or will I need to reorganize the table (drop and recreate again?). Reason why I am asking is that I can see table with 0 rows, but in dba_segment I can see it is occupying few gigabytes....
    Thank you

    Here is a little illustration for you;
    SQL> conn ogan/password
    Connected.
    SQL> create table ogan_deneme as select * from all_objects;
    Table created.
    SQL> select count(*) from ogan_deneme;
      COUNT(*)
        228470
    SQL> set line 1000
    SQL> set pagesize 1000
    SQL> select * from dba_segments where owner='OGAN';
    OWNER    SEGMENT_NAME        PARTITION_NAME           SEGMENT_TYPE       TABLESPACE_NAME                HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS    EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE  FREELISTS FREELIST_GROUPS RELATIVE_FNO BUFFER_
    OGAN      OGAN_DENEME          TABLE              SYSTEM                                 854       319981   *30408704*       *1856*         *44*          65536                       1  2147483645                       1               1          854 DEFAULT
    SQL> truncate table ogan_deneme;
    Table truncated.
    SQL> select * from dba_segments where owner='OGAN';
    OWNER    SEGMENT_NAME        PARTITION_NAME           SEGMENT_TYPE       TABLESPACE_NAME                HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS    EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE  FREELISTS FREELIST_GROUPS RELATIVE_FNO BUFFER_
    OGAN      OGAN_DENEME           TABLE              SYSTEM                                 854       319981      *65536*          *4*          *1*          65536                       1  2147483645                       1               1          854 DEFAULT
    SQL>Hope it Helps,
    Ogan

  • TRUNCATE TABLE NOT WORKING AFTER DROPPING CONSTRAINTS

    Hi,
    I have a table with a foreign key constraint. I know you can't truncate tables when there are foreign key constraints. So I drop the constraints before running the TRUNCATE TABLE command. But SQL Server is still stating there are foreign key constraints
    even after they have just been dropped.
    When I use SQL Server Management Studio to generate a drop & create script on this table or any other table with an FK consttaint, the generated script fails stating that there are still foreign key constraints??
    I have the same problem for every table that has FK constraints, for those without FK, TRUNCATE table works without issues.
    The end goal is to reset the identity value of the primary key. Since DBCC does not work on Azure, TRUNCATE TABLE is the only way left, especially if you can't even drop and recreate tables with FK constraints.
    What am I missing here?
    Peter

    Hi,
    Thanks for posting here.
    TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.
    TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes, and so on remain. To remove the table definition in addition to its data, use the DROP TABLE statement.
    If the table contains an identity column, the counter for that column is reset to the seed value defined for the column. If no seed was defined, the default value 1 is used. To retain the identity counter, use DELETE instead.
    Restrictions
    You cannot use TRUNCATE TABLE on tables that:
    •Are referenced by a FOREIGN KEY constraint. (You can truncate a table that has a foreign key that references itself.)
    •Participate in an indexed view.
    •Are published by using transactional replication or merge replication.
    For tables with one or more of these characteristics, use the DELETE statement instead.
    TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. For more information, see CREATE TRIGGER (Transact-SQL).
    Truncating Large Tables
    Microsoft SQL Server has the ability to drop or truncate tables that have more than 128 extents without holding simultaneous locks on all the extents required for the drop.
    Permissions--------------------------------------------------------------------------------
     The minimum permission required is ALTER on table_name. TRUNCATE TABLE permissions default to the table owner, members of the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles, and are not transferable. However, you
    can incorporate the TRUNCATE TABLE statement within a module, such as a stored procedure, and grant appropriate permissions to the module using the EXECUTE AS clause.
    You cannot truncate a table which has an FK constraint on it.
    Typically my process for this is:
    Drop the constraints
    Trunc the table
    Recreate the constraints.
    Hope this helps you.
    Girish Prajwal

  • Fetching more than one row from a table after selecting one value from the dropdown

    Hi Experts,
    How can we fetch more than one row from a table after selecting one value from the dropdown.
    The scenario is that I have some entries in the dropdown like below
      A               B               C        
    11256          VID          911256  
    11256          VID          811256
    11256          SONY      11256
    The 'B' values are there in the dropdown. I have removed the duplicate entries from the dropdown so now the dropdownlist has only two values.for eg- 'VID' and'SONY'. So now, after selecting 'VID' from the dropdown I should get all the 'C' values. After this the "C' values are to be passed to other methods to fetch some data from other tables.
    Request your help on this.
    Thanks,
    Preeetam Narkhede.

    Hi Preetam!
    I hope I understand your request proberly, since this is more about Java and less about WebDynpro, but if I'm wrong, just follow up on this.
    Supposed you have some collection of your original table data stored in variable "origin". Populate a Hashtable using the values from column "B" (let's assume it's Strings) as keys and an ArrayList of whatever "C" is (let's assume String instances, too) as value (there's a lot of ways to iterate over whatever your datasource is, and since we do not know what your datasource is, maybe you'll have to follow another approach to get b and c vaues,but the principle should remain the same):
    // Declare a private variable for your Data at the appropriate place in your code
    private Hashtable temp = new Hashtable<String, ArrayList<String>>();
    // Then, in the method you use to retrieve backend data and populate the dropdown,
    // populate the Hashtable, too
    Iterator<TableData> a = origin.iterator();
    while (a.hasNext()) {
         TableData current = a.next();
         String b = current.getB();
         String c = current.getC();
         ArrayList<String> values = this.temp.get(b);
         if (values == null) {
              values = new ArrayList<String>();
         values.add(c);
         this.temp.put(b, values);
    So after this, you'll have a Hashtable with the B values als keys and collections of C values of this particular B as value:
    VID --> (911256, 811256)
    SONY --> (11256)
    Use
    temp.keySet()
    to populate your dropdown.
    After the user selects an entry from the dropdown (let's say stored in variable selectedB), you will be able to retrieve the collection of c's from your Hashtable
    // In the metod you handle the selection event with, get the c value collection
    //and use it to select from your other table
    ArrayList<String> selectedCs = this.temp.get(selectedB);
    // now iterate over the selectedCs items and use each of these
    //to continue retrieving whatever data you need...
    for (String oneC : selectedCs) {
         // Select Data from backend using oneC in the where-Clause or whatever...
    Hope that helps
    Michael

  • Truncate table loses privs on table...

    Oracle11g/RHEL5
    Hi,
    We have a table that is inserted into a then deleted every so often. The current method that was being used to remove the rows was the TRUNCATE TABLE ption. However, we found out that when that statement is issued, that any user that had privs on that table, no longer work even after it is re-created. So it looks like the next option is to used the DELETE * from table_name. However, that is not good for performance and undo. This table is about 300,000 rows and will grow in the future. How could we get around this issue?
    Thanks.

    Hi,
    JrOraDBA wrote:
    Oracle11g/RHEL5
    We have a table that is inserted into a then deleted every so often. The current method that was being used to remove the rows was the TRUNCATE TABLE ption. However, we found out that when that statement is issued, that any user that had privs on that table, no longer work even after it is re-created. You must have done something else. TRUNCATE TABLE does change privileges.
    What do you mean by "after it is re-created"? You don't have to issue another CREATE statement after TRUNCATE TABLE.
    Do you mean after re-populating the table? Do you mean that other users, who did have privileges, can still DESCRIBE the table right after it is TRUNCATEd, but they can't do anything with it after an INSERTs have been done?
    I suspect you DROPped the table at some point.
    Double-check that the problem exists when all you do is TRUNCATE TABLE.
    Post a script that re-creates the problem. There's no need to include lots of data: one column and one row will show the problem just fine.

  • Shrink table after delete

    Hi,
    I want to remove some data from a Oracle table, too free up some space on hard drive.
    I use delete clause with where condition to delete data, but then after i would need some shrink clause to shrink up the table as i understand.
    I cant use truncate because it doesn't allow to use where clause. I need something like:
    delete from table 1 where condition1;
    shrink table1; --rfree up space                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Simply deleting rows doesn't make blocks eligible for deallocation. Try this:
    truncate table mette reuse storage;
    CALL DBMS_STATS.GATHER_TABLE_STATS(USER,'mette');
    SELECT t.blocks used, s.blocks allocated
    FROM   user_tables t JOIN user_segments s ON s.segment_name = t.table_name
    WHERE  t.table_name = 'METTE';
       USED ALLOCATED
          0     20480
    alter table mette deallocate unused;
    CALL DBMS_STATS.GATHER_TABLE_STATS(USER,'mette');
    SELECT t.blocks used, s.blocks allocated
    FROM   user_tables t JOIN user_segments s ON s.segment_name = t.table_name
    WHERE  t.table_name = 'METTE';
       USED ALLOCATED
          0         8
    alter table mette allocate extent;
    -- ...same query...
       USED ALLOCATED
          0        16
    alter table mette deallocate unused;
    -- ...same query...
       USED ALLOCATED
          0         8

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

  • Truncating table having partitions

    Hi,
    I have a table haing 10 partitions and 5 subpartitions in each partition. Now i have to truncate that table. please let me know..
    1) Can i truncate the table directly?
    2) If no then how to truncate the table having partition->sub-partitions....
    With Regards,
    snp

    Hello,
    To count your rows on the Truncated Table, you may also execute the following query:
    select count(*) from <Table_name>;You should be carefull if you ANALYZE or use DBMS_STATS on your Table just after you
    Truncate it.
    Because, as the Table is empty, the statistics of the optimizer may be wrong and, it could
    affect the performance of your queries on this Table later (when it will be full).
    So, you may have to refresh you statistics (with DBMS_STATS) after loading again this Table.
    Hope this help.
    Best regards,
    Jean-Valentin

  • How can I write into a table cell (row, column are given) in a databae?

    How can I write into a table cell (row, column are given) in a database using LabVIEW Database Toolkit? I am using Ms Access. Suppose I have three columns in a table, I write 1st row of 1st column, then 1st row of 3rd column. The problem I am having is after writing the 1st row 1st column, the reference goes to second row and if I write into 3rd column, it goes to 2nd row 3rd column. Any suggestion? 
    Solved!
    Go to Solution.

    When you do a SQL INSERT command, you create a new row. If you want to change an existing row, you have to use the UPDATE command (i.e. UPDATE tablename SET column = value WHERE some_column=some_value). The some_column could be the unique ID of each row, a date/time, etc.
    I have no idea what function to use in the toolkit to execute a SQL command since I don't use the toolkit. I also don't understand why you just don't do a single INSERT. It would be much faster.

  • Truncate Table before Insert--Performance

    HI All,
    This post is in focus of special requirement where a table is truncated before inserting records in the table.
    Now, when a table is truncated the High Water Mark(HWK) is reset to lowest memory allocated for table in tablespace. After this, would insert with append can boost the performance of the insert query?
    In simple insert query, the oracle engine consults the free list to look for free spaces.
    But in insert with apppend, the engine starts above the HWM. And the argument is when truncate has been executes on table, would the freelist be used in simple insert.
    I just need to know if there are any benefits of using append insert on truncated table or simple insert would be same in term of performance with respect to insert with append.
    Regards
    Nits

    Hi,
    if you don't need the data truncate the table. There is no negativ impact whether you are using an conventional path or a direct path insert.
    If you use append less redo is written for the table if the table is in NOLOGGING mode, but redo is written for all indexes. I would recommand to create a full backup after that (if needed), because your table will not be recoverable after that (no REDO Information).
    Dim

  • Raising ora-01426 error while truncating table

    Hi,
    We have a procedure which executes in the following process for few set of tabls
    1. disables the constraints
    2. truncating the tables
    3. enabling the constraints
    but after processing for 5 tables, while truncating the error throws
    BEGIN <procedure name >; END;
    ERROR at line 1:
    ORA-01426: numeric overflow
    ORA-06512: at "<procedurename> ", line 33
    ORA-06512: at line 1
    this line 33 point to execute immeidate 'truncate table < table name>
    Can i know what would be reason for throwing ' numeric overflow' error while truncating table..
    Thanks in advance

    user9080289 wrote:
    thanks.
    My oracle verision is 11gThen you could have the bug described there. Follow the instruction how to workaround (monitoring flush, set stats to low value) or apply the patch #8226471.
    Nicolas.

  • Truncate table and materialized view log

    I user oracle 10 R2
    I have a table and on that table a materialized view log.
    I execute in a pl/sql procedure:
    1) execute immediate('drop materialized view log on tab1');
    then:
    2) execute immediate('truncate table tab1');
    3) Now I insert a lot of records in tab1
    4) execute immediate('create materialized view log on tab1 WITH rowid INCLUDING NEW VALUES');
    When I create the materialized view log I recieved this message:
    ora32321: refresh fast on tab2 unsupported after detail table truncate
    Why?

    Refresh fast after truncate operation on container table is not supported, regardless the container table is or is not partitioned.
    Perform a refresh complete.
    ORA-32321 :
    Cause:     A detail table has been truncated and no materialized view
         supports fast refersh after a detail table has been truncated
    Action:     Use REFRESH COMPLETE. Note: you can determine why your
         materialized view does not support fast refresh after TRUNCATE
         using the DBMS_MVIEW.EXPLAIN_MV() API.

  • Truncate table related questions

    Hi Folks,
    Environment: 10g Rel 2
    I am trying to prove the following two points by way of experimentation
    a, The truncate table operation will reset the high water mark (HWM) to the first usable data block in the table segment
    # Take a HWM snap shot before the truncate operation
    select a.BLOCKS - b.EMPTY_BLOCKS -1 HWM
    from
      (SELECT BLOCKS
       FROM   DBA_SEGMENTS
       WHERE  OWNER=UPPER('JIM') AND SEGMENT_NAME = UPPER('EMPLOYEES')) a,
       (SELECT EMPTY_BLOCKS
        FROM   DBA_TABLES
        WHERE  OWNER=UPPER('JIM') AND TABLE_NAME = UPPER('EMPLOYEES')) b;Output: 7
    truncate table JIM.EMPLOYEES;
    Re ran the above code and got the same result (i.e. 7 blocks). I was expecting to see 0 blocks instead? Is the above query the right method of
    finding the HWM?
    b, The truncate operation will also truncate the corresponding indexes for the table
    Q, Is there a view that will show all the index values of the table? These values will probably be meaningless, but I would like to see them before
    and after the truncate operation.
    Thanks
    rogers42

    a) If you would have read on the empty_blocks column in dba_tables, you would have known it is populated by dbms_stats.
    Did you run dbms_stats.analyze_table?
    b)
    There is no such view.
    All dictionary views are documented in the view DICT and the online documentation.
    Sybrand Bakker

Maybe you are looking for

  • Cost Elements Values flow to COPA

    Dear Experts,        We are using Costing based Operating Concern. I am clear that how to get values from SD to COPA Value Fields, I.e. assignment of Value Fields with condition types. But my confusion is how to get the values of cost element and cos

  • Photoshop CS3 in wine with awesomewm.

    This has been happening for a while, and it's rather annoying. Every time I hover something, it moves like 3 pixes to the right and down. This includes the workspace window, the toolox, and all other windows (Character, Color palette, etc). I've sear

  • LiveCycle, Email Service Stops working

    Hi Folks, I'm having a sporadic issue with LiveCycle. Roughly 2-3 times a month the email service will stop working. Users can still email our adobe mailbox and wont receive any errors back but their documents arent being sent back to them. Once i re

  • Airport fails to load and even to be reconfigured via wifi

    airport fails to load and even to be reconfigured via wifi

  • Airport Extreme Power Failure

    My airport extreme died recently. We were using it for at least two years with no problems. The power light fails to turn on when plugged in - the device is unresponsive. Any way to salvage this Airport? Or am I screwed?