When attempting to call ctx_ddl.populate_pending on an index of another schema...
call ctx_ddl.populate_pending ('OTHERSCHEMA.INDEX_NAME', null);
... I'm getting an Oracle error:
SQL-Fehler: ORA-20000: Oracle Text error:
DRG-10502: index INDEX_NAME does not exist
When I connect as OTHERSCHEMA user and execute the same statement, everything works fine.
Why does it tell me the index doesn't exist (it does, verified) here?
Am I missing any grants or anything else?
Constraint for proposed solutions: I don't want to have to use 'alter session' as a workaround.
EDIT:
Seems to be a bug in Oracle 11.2. With Oracle 12.1, the statement works fine. Treat the solution below as a workaround for Oracle 11.2.
Solved it with a delegation to a procedure in the target schema:
On target schema 'OTHERSCHEMA'
CREATE OR REPLACE PROCEDURE POPULATE_PENDING_INDEX IS
BEGIN
execute immediate 'call ctx_ddl.populate_pending(''INDEX_NAME'', NULL)';
END;
/
Execute with another schema user:
exec OTHERSCHEMA.POPULATE_PENDING_INDEX
Related
I am trying to solve a task with a dynamic SQL, but facing an issue ora-00900 invalid sql statement.
execute immediate 'alter table my_table set interval (NUMTOYMINTERVAL(1, ''MONTH''))';
However, it works in the anonymous block treating the statement to be executed as a string.
DECLARE
str VARCHAR2 (250) := 'alter table my_table set interval (NUMTOYMINTERVAL(1, ''MONTH''))';
BEGIN
execute immediate str;
END;
So where is the issue in the first case? It looks like with escape quotes, but can’t catch this.
As the error says, execute immediate is not a SQL statement. There is an execute command in some clients - SQL*Plus, SQL Developer, SQLcl and possibly others - which is a shorthand wrapper around an anonymous block; but from the error you don't seem to be using one of those. If you were you'd get ORA-06550 and PLS-0010: Encounter edthe symbol "alter table..." when expecting...
execute immediate is a PL/SQL statement. So it is only valid within a PL/SQL block.
It has no meaning in plain SQL; the only execute in the SQL reference is referring to directory object privileges.
Your alter table doesn't make much sense anyway, not sure if that's supposed to be an update, but if so it isn't say what to set to that interval value. It isn't obvious why you need it to be dynamic either. Possibly that reason and the actual statement have been lost in simplifying for posting your question.
I'm trying to create a DB2 stored procedure that will clear all the data tables and reset the indexes to 0. The creating of the procedure is pretty straightforward, but the issue is that DB2 immediately forgets it exists. What am I doing wrong?
Create a simple script:
create procedure CLEARTABLES()
language sql
BEGIN
commit;
truncate TABLE1 immediate;
truncate TABLE2 immediate;
truncate TABLE3 immediate;
END;
Make sure we can execute it:
GRANT EXECUTE ON PROCEDURE CLEARTABLES TO PUBLIC;
And here is where it all breaks down with No authorized routine named "CLEARTABLES" of type "PROCEDURE" having compatible arguments was found.. SQLCODE=-440, SQLSTATE=42884, DRIVER=4.26.14
CALL CLEARTABLES;
I've also tried execute, but this does not appear to do anything.
EXECUTE CLEARTABLES;
And to prove it exists:
SELECT * FROM SYSIBM.SYSROUTINES s
WHERE s.ROUTINETYPE = 'P' AND s.ROUTINENAME = 'CLEARTABLES'
I feel like I'm missing very obvious here so I've tried a lot of small things like parentheses, no parentheses, lower/upper case etc. I'm using DBeaver and I can see the procedure under Application Objects > Procedures named CLEARTABLES in all caps no parameters, yet DB2 somehow can't find it with the way I'm calling for it.
For a project I've been working on, I had to create 2 tables in Oracle using Tableau's Initial SQL window. I basically need to re-create them each time Tableau does an extract, so would have to drop and re-create them. Only using the 'DROP' statement works, but if the extract fails in the middle of it, then when it re-runs, the tables don't exist, thus it returns an error.
I tried to use the below code which works fine in SQL Developer, but Tableau doesn't seem to accept it.
--Searches and deletes table TABLEAU_LCC_LEAD_TIME if it exists
DECLARE
does_not_exist EXCEPTION;
PRAGMA EXCEPTION_INIT (does_not_exist, -942);
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE TABLEAU_DOC_LEAD_TIMES';
EXCEPTION
WHEN does_not_exist
THEN
NULL;
END;
/
Tableau returns this error
Would you know of any workaround for the "/" in Tableau Initial-SQL for Oracle?
I think use temporary table in Oracle. Not need re-created table. https://oracle-base.com/articles/misc/temporary-tables
While I was inserting data into a table (db2), I got this error:
Message: Operation not allowed for reason code "7" on
table "ELSAG.ICGR1106".. SQLCODE=-668, SQLSTATE=57016, DRIVER=3.50.152,...
when I googled it, I found that the previous ALTER TABLE statement attempted to add a column to a table that has an edit procedure that is defined with row attribute sensitivity. No columns can be added to this table.
Is there is a way to rectify it?
Once I drop and re-create the table I can insert again.
Thanks in advance.
To add to James' answer and save people time looking around, you could execute
CALL SYSPROC.ADMIN_CMD('REORG TABLE MY_TABLE_NAME')
via any available SQL client (i.e. even over ODBC or JDBC connection) to rectify this problem. However, the connection has to be in autocommit mode and you have to have admin privileges to execute this command.
I highly recommend to read the documentation on REORG before calling it.
According to this:
SQL0668
You have done some alteration to the table which requires a REORG before you can further update the table.
Run the REORG utility against the table and you should be OK.
CALL SYSPROC.ADMIN_CMD('REORG TABLE TABLE_NAME') solves the problem
SELECT REORG_PENDING FROM SYSIBMADM.ADMINTABINFO where TABSCHEMA = '<schema_name>' and tabname = '<table_name>';
If above query returns Y
Then run below query:
call sysproc.admin_cmd('reorg table <schema_name>.<table_name>');
For more info visit: SQL0668N Operating not allowed for reason code '7'
I turned off integrity checks on some table and got that error message afterwards when altering data. This here generated the statements which helped:
select 'SET INTEGRITY FOR ' || rtrim(tabname) || ' IMMEDIATE CHECKED;'
from syscat.tables
where CONST_CHECKED like '%N%'
or status != 'N'
or access_mode != 'F'
with ur;
i created a procedure with 32 in argument,it sucessfully created.but when i am executing this in back end oracle the errror came ORA:00900 Invalid sql statement
Use:
SQL> alter procedure [your procedure name here] compile;
SQL> show errors
...to be able to diagnose the issue from the resulting error output.
Also look at view USER_ERRORS.
Sometimes, show errors does not show anything when in fact there are errors. Especially after alter compile.
Finally, re-compile in TOAD or SQL Developer and you can easily navigate to the error.
In Oracle SQL Developer you should execute it this way:
BEGIN
YOUR_PROCEDURE(PARAM1, PARAM2);
END;
If you use EXECUTE or EXEC (which work in SqlPlus) you get the ORA-00900 error.