drop and re-create the table using dynamic sql

The following procedure should drop the table and re-create it. Currently, I get the dbms_output of the query. If I run the query only, it works well. but through the procedure, it does not work. Please help me

PROCEdure emp_backup is
sql_txt varchar2(10000);
begin
     begin
     EXECUTE IMMEDIATE 'drop table emp_backup ' ;
     exception
     when others then
     null;

     sql_txt:= 'CREATE TABLE emp_backup as ' ||
                 'select * from emp  '||
                 'where dep_no=10 ' ;
     dbms_output.put_line(sql_txt);
     EXECUTE IMMEDIATE sql_txt;
Exception
when others then
Null;

End;

Daniel wrote:
I'm getting following error ORA-01031: insufficient privileges

What is the command to grant privileges to this

GRANT CREATE TABLE TO <>

Detaching Frank, however, and echoing my previous comment, let them down and to re-create the tables makes no sense. It is logical to truncate a table if you test a load. If you build a data warehouse, it makes sense to delete and re-create a partition if you rerun a load for a particular date and that you have daily partitions. Deletion and recreation of a table in a stored procedure is not a reasonable way to test a system (nor is there a reasonable way to approach change control issues that will inevitably produce when you need to change the structure of a table).

Justin

Tags: Database

Similar Questions

  • drop and re-create the table

    Hello

    I am very new to the Apex. Very basic SQL and pl sql.

    Two questions: -.

    First of all, I want to delete a table and then recreate the same table in a script (strange I know but it is purely a LOV table).

    Then, run the combined script when a user presses a button on a form in the published application.

    REPORTED

    Hi reported.

    The delay I was referring to that is that when you go on a database connection, it takes much longer for a long time as if it were local. Rather than create a local table, why don't you just make the LOV created through data binding? for example the LOV queries:

    SELECT DISTINCT surname display_value, surname return_value
    FROM CUSTOMER_TBL@DBLINK
    

    Mike

  • Trying to create the table using Clause any Union with Select multiple stmts

    The motion seeks to get the substring of the value to for example.
    If the value is * ASA 2 * then so do ASA
    where as if the value is * 1.5 TST * it sholud come as TST as wise for others too.
    I am trying to execute stmt SQL written but in error as below:

    * ' ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias. "

    CREATE TABLE TEST_CARE AS
    (
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 5
    UNION ALL
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 7
    UNION ALL
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 14
    UNION ALL
    Row_id SELECT, old_care_lvl, SUBSTR (old_care_lvl, 3), LEN test_care_lvl
    WHERE LENGTH = 7 AND old_care_lvl (old_care_lvl) = "Regular."
    );

    I want to create the table using the above given the multiple selection by using the Union ALL clause, but trying to create run query error like "ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias.

    Please guide me how to approach to solve this problem.
    Thanks in advance.

    Try this->

    CREATE TABLE TEST_CARE
    AS
      select *
      from (
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =5
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =7
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =14
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
          );
    

    N.B.: Not tested...

    Kind regards.

    LOULOU.

  • How to create the Table using the column Drag and Drop feature

    Hello:
    I'm new to Data Modeler tool Oracle SQL dev and would like to know if there is a way to create a new table by reusing existing columns or groups of columns. The idea is to maintain consistency and save time of table design. If the columns created previously can be reused and require, drag and drop column in the right pane, then only new columns must be created manually.

    Any thoughts on this will be appreciated.

    Thank you!

    Yes - just change the name of the model table in the script (t_name = "table_template") then save this new transformation for later use.

    I don't know how to apply only some of the tables. Seems like something you could do to a secondary view level?

    Perhaps someone else on the forum can advise how to change the script to work on a subview only instead of the whole model.

  • Drop and re-create the index on the current table

    Hello

    I just have a few questions about the removal and creating indexes on a table that activates a lot.

    Let me explain first:

    The table is used by the application with the DML statements every 3 seconds and I want to do is to drop the indexes and re-create them.
    But Im worried about the consequences - what happens when I try to recreate the indexes and the table has an option rowlock/used by the application?

    P.S
    It's production environment - so I can't stop the application.


    BR / Ander

    A reconstructed index either Online or Offline.

    Online index rebuild features:

    ALTER INDEX REBUILD ONLINE;

    LMD is allowed on the base table
    It's relatively slow
    Base table is targeted for the new index
    Base table is locked in shared mode and DOF is not possible
    Intermediate table stores changes to data in the base table, during the rebuilding of indexes to update the new index later

    Offline index rebuild features:

    ALTER INDEX REBUILD. (Default)
    Does not refer to the base of the table and the base table is exclusively locked
    New index is created from the old index
    Not possible DML and DDL on the base table
    Relatively faster

  • Create the table using check constraints

    I am trying to create a table with the following sql statement.

    CREATE TABLE suppliers
    (
    supplier_id NULL NUMERIC (4).
    supplier_name NULL VARCHAR2 (50).
    Date1 DATE NULL,.
    date2 DATE NULL CONSTRAINT CHECK check_date (date1 > date2)
    );


    I am gettign the following error

    "ORA-02438: column check constraint cannot reference other columns.

    How can I get this red using a trigger.
    Help, please

    Simply, you missed a comma after your last column and constraint.

    ME_XE?CREATE TABLE suppliers
      2  (
      3  supplier_id NUMERIC(4) NULL ,
      4  supplier_name VARCHAR2(50) NULL ,
      5  date1 DATE NULL ,
      6  date2 DATE NULL ,
      7  CONSTRAINT check_date CHECK (date1 > date2)
      8  );
    
    Table created.
    
    Elapsed: 00:00:00.04
    
  • create the cookie using pl sql and retrieve values

    Hello
    I am currently in an urgent need to create cookies to BE oracle and also read the values of the. I tried to use code below. his display error
    code
    DECLARE
    ourcookie owa_cookie.cookie;
    BEGIN
    ourCookie: = owa_cookie.get('SESSION2');
    END;
    /

    BEGIN

    owa_util.mime_header ("text/html", FALSE ");

    -Create a cookie
    (owa_cookie). Send
    name = > 'SESSION. "
    value = > '344444',.
    expires = > sysdate + 2,.
    path = > ' / ');


    owa_util.http_header_close;

    EXCEPTION
    WHEN OTHER THEN NULL;

    END;


    But when I'm reading the cookie that I created, I am unable to exercise

    -It's for reading cookies
    DECLARE
    ourcookie owa_cookie.cookie;
    BEGIN
    ourCookie: = owa_cookie.get('SESSION2');
    END;
    /

    error:
    ORA-06502: PL/SQL: digital error or value
    ORA-06512: at "SYS." OWA_UTIL", line 325
    ORA-06512: at "SYS." OWA_COOKIE', line 36
    ORA-06512: at "SYS." OWA_COOKIE', line 140
    ORA-06512: at line 4 level

    842106 wrote:

    Now according to the guidelines of your comment, I created a simple OWA environment and run the code below. Now I get not found error of data

    ORA-01403: no data found
    ORA-06512: at line 23

    The error is caused the cookie is not found.

    The following is not valid - as there is no browser to receive the cookie:

    (owa_cookie). Send
    name-online "SESSION1"
    value-online '344433',
    expires => it sysdate + 2,.
    => path ' / '.
    );

    The following code must set the CGI environment - and add the cookie to the environment for the following code to read (as shown in the code example that I posted in the 2nd thread I talked to you):

    / * Initialization * /.
    OWA.cgi_var_name (1): = 'something ';
    OWA.cgi_var_val (1): = "other";
    OWA.init_cgi_env (1, owa.cgi_var_name, owa.cgi_var_val);
    / * End initialization * /.

    Of course, the following code will fail with a NO_DATA_FOUND there is no cookie.

    ourCookie: = owa_cookie.get('SESSION1');
    v_session: = ourCookie.vals (1);

    So it is not possible to create a true cookie and retrieve the value of CGI environment or apex not?

    Yes. But the web browser is non-existent. Then, you need create the CGI environment, which would have created the web server, before you call your allowed web code PL/SQL.

    In other words, if your initialization code of CGI should pretend that it is the web server, he received the call from web browser, it received the cookie (s) from the web browser - and now she needs to create the CGI (including cookies) environment for this web browser, and then call the procedure PL/SQL referenced by the browser in the URL, he argued.

  • insert into the table using dynamic data

    Oracle form 6i
    Hai

    I need to insert data into a table. I have generated my data text file with data in a form, now I need to insert data into a table. How can insert my field at that table if it is given in the table, I need to update, and there is no data I need to insert... Pls tell me the solution...

    Concerning

    Srikkanth.M

    Create the trigger of the sur-insert and check the data are thre or not through the value of the primary key in this trigger. If the data is thre then update or it is then do not insert in the same trigger.

    Thank you
    SUN

  • drop and re-create the tablespace

    version 9208
    the requirement must deletes and recreates same tablespace with different data file location, could it cause any problem?

    Published by: DBA2008 on February 18, 2010 15:24

    The problem is that you lose data, which is currently this tablespace (unless export you it before).

    Werner

  • Create the cursor using dynamic query

    Hello

    I declare a query:

    l_query VARCHAR2 (32000): = ' select distinct ' | : P_ITEM | "of OCM_CUSTOMER."

    How can I assign this cursor query?
    I tried, in vain.

    Declare
    l_query VARCHAR2 (32000): = ' select distinct ' | : P_ITEM | "of OCM_CUSTOMER."
    CURSOR l_cur IS l_query;
    Begin
    .......
    End

    Thanks for help on this.

    Hello

    You must use a REF CURSOR for that (there are a few examples in the Oracle documentation). Here is a code example:

    DECLARE
       TYPE EmpCurTyp IS REF CURSOR;
       emp_cv   EmpCurTyp;
       emp_rec  emp%ROWTYPE;
       sql_stmt VARCHAR2(200);
       my_job   VARCHAR2(15) := 'CLERK';
    BEGIN
       sql_stmt := 'SELECT * FROM emp WHERE job = :j';
       OPEN emp_cv FOR sql_stmt USING my_job;
       LOOP
          FETCH emp_cv INTO emp_rec;
          EXIT WHEN emp_cv%NOTFOUND;
          -- process record
       END LOOP;
       CLOSE emp_cv;
    END;
    

    Greetings,
    Roel

    http://roelhartman.blogspot.com/

  • Skip a page and print on the back using PL/SQL?

    Morning people,
    Greetings from Toronto. I have a report that was written in PL/SQL (not Oracle or SQL reports * most) and its job very well. The totals are correct and I have two sets of totals. A total for the Department in particular and, finally, a total of the entire company. The user of course wish the two totals for each same Department if he or she chooses to print only service (using a setting). So, it's not a problem.

    I just want to be the total final (company-wide) on the last page. Now, it is relatively simple in the reports of the Oracle, as well as SQL * more reports where I could probably use Skip. Y at - it a simple way to do or what I must count lines based on pagesize? So, for example, if the size of my page is 53 and my last record Department stops at line 35, I have to insert empty rows using UTF_FILE. Put_line in a FOR loop. This method would probably work ut I wonder if there's ways more interesting or easier to do?

    This issue does not have to decide at this moment and I know its Monday. :-) Any help would be appreciated.

    Concerning
    REDA

    Published by: Raj404261 on June 8, 2009 10:22

    Try:

        -- etc --
        UTL_FILE.FFLUSH (id);
        UTL_FILE.PUT_LINE(id,CHR(12));
        -- Write totals:
        -- etc --
    

    : p

  • Missing cells in the table of dynamic columns

    Hello

    I am creating a table using dynamic columns. Here's an example simplified data that I use:

    < sales >
    ... < drive >
    ... Honda < brand > < / brand >
    ... < color > green < / color >
    ... < / car >
    ... < drive >
    ... Nissan < brand > < / brand >
    ... < color > blue < / color >
    ... < / car >
    ... < drive >
    ... Honda < brand > < / brand >
    ... < color > blue < / color >
    ... < / car >
    < sales >

    I am grouping the brands for the lines, and I want a number of colors as my dynamic column. I find myself with a table that looks like this:

    ----------------------------------------------------------------------------------
    Brand | Blue | Green |
    ----------------------------------------------------------------------------------
    Honda | 1. 1.
    ----------------------------------------------------------------------------------
    Nissan | 1
    --------------------------------------------------------

    Since there is no green Nissan, a cell not created so I find myself with a hole in my table. Ideally, I would want a cell containing 0 to be in this space.
    Is it possible, or to all the least have a cell in this space, so I did not have a table with gaps?

    Thank you!

    Hi cc22

    If you have a look at these. http://winrichman.blogspot.com/search/label/cross%20tab
    you will identify yourself,

    its simple... If this is not the case, let me know.

  • How to insert image from mysql into the table using php and create the checkbox in the table?

    How can I insert image from mysql into the table using php and create the checkbox for each data as a vote? Here is my code...

    WELCOME

    connect_error) {die ("connection failed:".)} $conn-> connect_error); } $sql = "SELECT no, Calon, ID, of course, the Image OF THE candidates." $result = $conn-> Query; If ($resultat-> num_rows > 0) {echo ' '; export data of each line while ($row = $result-> fetch_assoc()) {"echo"}}
    NO Candidate INFO Vote
    " . $row ["no"]. "-" . $row ["Calon"]. "
    -" . $row ['ID']. "
    -" . $row ['class']. "
    "; } ECHO ' ' ;} else {echo '0 results' ;} $conn-> close();?} >

    hope someone can help me because I am a newbie in this program... need to finish this project... Thank you.

    If you have saved the file name in the database, it's pretty simple.

    echo '' . $row['description'] . '';
    

    Is the same for the box:

    echo '';
    

    If you have saved the image file in the database, it is much more complicated. I recommend you store only the file name in the database.

  • Get the 500 error trying to create a table using the REST API

    Hello

    I tried to create a table using the REST API for Business Intelligence Cloud, but I got 500 Internal Server Error for a while now.

    Here are the details that I use to create a table.

    Capture.JPG

    and the json to create the schema that I use is

    [{'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ["ROWID"]}]

    , {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['RELATIONID']},

    {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['ID']}

    , {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['RESPONDEDDATE']},

    {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [255], 'columnName': ['RESPONSE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_CREATEDDATE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['SYS_CREATEDBYID']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_LASTMODIFIEDDATE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['SYS_LASTMODIFIEDBYID']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_SYSTEMMODSTAMP']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [10], 'columnName': ['SYS_ISDELETED']},

    [{'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [50], 'columnName': ['TYPE']}]

    I tried this using postman and code, but I always get the following response error:

    Error 500 - Internal server error

    Of RFC 2068 Hypertext Transfer Protocol - HTTP/1.1:

    10.5.1 500 internal Server Error

    The server encountered an unexpected condition which prevented him from meeting the demand.

    I am able to 'get' existing table schemas, delete the tables, but I'm not able to make put them and post operations. Can someone help me to identify the problem, if there is no fault in my approach.

    Thank you

    Romaric

    I managed to create a table successfully using the API - the only thing I see in your JSON which is different from mine is that you have square brackets around your values JSON where I have not. Here is my CURL request and extract my JSON file (named createtable.txt in the same directory as my CURL executable):

    curl u [email protected]: password UPDATED h x ' X-ID-TENANT-NAME: tenantname ' h ' Content-Type: application/json '-binary data @createtable.txt https://businessintell-tenantname.analytics.us2.oraclecloud.com/dataload/v1/tables/TABLE_TO_CREATE k

    [

    {

    'columnName': 'ID',

    'dataType': 'DECIMAL ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': false

    },

    {

    'columnName': 'NAME',

    'dataType': 'VARCHAR ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    "columnName': 'STATUS."

    'dataType': 'VARCHAR ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    "columnName': 'CREATED_DATE."

    'dataType': 'TIMESTAMP '.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    'columnName': 'UPDATED_DATE ',.

    'dataType': 'TIMESTAMP '.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    }

    ]

  • Create the Table as and hybrid columnar Compression

    I'm looking to connect to tables help to create the table as I had a question about columnar Compression hybrid. For the test, I found that the uncompressed daata will be approximately 10 to and compressed data will be around 1 TB. I anticipate compress the table when the table to create as an instruction and wanted to know in what order Oracle forge do compression, that is, the table will be created then Oracle will compress the data or will the compressed table that the table will be created. The motivation behind the question is to see how much storage I need to complete the operation.

    Thank you

    If you are using
    create table xxx compress for query high what to choose...

    While the data will be compressed before insertion, so in your case, it will use about 1 TB of disk space

Maybe you are looking for

  • Renaming of files with the same file name.

    I got image files files that have been renamed properly with a file name 1234 and they must be 1234.jpg. When I open the file in Photoshop, the name of the file says 1234 .jpg. Can someone help me with an action or Automation (not good at writing, it

  • Qosmio X 300 - 13V stops every time

    My computer laptop toshiba qosmio x 300 - 13v. She stops erverytime...If I'm in the middle of a game or simply get on the internet it quickly stops went al... I have a cooler under the laptop...I don't know what's wrong, but can someone help me what

  • Failure of Windows Vista updates

    Hello. How can I reinstall chess updates to Windows Vista? Any help would be greatly appreciated.

  • Need to reinstall SP1

    TurboTax 2010 trys to stal net framework 3.5 SP1 I've already went and cleaned framework 3.5 3.0 and 2.0 I'm totally lost

  • Add/change the columns of data type (scripting)

    HelloI am writing a script to add default columns and their values in tables. So far, for me, it is possible to add columns to an existing table in the model.Then, I want to add value to the data type. I discovered there is a method called getDataTyp