Can't create Oracle Text index with sync (every...) - sql

I'm trying to create an Oracle text index on a CLOB column in a table but whenever I try to specify the sync parameter as 'SYNC (EVERY "(sysdate+30/24/60/60)")' it fails with some errors about having insufficient privileges.
The tables is defined as:
CREATE TABLE MESSAGE
(
MESSAGE_ID NUMBER(19,0),
FROM NUMBER(19,0),
TO NUMBER(19,0),
RECEIVED_AT TIMESTAMP (6),
MESSAGE_TYPE_ID NUMBER(19,0),
MESSAGE_DATA CLOB,
IS_SEARCHABLE CHAR(1 BYTE)
)
So when I try to create the text index on the message_data column as:
BEGIN
CTX_DDL.CREATE_PREFERENCE('msg_data_lexer', 'BASIC_LEXER');
CTX_DDL.SET_ATTRIBUTE('msg_data_lexer', 'skipjoins', '_-');
CTX_DDL.CREATE_PREFERENCE('msg_data_wordlist', 'BASIC_WORDLIST');
CTX_DDL.SET_ATTRIBUTE('msg_data_wordlist', 'SUBSTRING_INDEX', 'YES');
CTX_DDL.SET_ATTRIBUTE('msg_data_wordlist', 'PREFIX_INDEX', 'TRUE');
CTX_DDL.SET_ATTRIBUTE('msg_data_wordlist', 'PREFIX_MIN_LENGTH', '3');
CTX_DDL.SET_ATTRIBUTE('msg_data_wordlist', 'PREFIX_MAX_LENGTH', '6');
END;
/
CREATE INDEX message_msg_data_txt_idx on message(message_data)
INDEXTYPE IS CTXSYS.CONTEXT
FILTER BY message_type_id, from_entity, to_entity, is_searchable
PARAMETERS ('DATASTORE CTXSYS.DEFAULT_DATASTORE
FILTER CTXSYS.NULL_FILTER
LEXER msg_data_lexer
SYNC (EVERY "SYSDATE + (30/24/60/60)")
WORDLIST msg_data_wordlist');
So basically I want to create an index that syncs every 30 seconds because this is a table where lots of new messages will be added all the time (potentially hundreds to thousands of messages per second).
When the create index is run, it outputs:
Error at Command Line:1 Column:13
Error report:
SQL Error: ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-20000: Oracle Text error:
DRG-50857: oracle error in drvddl.IndexCreate
ORA-27486: insufficient privileges
ORA-06512: at "CTXSYS.DRUE", line 160
ORA-06512: at "CTXSYS.TEXTINDEXMETHODS", line 366
29855. 00000 - "error occurred in the execution of ODCIINDEXCREATE routine"
The user has all the necessary privileges as far as I know. If I either remove the 'sync' parameter or change it to 'SYNC (ON COMMIT)', then the index gets created properly.
Why can't I set the sync parameter to 'every'? What am I doing wrong?
The version of Oracle I'm using is:
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

After digging through Google, that's what I have finally come across:
EVERY interval-string - Automatically synchronize the index at a regular interval specified by the value of interval-string. interval-string takes the same syntax as that for scheduler jobs. Automatic synchronization using EVERY requires that the index creator have CREATE JOB privileges.
Taken from here: about Oracle Text
I tried to run your code and got the same error as you did. However, after:
GRANT CREATE JOB TO my_user;
I was able to create the index without any errors.

Related

Show errors in sql plus

I have a file myFile.sql that contains a list of script to compile :
#"Directory\package1.sql"
#"Directory\package2.sql"
#"Directory\package3.sql"
#"Directory\package4.sql"
I have the following script:
SPOOL Directory\Upgrade.log
#"Directory\myFile.sql"
SPOOL OFF
Some packages in myFile.sql have errors, but in Upgrade.log I do not have the details of the errors, I have the message Warning : Package body created with compilation errors.
How can I add the error detail without adding SHOW ERR after each line in MyFile.sql ?
In upgrade.log I want have this:
Package1 created
Warning Package body created with compilation errors.
**Error detail1**
Package2 created
Warning Package body created with compilation errors.
**Error detail2**
I need a hook in sqlplus to show error automatically after each package creation if there is an error
Thanks for your help.
One method is to query dictionnary view USER_ERRORS, or ALL_ERRORS.
From the documentation:
ALL_ERRORS describes the current errors on the stored objects accessible to the current user.
USER_ERRORS gives the same information for objects owned by the current user.
From Oracle 11.1 onward, you could use the SQLPlus error logging feature. You can read more about SQL*Plus error logging – New feature release 11.1.
SQL*Plus error logging is set OFF by default. So, you need to set errorlogging on to use the SPERRORLOG table.
Demo:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> desc sperrorlog;
Name Null? Type
----------------------------------------- -------- ----------------------------
USERNAME VARCHAR2(256)
TIMESTAMP TIMESTAMP(6)
SCRIPT VARCHAR2(1024)
IDENTIFIER VARCHAR2(256)
MESSAGE CLOB
STATEMENT CLOB
SQL> truncate table sperrorlog;
Table truncated.
SQL> set errorlogging on;
SQL> selct * from dual;
SP2-0734: unknown command beginning "selct * fr..." - rest of line ignored.
SQL> select timestamp, username, script, statement, message from sperrorlog;
TIMESTAMP USERNAME STATEMENT MESSAGE
----------- -------- ------------------ -------
17-APR-2020 SCOTT selct * from dual; SP2-0734: unknown command beginning "selct * fr..." - rest of line ignored.
Similarly, you can capture PLS errors too. They will start with error code SP.

HSQLDB SqlTool is throwing user lacks privilege or object not found

I'm executing .sql scripts using SqlTool. It keep on saying user lacks privilege or object not found. The same script is working perfectly from Swing UI.
My Script (hello.sql)
\.
SET DATABASE SQL SYNTAX ORA TRUE;
ALTER CATALOG PUBLIC RENAME TO SOMENAME;
COMMIT;
CREATE SCHEMA SOMESCHEMA;
COMMIT;
CREATE PROCEDURE SOMENAME.SOMESCHEMA.SP_FAILED_COUNT(IN i_ssn VARCHAR(100), IN i_page_id NUMBER(10), IN i_ip_address VARCHAR(100), IN i_session_guid VARCHAR(100), OUT o_toomanyfails VARCHAR(2000))
READS SQL DATA
BEGIN ATOMIC
SET o_toomanyfails = 'N';
END
COMMIT;
.
:;
Exception
> java -jar sqltool-2.4.1.jar --autocommit --rcfile C:\\my-files\\hsqldb\\2.4.1\\dbmanager.rc web C:\\my-files\\hsqldb\\2.4.1\\hello.sql
Executing command from edit buffer:
"SET DATABASE SQL SYNTAX ORA TRUE;
ALTER CATALOG PUBLIC RENAME TO SOMENAME;
COMMIT;
CREATE SCHEMA SOMESCHEMA;
COMMIT;
CREATE PROCEDURE SOMENAME.SOMESCHEMA.SP_FAILED_COUNT(IN i_ssn VARCHAR(100), IN i_page_id NUMBER(10), IN i_ip_address VARCHAR(100), IN i_session_guid VARCHAR(100), OUT o_toomanyfails VARCHAR(2000))
READS SQL DATA
BEGIN ATOMIC
SET o_toomanyfails = 'N';
END
COMMIT;"
SEVERE SQL Error at 'C:\my-files\hsqldb\2.4.1\hello.sql' line 14:
"SET DATABASE SQL SYNTAX ORA TRUE;
ALTER CATALOG PUBLIC RENAME TO SOMENAME;
COMMIT;
CREATE SCHEMA SOMESCHEMA;
COMMIT;
CREATE PROCEDURE SOMENAME.SOMESCHEMA.SP_FAILED_COUNT(IN i_ssn VARCHAR(100), IN i_page_id NUMBER(10), IN i_ip_address VARCHAR(100), IN i_session_guid VARCHAR(100), OUT o_toomanyfails VARCHAR(2000))
READS SQL DATA
BEGIN ATOMIC
SET o_toomanyfails = 'N';
END
COMMIT;"
user lacks privilege or object not found: SOMENAME
org.hsqldb.cmdline.SqlTool$SqlToolException
The same script is working from HSQLDB Swing UI.
I tried adding commit but still it is not working. It is working fine if I remove catalogname.schemaname.(SOMENAME.SOMESCHEMA.) from script
Also, i didn't understand one thing.
If I execute the following command in Swing UI it working perfectly for first time but if i execute for the second time i get the following exception
user lacks privilege or object not found: PUBLIC / Error Code: -5501 / State: 42501
ALTER CATALOG PUBLIC RENAME TO SOMENAME;
It confirms that the catalog is renamed. But where if I run the same script using sqltool again and again it never throws the same exception. How to make it working from sqltool (i.e. after importing it from .sql script)
There's no way that "The same script is working from HSQLDB Swing UI."
I loaded the exact script into HSQLDB Swing UI v. 2.4.1 and it fails as I expected with "unknown token: / Error Code: -5582 / State: 42582" because you have SqlTool-specific grammar in your script.
If I remove the Sql-Tool specific grammar then Swing UI reports "user lacks privilege or object not found: SOMENAME / Error Code: -5501 / State: 42501".
Fred T. can explain exactly why, but those commands apparently have to be in two transactions and I can make it work from Swing UI by just executing everything before the "CREATE SCHEMA" in one execution; then the rest in another execution. I suspect that you actually edited your script (not running "The same script") and then executed it with an older version of HyperSQL Swing UI where it did not execute all of the commands in a single transaction.
SqlTool doesn't have that limitation and allows you to control exactly what commands go over in which transaction. Just allow all commands (the COMMITs are unnecessary) in their own transactions (which is default behavior). It then works.
TIPS:
You don't need the COMMITs because these are DDL statements.
You can
execute the . transaction by terminating it with ".;" instead of
separate "." and ":." commands.
You don't need the \. at all because
SqlTool automatically knows that you need a new grouped transaction
when it sees "CREATE PROCEDURE" beginning a command. If it makes
the code more readable for you, you can insert the ".\" immediately
before the CREATE PROCEDURE.
In summary this works from SqlTool:
SET DATABASE SQL SYNTAX ORA TRUE;
ALTER CATALOG PUBLIC RENAME TO SOMENAME;
CREATE SCHEMA SOMESCHEMA;
CREATE PROCEDURE SOMENAME.SOMESCHEMA.SP_FAILED_COUNT(IN i_ssn VARCHAR(100), IN i_page_id NUMBER(10), IN i_ip_address VARCHAR(100), IN i_session_guid VARCHAR(100), OUT o_toomanyfails VARCHAR(2000))
READS SQL DATA
BEGIN ATOMIC
SET o_toomanyfails = 'N';
END
.;

Oracle: 'populate pending' index of another schema

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

Can't load an SQL dump into Oracle 11g

I was given an SQL dump from an Oracle 11g database. It contains all of the statements to reproduce the database. Unfortunately, it fails at the very first one
CREATE SEQUENCE "XXX"."YYY"
INCREMENT BY 1
START WITH 129004
MAXVALUE 1000000000000000000000000000
NOMINVALUE
NOCYCLE
CACHE 20
NOORDER
GO
With the error SQL command not properly ended. If I throw out the GO at the end, the error user or role '' does not exist. What am I doing wrong? I tried this both in sqlplus command line client and in Oracle SQL developer.
Needless to say, I'm very new to Oracle, so please be easy on me :D.

Oracle 10gR2 trigger error

I have Oracle 10gR2. I am trying to create autoincrement trigger.
Here is the sample:
CREATE SEQUENCE TEST_SEQ
INCREMENT BY 1
START WITH 1
NOMAXVALUE
/
CREATE TABLE TESTER (
ID_TESTER INTEGER NOT NULL,
VAL VARCHAR2(20) NOT NULL
)
/
CREATE OR REPLACE TRIGGER TIB_TESTER BEFORE INSERT
ON TESTER FOR EACH ROW
BEGIN
SELECT TEST_SEQ.NEXTVAL
INTO :NEW.ID_TESTER
FROM DUAL;
END;
/
Trigger creation gives warning:
warning : ORA-24344: success with
compilation error
And when I get error value:
select OCI_SUCCESS_WITH_INFO;
/
It gives error:
error : ORA-00923: FROM keyword not
found where expected
What client are you using to issue these commands? ORA-24344 is a perculiar error.
In SQL*PLus we can get more information about compilation errors like this:
SQL> show errors
As for the ORA-00923 error, that is because in Oracle's version of SQL we always have to select from a table. So you should execute
select OCI_SUCCESS_WITH_INFO
from dual
/
I'm not sure how much sense that makes, but at least you won't get the error.
"It was Navicat problem"
That doesn't surprise me, as I ran your code against my database and it built without a hitch.
Maybe it will be useful for somebody:
If you are using Oracle 10g and OCI driver, ORA-24344 shows when trigger have carriage return sign (\r) in code eg. file was created with Windows end of line style.