Of FUNDING and dynamic SQL CREATE ANY TABLE

Hi gurus,

I have a dynamic SQL code in a procedure where a table to an existing table without data will be created.

strSQL: = "create table ' | strTemp | ' in select * from '. strArc. "where 1 = 2"; "
Execute immediate strSQL;


without GRANT CREATE ANY TABLE to user, * "ORA-01031: insufficient privileges" * error executing. "."

Is there a way to tackle this problem without providing a GRANT CREATE ANY TABLE privileged?


Thank you very much
Charles

(1) why you are creating a table to run? Which seems to me very concerning. If you create a temporary table and you're accustomed to work how temporary tables in other databases, I would strongly suggest you look at how Oracle manages global temporary tables. If temporary storage is really necessary (99% of the time is not because of the consistent reading multi-version), you should be able to create global temporary tables a few during execution.

(2) the owner of the procedure should just need the CREATE TABLE privilege granted directly to the user (not granted through a role), assuming that it is in stored procedure a standard DEFINER rights.

Justin

Tags: Database

Similar Questions

  • Audit to create any table

    SQL > select * from v version $;

    BANNER

    --------------------------------------------------------------------------------

    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

    PL/SQL Release 11.2.0.1.0 - Production

    CORE 11.2.0.1.0 Production

    AMT for 32-bit Windows: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    SQL > select audit_option in the dba_stmt_audit_opts;

    no selected line

    SQL > see the parameter checking.

    VALUE OF TYPE NAME

    ------------------------------------ ----------- ------------------------------

    audit_file_dest string C:\APP\ADMINISTRATOR\ADMIN\ORC

    L\ADUMP

    audit_sys_operations boolean FALSE

    AUDIT_TRAIL DB string

    SQL > select count (*) in the dba_audit_trail;

    COUNT (*)

    ----------

    4132

    SQL > audit create any table Scott.

    Verification succeeded.

    SQL > select audit_option in the dba_stmt_audit_opts;

    AUDIT_OPTION

    ----------------------------------------

    CREATE A TABLE

    SQL > create table dummy (a number);

    Table created.

    SQL > insert into values dummy (1);

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL > select count (*) in the dba_audit_trail;

    COUNT (*)

    ----------

    4132

    SQL >

    So, my question is why I see no + 1 in dba_audit_trail while the user scott has been audit to create any table that is before activation of the audit and creating the table there are 4132 lines in dba_audit_trail and they are same even after activation of the audit and create the table. Kindly help me to understand.

    Thank you.

    It seems the user scott created table in its own schema, you must check create table as well.

    Thank you

    Bigot

  • GRANT CREATE ANY TABLE

    Hello
    in 10g,.
    If I have:
    GRANT CREATE ANY TABLE to user1;
    then:
    1 - user1 can create a table in any schema and remove any table in any schema?

    2-can we user1 create a table in any schema and drop any table from only its own schema?

    Thank you.

    just give a try if you have a test database.

  • Difference between the static SQL query and dynamic SQL query.

    Hello

    Please explain the fundamental difference between static and dynamic sql queries. Please explain for example.

    Static: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/static.htm
    Dynamics: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm

  • How to count the amount of toys that every boy has (without creating any table)?

    For example, there are 3 boys (boy, a boy b, boy c) and 2 types of toys (A toy, toy B).

    Insert the following records:

    (boy a, A toy)

    (boy a toy B)

    (boy a toy B)

    (boy b, a toy)

    So I expect to get the following statistics:


    A toy
    Toy B
    Boy one12
    b Boy10
    c boy00

    Notice 1: The list of boys and the list of the toy_kind are determined, that is, I can generate the phrase sql in c#, using the two lists.

    Notice 2: I wish that all the columns appeared, even if a column is made up of 0. If a row of 0 as 'boy c' is displayed or not has no importance.

    How to do this WITHOUT creating tables? Use sql or a procedure are OK. I had to use the result in c# to add the table to Word.

    Thank you!

    These data are stored in a table already?

    You say "without creating table", but we don't know what that makes reference.

    You are looking for something like this?

    SQL > with boys like (select "boy a ' as a boy all the double union")
    2 Select 'b boy' union double all the
    3 select 'boy c' double
    4               )
    5, boys_toys as (select ' boy a "boy,"A toy"as any double union toy")
    6 select 'boy a', 'toy B' from dual union all
    7 if he would choose "a boy ', 'toy B' dual Union all"
    8 select 'boy b', 'A Toy' go two
    9                    )
    10-
    11 - the end of test data
    12-
    13. Select boys.boy
    14, sum (case when toy = 'toy A' then 1 else 0 end) as the toyA
    15, sum (case when toy = ' toy B' then 1 else 0 ") as toyB
    boys 16
    17 left outer join (boys_toys.boy = boys.boy) boys_toys
    Group 18 by boys.boy
    19 order by 1
    20.
    TOYA TOYB BOY
    ----- ---------- ----------
    boy's 1 2
    Boy b 1 0
    Boy c 0 0

    3 selected lines.

  • bind variables and dynamic sql

    Hi all

    Here's my situation:

    I have a query with 2 bind variable: the FROM clause also uses a variable binding!

    PROCEDURE describe_columns(p_curr_tablename VARCHAR(50), p_curr_intentseq NUMBER)
       IS
          l_cur     INTEGER;
          l_query   VARCHAR (100);
       BEGIN
          l_query :=
             'select * from :table_name where ibmsnap_intentseq = :sequencenr';
          l_cur := DBMS_SQL.OPEN_CURSOR;
          DBMS_OUTPUT.PUT_LINE (p_curr_tablename);
          DBMS_OUTPUT.PUT_LINE (p_curr_intentseq);
          DBMS_OUTPUT.PUT_LINE (l_query);
          DBMS_SQL.PARSE (l_cur, l_query, DBMS_SQL.V7);
          DBMS_SQL.bind_variable (l_cur, ':table_name', p_curr_tablename);
          DBMS_SQL.bind_variable (l_cur, ':sequencenr', p_curr_intentseq);
          DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
          DBMS_SQL.CLOSE_CURSOR (l_cur);
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.put_line ('DF-EXCEPTION: ' || SQLERRM);
             DBMS_OUTPUT.put_line (
                'DF-EXCEPTION: ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
             );
    
             IF DBMS_SQL.IS_OPEN (l_cur)
             THEN
                DBMS_SQL.CLOSE_CURSOR (l_cur);
             END IF;
       --         RAISE;
       END;
    and the output is:
    CD_B136V4_NEW
    16
     select * from :table_name where ibmsnap_intentseq = :intentseq
    DF-EXCEPTION: ORA-00903: invalid table name
    DF-EXCEPTION: ORA-06512: in "SYS.DBMS_SYS_SQL", line 906
    So is the problem that I want to use a variable binding for the name of the table?

    I'd appreciate any help!
    Thank you!

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:227413938857

    Identifiers cannot be used as variable bind - never. Identifiers must be "hard-coded".
    in the query.

    I can't put in a link for "emp" variable because I can't use a string
    constant for emp.

    The reason is quite simple - a bind variable query is parsed and optimized once
    variables are evaluated before linking. If I could code:

    Select * from: bind_x

    the optimzer would not have an idea of what will come with, security (access rights)
    could be evaluated and so on. We could not develop a plan for this query - not
    enough information. Therefore, no variable bind for identifiers.

  • 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

  • Oracle 11g R2, CREATE THE TABLE and QUOTAS

    Hi all
    I need some insight on a strange behavior, that I discovered in Oracle 11 g 2. Don't know if I'm missing something or if I just discovered a security issue with Oracle.

    Oracle Version: 11.2.0.1.0

    The problem is with the CREATE TABLE and the QUOTA on the specific tablespace privilege.

    Please, try this on your system (if you have some free time and care to confirm the "bug").

    Create a user, grant privileges than two, CREATE THE SESSION and CREATE TABLE.

    Grant NO quota on any tablespace.

    Try to create a table on any tablespace (except SYSTEM) and everybody say if it worked or not.

    The oracle documentation provides the following:

    To create a relational table in your own schema, you must have the CREATE TABLE system privilege. To create a table in the schema of another user, you must have the CREATE ANY TABLE system privilege. In addition, the owner of the schema containing the table must have a quota of space on the tablespace contains the table or the UNLIMITED TABLESPACE system privilege.

    [http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_7002.htm#SQLRF01402]

    The fact is, so far, on two different instances of Oracle 11 g 2, my users are not limited in the creation of the tables only when they have quotas, but where they want to, except the STRING.

    The behavior correct would be to deny the creation of the table the tablespace where there is no quota, but it does not work.

    My instance of Oracle 10 g behave properly and therefore the creation of the table is denied the tablespace with no quota.

    P.s1 sorry if this a well known "bug/problem/question". I've been ridiculous on a well-known forum for the same question. I don't need to be "filled spoon" as shown on this famous site! I have read the documentation! I googled a lot!

    P.s2 even if the creative work of table on tablespace with no quota, you cannot insert data into it. Yes, big picture, the user cannot not filled space with irrelevant data tables, but it can create thousands of tables...!

    Did I miss something?
    Is there a 'default' option I have to mark to prevent the creation of the table where it shouldn't?
    ? (?)

    Please read http://tkyte.blogspot.com/2011/02/deferred-segment-creation.html.

  • : SQL error create temporary table

    I do a small Forum of discussion for a customer.

    So having a problem below:

    Internal error.
    tNG_fields.getFakeRecordset:
    SQL error: error creating temporary table:
    Você tem um erro syntax no seu proximo a SQL '-TEXT messaging, cidade idade foto senha, TEXT TEXT TEXT TEXT of COD)' na linha 1
    SQL:
    CREATE TEMPORARY TABLE KT_fakeRS_20090928 (nome cidade of TEXT, text, TEXT, TEXT, TEXT, TEXT, TEXT of cod senha foto idade) (FIELDS_FAKE_RS_ERROR)
    • tNG_insert.executeTransaction
      • STARTER. Trigger_Default_Starter
    • tNG_insert.getRecordset
    • tNG_insert.getLocalRecordset
    • tNG_insert.getFakeRecordset*


    Please help me solve this problem.



    Can´t you have the hyphen (-) in the column names and that s why MySQL chokes on the column 'email '. That said, please rename this column 'e-mail' or 'email' (underscores are allowed)

    See you soon,.

    Günter

  • Creating a table to a csv file

    I use the JDeveloper 11.1.1.6.

    I'm looking to recover data to a .csv file and load it into a custom table made just for the data in the file.

    I managed to load the csv file in a data control with a Service URL data control. I wonder how to take data from the data control and place it in a Java object so that I can make the dynamic creation of sql create statement table. I know how to do dynamic creation - it's just to access the data of the data control to which I am at this point.

    If there is a better way to do it, I would be also open to it! Thank you!

    Published by: Jim W. 26 September 2012 08:00

    I found this documentation. Is not myself. The documentation is newer than your version, so it may not work.

    http://docs.Oracle.com/CD/E24382_01/Web.1112/e16182/bcquerying.htm

    Stuart

  • Dynamic SQL in APEX

    Hey everyone, I'm trying to understand how to use dynamic sql statements in Application Express. Specifically, I'm trying to write a query using substitution/bind variables. I don't know if you need a description of the application or not, but here's the query that will run in sqlplus:
    ACCEPT     file_id     PROMPT     "Enter the file_id (a number, e.g. 3): "
     
    -- Preliminary Query, to set table_name
     
    COLUMN     reference_id_col     NEW_VALUE     reference_id
    COLUMN     table_name_col     NEW_VALUE     table_name
     
    SELECT  f.reference_id          AS reference_id_col
    ,           t.reference_table       AS table_name_col
    FROM      aa_files     f
    JOIN     aa_type     t     ON     f.file_type     = t.type_id
    WHERE     f.file_id     = &file_id
    ;
     
    --     Main Query
     
    SELECT  * 
    FROM     &table_name
    WHERE      reference_id     = &reference_id
    ;
    There are three substitution variables, reference_id & file_id and & table_name. My basic setup is that I have a table full of table names, so I ask her to get a table name in a variable, then query this table for my data.

    I work inside the window of SQL commands to try to find the proper syntax to make this work in the APEX. I'm pretty sure that APEX does not allow the use of substitution variables, because they are one thing on the side of client SQL more right?

    I'm still a student, so I'm not known and Oracle Application Express, but reading the documentation of the APEX and the Googling, I tell myself that bind variable should be able to do this for me, but I don't know how. I searched for some examples or documentation on the use of dynamic SQL statements in the APEX, but I could not find anything. I'm sure I could do this using a PL/SQL block, but I'd rather do it in pure SQL if possible.

    So if someone could help me or giving me an example of syntax I would have to use to write a query that is running in Application Express, or could direct me to the literature on the use of dynamic sql statements in Application Express, it would be greatly appreciated!

    If you need more information on my application, I can post my create table statements and some inserts sample data, if that would be helpful.

    Thank you!

    Published by: username, June 21, 2010 07:34

    OK, so one of the great things about SQL is your ability to choose what columns you want to include in your result set. You don't have to use all of them. You can do this in two ways: with dynamic SQL or individual areas for each type of file. This will depend on your use as to how many types different files will be added each day on which you want to go with.

    If you go with dynamic SQL (and because you don't know until run time what columns you want to use, it is an appropriate use), you will need to build your query based on the file type. Something like this:

    declare
      qry_type  VARCHAR2(10);
      sql_qry    VARCHAR2(4000);
      qry_select  VARCHAR2(500);
      qry_from   VARCHAR2(100);
      qry_where  VARCHAR2(400);
      qry_order   VARCHAR2(100);
    begin
      qry_type  :=  :PX_QRY_TYPE;
      --Build the SELECT clause
      qry_select   := 'select a.FILE_NAME, a.FILE_NAME, a.FILE_TYPE, a.LOCATION';
      CASE qry_type
         WHEN 'PDF' THEN qry_select   := qry_select || ', pdf.DATE_MODIFIED, pdf.SUMMARY, pdf.AUTHOR';
         WHEN 'XLS' THEN qry_select   := qry_select || ', xls.DATE_MODIFIED, xls.SUMMARY, xls.TOTAL_VALUE';
         ...
      END CASE;
      --Build the FROM clause
      qry_from    := ' from AA_FILE a, AA_FILETYPE_PDF pdf, AA_FILETYPE_XLS xls, AA_FILETYPE_PHOTO p';
      --Build the WHERE clause
      qry_where  := ' where a.FILE_ID = pdf.FILE_ID (+)';
      qry_where  := qry_where || ' and a.FILE_ID = xls.FILE_ID (+)';
      qry_where  := qry_where || ' and a.FILE_ID = p.FILE_ID (+)';
      --Build the ORDER BY clause
      qry_order  := '';
      --Put it all together
      sql_qry   := qry_select || qry_from || qry_where || qry_order;
      EXECUTE IMMEDIATE sql_qry;
      ...
    end;
    

    Now this does not cover the addition of new file types. I still think you're going to be better off planning for as much as you can and handle manually creating additional tables, but this is going to be to you. I know you are trying to generate code to do everything for you, but when it comes to databases, I found that the creation of objects can quickly become uncontrolled if you're not very careful. These are going to be permanent, not temporary memory built database objects. Just a word of warning.

    If you decide to go with a region and by file type, it does not require nearly as much work. Simply create a report region based on the view and set the conditional display based on your file type.

      select * from V_FILES_PHOTO
       where FILE_ID = :PX_FILE_ID;
    
    condition:  FILE_TYPE = 'PDF'
    

    While you will need to add a region again every time that you add a new file type, once again, the question that arises is: file types how are you really going to have to worry? If you're talking about a dozen, I would like to do things manually. If you're talking about a hundred, it's maybe worth trying to find a method of programming. It is your call to make.

  • A loop dynamic sql in the procedure

    Hi guys,.

    I'm having a procedure that will have two input start_date and end_date parameters

    I need a loop in alter procedure statement something like this using dynamic sql


    CHANGE TABLE M1

    SWAP PARTITION FOR (TO_DATE('01-JAN-2015','dd-MON-yyyy'))

    WITH TABLE T2

    INCLUDING THE INDEX;

    CHANGE TABLE M1

    BY EXCHANGE COMPETITION FOR (TO_DATE('02-JAN-2015','dd-MON-yyyy'))

    WITH TABLE T3

    INCLUDING THE INDEX;

    .

    .

    .


    For example I have dates in setting something like January 1, 2015-4 January 2015

    I need something like this, where T is a constant variable, I need to add T1, T2. T3 according to the dates of the range.

    Hello

    your procedure can not simply be rolled up, but the call session can be rolled up the output to a file.

    Try something like this

    col act_date noprint new_value act_date
    
    SET TERMOUT  OFF
    
    select to_char(sysdate, 'yyyy_mm_dd_hh24miss') act_date
      from dual;
    
    SET TERMOUT      ON
    set serveroutput on
    set feedback     off
    set linesize     3000
    
    col statement for a200 heading "-- alter statements"
    
    spool d:\temp\&act_date._&_CONNECT_IDENTIFIER._alter_partition.sql
    
    -- exec your_procedure
    
    -- or simple plain sql
    
    with data (start_date, end_date) as (
      select to_date('01/01/2016', 'dd/mm/yyyy'),
            to_date('05/01/2016', 'dd/mm/yyyy')
        from dual
        )
    select --level, to_char(start_date + (level - 1), 'dd-MON-yyyy' ) cur_date
                     'ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE(''' || to_char(start_date + (level - 1), 'dd-MON-yyyy' ) || ''',''dd-MON-yyyy'')) WITH TABLE T2 INCLUDING INDEXES;'
      || chr(10) ||  'ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE(''' || to_char(start_date + (level - 1), 'dd-MON-yyyy' ) || ''',''dd-MON-yyyy'')) WITH TABLE T3 INCLUDING INDEXES;'  as statement
      from data
    connect by level <= end_date - start_date + 1;
    
    spool off
    
    set feedback    on
    
    prompt @d:\temp\mk_alter.sql
    

    concerning
    Kay

  • Using createTextField in a loop to create a table

    Hi, I was looking everywhere and through my book, trying to find a way to make a table of textfields. I have 3 tables that are received through a Pearl script and need to create a table to display the 3 tables. The size of the tables always varies the table must be able to adapt to the size.

    I was thinking something in the sense of

    This.createTextField("hello_txt",0,10,10,100,20) ("title_text", this.getNextHighestDepth (), 10, 10, 300, 100);
    title_text. Multiline = false;
    title_text.WordWrap = false;
    title_text. Text = title;
    title_text.setTextFormat (title_fmt);

    I tried to do inside loops using the number of the loop under the title of the textfield object when it was created, but then I can't find a way to reference and assign the .text.

    Any help would be great, or if there is a different command to use that would work better than createTextField, I'm still pretty new flash and actionscript.

    Thanks in advance.

    You can always just use a datagrid for this. It adds to the size of your file, but it also looks good, scrolls AND is sortable and resizable accepts arrays as dataproviders. That being said, you can reference your clip as follows:

  • How to create a table with a variable

    Hello world!

    I have a procedure that receives a table as parameter name and need to create a table using this name

    For example:

    PROCEDURE REFRESH_REPORTS (table_name varchar2) IS

    BEGIN
    table_name_REPORT: = table_name;

    run immediately "create table table_name_REPORT...

    But I don't get this job. I'm just add this procedure as part of a package that is used for online/web declarations.

    Could someone guide me how can I create this table?

    I was getting errors such as invalid table name, and I even tried to use a variable that stores the SQL full and concatenated to the name of the table variable, but still that didn't work.

    Thank you so much in advance.

    Nithya

    Published by: user645399 on January 20, 2010 21:42

    You need create a valid SQL statement in the string. And if you want to add variables in this chain, do you this through the concatenation or replacement.

    For example using concatenation

    declare
      tableName varchar2(30);
      sqlCreate varchar2(1000);
    begin
      tableName := 'funky_foo';
      sqlCreate := 'create table '||tableName||' as select * from foo@remotedb';
      -- using dbms_output to enable the display of the SQL that is about to be executed
      execute immediate sqlCreate;
    end;
    

    For example using replacement (better option than the SQL syntax is more easily readable and maintainable and allows several variables to set in the SQL model)

    declare
      SQL_CREATE_TEMPLATE constant varchar2(1000) :=
    'select
       *
    from $TABLE@remotedb';
    
      tableName varchar2(30);
      sqlCreate varchar2(1000);
    begin
      tableName := 'funky_foo';
      sqlCreate := replace( SQL_CREATE_TEMPLATE, '$TABLE', tableName );
      -- using dbms_output to enable the display of the SQL that is about to be executed
      execute immediate sqlCreate;
    end;
    
  • Create table form another table in different schema throwing error when dynamic sql

    Hello

    With the help of 11.2.0.3 and was following the issue.

    To create a table in a schema (b) using data from another schema (b)

    If independent run in sqlplus create works OK but same sql in dynamic sql block saying the table or view does not exist.

    SQL even in dynamic sql

    {code}

    v_sql: =' create table new_table in select * from schemab.table_name where...';

    run immediately (v_sql);

    [code}

    Other tables work fine.

    Any ideas - don't want to grant all the schemaa.table schema b if can avoid.

    Thank you

    You run the immediate execution in an anonymous block or a stored procedure?  If it is a stored procedure, then as others have said, the owner of the procedure must have select privileges on granted directly schemab.table_name.

    Another possibility, which would be the case for a stored procedure, or an anonymous block is that your code is something like:

    v_sql: =' create table new_table in select * from schemab.table_name where...';

    immediately run v_sql;

    Select count (*) in the l_count new_table;

    who will fail at compile time because new_table does not exist.

    When you create objects using dynamic sqly you dynamic sql user to reference them in the block of code.

    John

Maybe you are looking for