dynamic SQL to drop the indexes on the table
Hello worldPlease tell me how to remove the indexes on a table by using a dynamic sql code
for example, I have a dummy table with two index idx1, idx2
I need a procedure or a function where I will be passing in the name of the table, the function/procedure should remove the indexes on the table
Thank you
Not tested:
create or replace
procedure drop_indexes_of_table(p_table_owner varchar2,
p_table_name varchar2)
as
cursor c_drop_statements is
select 'drop index '||owner||'.'||index_name stmt
from all_indexes
where table_owner=p_table_owner
and table_name=p_table_name;
begin
for r in c_drop_statements loop
execute immediate r.stmt;
end loop;
end;
Tags: Database
Similar Questions
-
insufficient privileges when using dynamic sql statements in the procedure
Hello
I use following script on oracle 10g. and get the error not enough privs. Please advice.
SQL > show user
The user is 'GRSADM '.
SQL > create or replace procedure grsadm.test_proc as
a varchar2 (2000);
Start
a: =' VIEW to CREATE or REPLACE
TEST_VIEW
IN SELECT
"FLAS" one
THE DOUBLE ';
immediately run one;
end;
Created procedure.
SQL > start
grsadm.test_proc;
end;
Start
grsadm.test_proc;
end;
Error on line 16
ORA-01031: insufficient privileges
ORA-06512: at "GRSADM. TEST_PROC', line 9
ORA-06512: at line 2
SQL > select * from session_privs
where the privilege as "VIEW %.
PRIVILEGE
----------------------------------------
CREATE A VIEW
REMOVE ANY VIEW
CREATE A MATERIALIZED VIEW
MODIFY A MATERIALIZED VIEW
REMOVE ANY MATERIALIZED VIEW
5 selected lines.
Published by: Rous Sharma on November 24, 2011 12:00GRSADM has a privilege ' CREATE (all) VIEW ' live?
And not via a role...SSM
Samir,
GRSADM is the owner of this procedure, it seems that the EXECUTE priv, that you suggested is already involved. -
Dynamic SQL query in the DB adapter
Hello
I want to use the following custom SQL query in the DB adapter:
SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)
the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case
Thank you
SunilUse the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)
Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)
Thank you
-Sreeny -
How to dynamically add columns to the table
Hi all
I'm new to ADF and need help on sub condition.
We have created a ViewObject on the EMPLOYEE table that has under columns:
EMP_ID,
EMP_NAME,
DEPARTMENT,
COST_CENTER,
BUSINESS_UNIT
COUNTRY
GCODE
We need to create a page in the ADF with employee table to show only below the columns
EMP_ID,
EMP_NAME,
DEPARTMENT,
COST_CENTER
Later, if necessary user should be able to add other columns to the page dynamically.
Can you please advice on how to implement this feature.
Thank you.
Kind regards
Vidya
Hello.
There could be a simple solution, which is to use the component PanelCollection.
Drag ' drop your VO to a page and create a Table with all the attributes.
For columns that emp_id, emp_name, cost_center, set the Visible property to false.
Put the PanelCollection component on your page and drag your table inside.
When you run the page you will see the view menu in the upper left corner of the table above. You can show/hide columns in this menu.
-
The versions are Oracle 11.2.0.1.0 and Developer SQL 4.0.0.12 on Windows 7 Ultimate SP1.
Hello
I am training CBT Nuggets SQL basics (video #11) and cannot delete a table that I just created. The command and the error are:
drop table newprods;
Error starting line: 1 at the controls.
drop table newprods
Error report-
SQL error: ORA-00604: error occurred at the SQL level 1 recursive
ORA-20000: cannot delete the object
ORA-06512: at line 2
00604 00000 - "an error occurred at the SQL level recursive %s.
* Cause: An error occurred during the processing of a recursive SQL statement
(a statement applicable to dictionary tables inside).
* Action: If the situation described by the following error stack
can be corrected, to do so; otherwise contact Oracle Support.
As the HR user, I created two tables and created a FK constraint between them. After truncating the table with this FK, I am unable to drop. Even if I remove the FK, the error is the same. Issing the command in SQL * Plus gives the same error.
This is the first time that I have created a table from Oracle installation on this machine and is my first attempt to delete a table. I did not create sequences, triggers, or views based on these newly created tables.
Someone at - it ideas?
See you soon
-
dynamically create columns of the table...
I have three tables
'DQ_SUMMARY' with column (ATTRIBUTE_NAME, OWNER)
"di_proposition" with a single column (PROP_NAME) and have values (MP, upward, AP)
"dq_parameter" with a single column (PARAMETER) and have values (TOTAL_RECORDS, TOTAL_DEFECT, DQ)
now I want to add the new column in "DQ_SUMMARY" of the combination of the values of table 'di_proposition' & 'dq_parameter '.
that is now "DQ_SUMMARY" have & I want to add the new column name and column (ATTRIBUTE_NAME, OWNER)
MP_TOTAL_DRECORDS, MP_TOTAL_DEFECT, MP_DQ, UP_ (TOTAL_RECORDS...
If they are already present in 'DQ_SUMMARY', create not and if not then create.
& If I add a new value in the table 'di_proposition' & 'dq_parameter', then it also adds columns to the values
I write the code below but further, I'm not able.
pls help me...
create or replace
PROCEDURE DQ_SUMMARY_REPORT
AS
CURSOR cur_user_tab_cols
IS SELECT column_name
Of user_tab_cols
WHERE column_name = 'DQ_SUMMARY ';
CURSOR cur_di_proposition
IS SELECT pro_name
OF di_proposition
WHERE pro_name = 'MPLS;
CURSOR cur_dq_parameter
IS SELECT Parameter_name
OF dq_parameter;
BEGIN
INSERT INTO dq_summary (ATTRIBUTE_NAME, ENTITY_NAME)
SELECT a.ATTRIBUTE_NAME, b.ENTITY_NAME
DI_ATTRIBUTE_MASTER a, DI_ENTITY_MASTER b
WHERE a.entity_id = b.entity_id;
FOR c_prop IN cur_di_proposition
LOOP
FOR c_para IN cur_dq_parameter
LOOP
IF c_prop.pro_name |' _'. c_para.parameter_name
END DQ_SUMMARY_REPORT;CURSOR cur_user_tab_cols IS SELECT column_name FROM user_tab_cols WHERE column_name = 'DQ_SUMMARY';
change the condition WHERE table_name = 'DQ_SUMMARY ';
-
SQL query for the table in the schema
Hi user;
Imagine that we have 10 schema in oracle db. I wonder all the name of the table as shcema A1. I want to find these tables name everything first (let us suppose schema A1 has 100,000 tables)
Then, I want to give select grant the user A for these 100,000 tables. I don't want to use grant any table. I just want to give A user to select right for tables (100,000) which is under schema A1. How can I do? Please give me some ideas or the path
Thank youAAAAA says:
Hi Nicholas.Its system of prod and I'm afraid to be confused :)
Yes, I understand very well you're scared, then why not you plan some tests in front on a dummy database?
Nicolas.
-
ORA-14452 attempts to create, alter or drop an index on a table temporary alr
I'm trying to edit a column in my global temporary table.
When I try to run the query, I get this error...
ORA-14452: try to create, alter or drop an index on a temporary table already in use
It is the solution that I found in google.
Action: All sessions using the session-specific temporary table must truncate table and all transactions using the specific temporary table have to end their operations in transaction.
How can I make sure that the transaction is complete
or what is the best way to solve this problem?
Thank youTell everyone to disconnect from the database. If they won't come out and it is a change of mission critical and killing their session will have undesirable consequences for the data, and then kill their sessions. Hell you could bounce back just the database, that everyone will come out and then don't open it back to connections non s/n until your done with your DOF on the TWG. Of course, you probably want to do during a scheduled maintenance window if it is a production environment because it tends to make people grumpy when you surreptitiously gives them the boot.
Depends on the importance, it's to make the change, on the other hand, the importance is keeping your DB online and/or your connected users.
-
How to integrate the dynamic SQL generated in the data definition XML file?
Hi all
I have it here is the XML file that is attached to the definition of data model RTF as below. Also, I have a function that will return to create a dynamic query as shown below.
<?xml version="1.0" encoding="UTF-8"?> <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0"> <dataQuery> <sqlStatement name="Q2"> <![CDATA[
-
PL/dynamic sql to retrieve the data from the production server
Hello
I need to create a dynamic pl/sql program to retrieve all packages from the production server and store it on my local machine in another file.
Thanks in advance.Hello
user9963922 wrote:
Hi Peter,.Thanks for the reply.
I need make my block dynamic while in a single query, for different packages I can save it in another file with the same name as the package on my local machine.What is the problem with the suggestion of Peter? This is not 'dynamic' on this subject?
To save the code in the files, use utl_file. Inside the loop, open, write, and close a file. If you need help, your zip code and a description of the specific problem.It is also possible to use only user_source table to accomplish the task.
Yes, but it doesn't work for you own schema.
If you do not use user_source, then you will not need any condition asand owner in ('
') -
SQL - restructuring of the Table
Hello world
I hope that this is possible in Oracle. I need to restructure a followingly table. I appreciate all of your time.
With the help of 10 or 11 g
ResultPCP MEASURE SUCCESS TOTAL P001 A 2 3 P001 B 3 4 P001 C 4 5 P001 D 5 6 P001 E 6 7 P002 A 7 8 P002 B 8 9 P002 C 9 10 P002 D 10 11 P002 E 11 12 P003 C 12 13 P003 D 13 14
Published by: 788729 on October 26, 2011 13:42PCP A B C D E FLAG P001 2 3 4 5 6 SUCCESS P001 3 4 5 6 7 TOTAL P002 7 8 9 10 11 SUCCESS P002 8 9 10 11 12 TOTAL P003 0 0 12 13 0 SUCCESS P003 0 0 13 14 0 TOTAL
Hello
Assuming you are wanting to do using a query, you can go (using 10 G)...
select pcp, nvl(max(a),0) as a, nvl(max(b),0) as b, nvl(max(c),0) as c, nvl(max(d),0) as d, nvl(max(e),0) as e, flag from ( select pcp, case when measure = 'A' then success end as a, case when measure = 'B' then success end as b, case when measure = 'C' then success end as c, case when measure = 'D' then success end as d, case when measure = 'E' then success end as e, 'SUCCESS' as flag from temptable union all select pcp, case when measure = 'A' then total end as a, case when measure = 'B' then total end as b, case when measure = 'C' then total end as c, case when measure = 'D' then total end as d, case when measure = 'E' then total end as e, 'TOTAL' as flag from temptable ) group by pcp, flag order by pcp, flag
Hope this helps,
MarkPublished by: user455268 on October 26, 2011 16:15
-
HI -.
Here is the configuration:
I have a basic table that has 6 values in there (i.e. the tabs).
The tabs are generated without problem and when I discover things six show. For example:
Video clip: frame = 1 Target = "_level0.tabsMC6"
so it's cool.
Now when I go to configure the action of button for these babies, if I use the _level0.tabs.MC6 so that I can trigger button available for this tab or one if I change the value of tabsMC. What I want to do is to try to reduce the code and have an increase in value of tab, but the best I could achieve is to have the last work in the tab. What is interesting is that if I try an other tabs (1-5) they are all trigger tab #6.
What I have right now is:
function tabCount (): Void {}
for (i = 0; i < _root.slideContainerMC.tabList.length; i ++) {}
_level0 ["tabsMC" + i].clickerMC.onRollOver = function() {}
_level0 ["tabsMC" + i].gotoAndStop("on");
}
}
};(Note: tabList is the picture I mentioned above and Yes, in an another MC, which = code in every sense but I'm in a hurry)
I need guidance is how to get all the tabs for the actions of the individual buttons. I thought that the script above woul have then button actions for
tabsMC1
tabsMC2
tabsMC3
tabsMC4
tabsMC5
tabsMC6
what it does exactly. tabsMC6 is the only tab that will show you the status 'on' - I can ride on one of them, and it's the only tab that says this rather than EACH tab showing a State.
Looks like I'm missing what is obvious!
Thank you!
you define tabMC0,..., tabMC5. If you want tabMC1,..., tabMC6 use:
function tabCount (): Void {}
for (i = 1; i<=_root.slideContainerMC.tabList.length; i++)="">=_root.slideContainerMC.tabList.length;>_level0 ["tabsMC" + i] .ivar = i;
_level0 ["tabsMC" + i].clickerMC.onRollOver = function() {}
This._parent.gotoAndStop("on");
}
_level0 ["tabsMC" + i].clickerMC.onRollOut = function() {}
This._parent.gotoAndStop ("OFF");
}
_level0 ["tabsMC" + i].clickerMC.onRelease = function() {}
This._parent.gotoAndStop ("delivery");
}
}
};and the ivar part provided that you would need the ith tab to know that it is the ith tab. Ivar stores that I have the value used when this particular tabMC was created. If you don't need that, delete it.
-
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
-
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 privilegesWhat 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
-
Tables created in a stored procedure cannot be used with dynamic SQL? The impact?
There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?
If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).
In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?
Thank you and best regards,
Amedeo.
Published by: AGF on March 17, 2009 10:51AGF says:
Hi, Frank.Thank you for your response. I understand that the dynamic SQL is required in this context.
Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.
In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.
I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.
The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).
If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.
With the TWG, you have none of these issues.
Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)
When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.
Another risk of dynamic query is SQL injection which may result in a security risk on the database.
Good programming will have little need for the tables of dynamically created dynamically or SQL.
Maybe you are looking for
-
Microsoft Outlook: Microsoft Outlook app
Hello everyone. When I try to open MS Outlook, I get an error that it cannot open the pst file. I tried to follow the other instructions for older versions - for example deleting the reference of pst file. But when I try to open again the file is re
-
Cannot open the database: TrueSuite Access Manager
Whenever I try to record fingerprints in TrueSuite Access Manager, I get an error indicating that it was unable to open the database.
-
Where is my Windows XP key?
Telephone support at HP and M$ was useless on this issue. Also, filed a case with CV and got some of the canned response and then dismissed my case. Then I'll try the forums. I am trying to create an image for cloning Windows XP in my small office.
-
I have a computer running Symantec Endpoint protection and WSUS. It is Win 2008 R2. MS11-011 update has been applied, and now in the Server Manager I get an error when viewing roles or features. Needless to say, I can't access WSUS through Server Man
-
Original title: java question. I'm trying to access the Citrix server to access my work server. When I click on an application, I get an error message: your browser must have Java enabled to use the Client for Java. I checked and the right version