I am using Oracle for production and H2 as an in-memory test database. I'm having trouble with Oracle compatibility for the "rename column" statement.
Specifically, the Oracle statement is:
alter table "SOME_TABLE" rename column "COLUMN_A" to "COLUMN_B" ;
I'm using Spring and Liquibase to set up the test environment and believe I have specified "use Oracle compatibility mode" correctly, but this statement is rejected by H2 as follows:
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement
"ALTER TABLE ""SOME_TABLE"" RENAME COLUMN[*] ""COLUMN_A"" TO ""COLUMN_B"" "; expected "TO"; SQL statement:
alter table "SOME_TABLE" rename column "COLUMN_A" to "COLUMN_B" [42001-174]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:332)
at org.h2.message.DbException.getSyntaxError(DbException.java:197)
at org.h2.command.Parser.getSyntaxError(Parser.java:504)
at org.h2.command.Parser.read(Parser.java:2867)
at org.h2.command.Parser.parseAlterTable(Parser.java:4971)
at org.h2.command.Parser.parseAlter(Parser.java:4412)
at org.h2.command.Parser.parsePrepared(Parser.java:316)
at org.h2.command.Parser.parse(Parser.java:289)
at org.h2.command.Parser.parse(Parser.java:265)
at org.h2.command.Parser.prepareCommand(Parser.java:226)
at org.h2.engine.Session.prepareLocal(Session.java:437)
at org.h2.engine.Session.prepareCommand(Session.java:380)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1138)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:168)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:156)
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:294)
I am finding through research that this level of compatibility may not be implemented by H2 at this time. Are there any extensions I can write or any other actions I can take to rename a column in both Oracle and H2.
Thanks!
Steve Nester
Related
alter table tablename rename column zl_divn_nbr to div_loc_nbr;
Error while executing the above statement. Please help.
SQL Error: ORA-54032: column to be renamed is used in a virtual column expression
54032. 0000 - "column to be renamed is used in a virtual column expression"
*Cause: Attempted to rename a column that was used in a virtual column
expression.
*Action: Drop the virtual column first or change the virtual column
expression to eliminate dependency on the column to be renamed
Run the following SQL query in your database using the table name mentioned in the error message. For example, in the error message shown in this article, the table name is 'tablename'. Note that whilst the table name appears in lower case in the error message, it may be upper case in your DB. This query is case sensitive so if you receive no results, check whether the table name is upper case inside your database.
SELECT COLUMN_NAME, DATA_DEFAULT, HIDDEN_COLUMN
FROM USER_TAB_COLS
WHERE TABLE_NAME = 'tablename';
Before proceeding, make sure the Bitbucket Server process is not running. If Extended Statistics has been enabled, contact your database administrator to have them drop the Extended Statistics metadata from the table, and proceed with your upgrade. If you wish to enable Extended Statistics again after the upgrade you may do so, however be aware that you may need to repeat this process again for subsequent upgrades otherwise you risk running into this issue again.
Removing columns created by Extended Statistics requires using an in-build stored procedure,
DBMS_STATS.DROP_EXTENDED_STATS().
Usage of this stored procedure is covered further in ORA-54033 and the Hidden Virtual Column Mystery, and looks similar to the following:
EXEC DBMS_STATS.DROP_EXTENDED_STATS(ownname=>'<YOUR_DB_USERNAME>', tabname=>'tablename', extension=>'("PR_ROLE", "USER_ID", "PR_APPROVED")')
References
Database Upgrade Eror: column to be rename
Thanks.
Probably, you have such a table :
CREATE TABLE tablename(
id NUMBER,
zl_divn_nbr NUMBER,
zl_divn_percent NUMBER GENERATED ALWAYS AS (ROUND(zl_divn_nbr/100,2)) VIRTUAL
);
where zl_divn_nbr column is used for a computation for virtual(zl_divn_percent) column.
To rename zl_divn_nbr, all referenced virtual columns to this column should be removed, and may be created later.
The syntax for defining a virtual column is this :
column_name [datatype] [GENERATED ALWAYS] AS (expression) [VIRTUAL]
Since version 11 R1, we have this property.
ALTER TABLE rename column to
In the case of tables with virtual or 'group extension columns' the above
statement returns an error before Oracle 12cR2. For Oracle 12cR2 or newer versions the above statement runs fine cause 'renaming column' command is decoupled from the group extension aspect.
How do I access tables in my user schema in Sybase from Oracle?
In isql I can do
use mydb
go
How do I select from mydb tables from Oracle using dblink NITSYB5?
This does not work:
select count(*) from "mydb"."lon_client_confirm_exec"#NITSYB5;
Error:
ORA-00942: table or view does not exist
[Oracle][ODBC Sybase Wire Protocol driver][SQL Server]"mydb"."lon_client_confirm_exec" not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
{42S02,NativeErr = 208}
ORA-02063: preceding 3 lines from NITSYB5
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 3 Column: 30
NOTE: I don't work with Oracle and hence know nothing about Oracle's dblink, so fwiw ...
In Sybase ASE the fully qualified table name format is: <dbname>.<owner>.<table>
If you leave out the <owner> then the optimizer will first look for tables owned by the user running the query, then look for tables owned by dbo.
In your example it appears you've left out the <owner>. If the table is owned by your user or dbo then I'd suggest you try adding an additional period, eg:
select count(*) from mydb..lon_client_confirm_exec#NITSYB5;
NOTE: Add quotes as/if needed by Oracle's dblink.
SERVER 1 AND SERVER 2
open SSH server2 telnet server 1 host, its ok to done
su oracle
1) cd $ORACLE_HOME/bin
2) TNSPING database1 name
its ok done
create public database link
LINK_NAME
connect to
DB1USERNAME
identified by
111
using 'DB1NAME';
select * from dual#LINK_NAME, result x, finish.
I'm using Liquibase to create tables in DB2. I have a simple example changelog that tries to drop and then create a table.
The SQL statements work fine via my DbVisualizer tool (which uses the same JDBC driver as Liquibase) and also works fine when submitted via the db2 command line tool.
Here's the Liquibase input file:
--changeset dank:1 runAlways=true failOnError:false
DROP TABLE AAA_SCHEMA.FOO
--changeset dank:2 runAlways=true
CREATE TABLE AAA_SCHEMA.FOO ( MYID INTEGER NOT NULL )
Here's the error message I get:
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error:
SQLCODE=-104, SQLSTATE=42601, SQLERRMC=DROP TABLE AAA_SCHEMA.FOO;
;, DRIVER=4.18.60
The IBM error code -104 is about syntax problems. Based on looking at the error message my guess is that it has something to do with the end of line character ";". But I've tried the query with and without the semi-colon. The semi-colon is accepted by IBM's own db2 too, so it seems like a valid choice.
Any help in figuring out the cause of this error is much appreciated.
The problem was me forgetting to start my native sql file with this required line:
--liquibase formatted sql
Doh!
I currently work at migrating an Oracle 9i database (*.dmp file) to an Oracle 11g one.
To achieve this I use the exp and imp Oracle utilities command lines:
exp USERID=<user>/<password>#<database> FILE=<path> OWNER=<owner>
Then I create a skeleton.sql file which will create tables, index tables and finally indexes.
imp <user>/<password>#<database> FILE=<path> INDEXFILE="<path>\skeleton.sql" FROMUSER=<fromuser> TOUSER=<touser>
During this migration I am able to import most of the data correctly, and of course tablespaces are kept the same from one database to the other to avoid any conflicts.
But here comes the problem. In Oracle 11g, KOREAN_LEXER is no longer supported, instead you have to use the KOREAN_MORPH_LEXER. To do so I execute the following SQL commands:
call ctx_ddl.create_preference('korean_lexer','korean_morph_lexer');
call ctx_ddl.add_sub_lexer('global_lexer','korean','korean_lexer',null);
Then I import the skeleton.sql file in order to inject the data needed before the import:
sqlplus <user>/<password>#<database> #<path>\skeleton.sql
The creation of tables and index tables go smoothly until I get the following error for each of the 150+ indexes I created:
CREATE INDEX "<schema>"."WORKORDER_NDX16" ON "WORKORDER"
ERROR at line 1 :
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-20000: Oracle Text error:
DRG-10502: WORKORDER_NDX16 index does not exist
DRG-13201: KOREAN_LEXER is no longer supported
ORA-06512: at "CTXSYS.DRUE", line 160
ORA-06512: at "CTXSYS.TEXTINDEXMETHODS", line 366
Indexes are still created, this message is just a warning.
I try to rebuild any of the broken indexes:
ALTER index WORKORDER_NDX16 REBUILD;
Which give me the following error again:
SQL Error : ORA-29874: warning in the execution of ODCIINDEXCREATE routine
ORA-29960: ligne 1,
DRG-10595: failure on ALTER INDEX WORKORDER_NDX16
DRG-50857: oracle error in drixmd.PurgeKGL
ORA-20000: Oracle Text error:
DRG-13201: KOREAN_LEXER is no longer supported
ORA-30576: ConText Option dictionary loading error
DRG-50610: internal error: kglpurge []
29874. 00000 - "warning in the execution of ODCIINDEXALTER routine"
*Cause: A waring was returned from the ODCIIndexAlter routine.
*Action: Check to see if the routine has been coded correctly
Check the user defined warning log tables for greater details.
In my skeleton.sql file, under the creation of each indexes, I have the following lines for each language:
ctxsys.driimp.set_object('LEXER','MULTI_LEXER',12);
...
ctxsys.driimp.set_sub_value('SUB_LEXER','8', NULL, NULL,'KO:KOREAN_LEXER:');
...
So far I am lost on what to do, this seems to be a simple issue to solve but my dba skills are too low to do this on my own.
If anyone could help me on this I would greatly appreciate it !
Thank you.
This looks like your database is using Oracle Text indexes, which are not the same as ordinary indexes. Have you followed completely Oracle Note 300172.1 (Obsolescence of KOREAN_LEXER Lexer Type)? It mentions this code below, which could help.
ALTER INDEX <[schema.]index> REBUILD
PARAMETERS('REPLACE LEXER ko_morph_lexer [MEMORY <size>]');
If all else fails, maybe consider trying to migrate your data into an Oracle 10g database and complete the korean_morph_lexer in 10g. If that works, it would be an easy Data Pump task to move it from 10g to 11g (or 12c).
Can any one give me the syntax to truncate a table in IBM DB2.
I m running the following command: truncate table tableName immediate;
The eror is DB2
SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;truncate ;JOIN , DRIVER=3.50.152
Message: An unexpected token "table" was found following "truncate ". Expected tokens may include: "JOIN ".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.50.152
The syntax matches the one specified in the reference docs of IBM : http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_sql_truncate.htm
There is a great article about truncating, here is the Gist of DB2 stuff
Almost follows the standard.(since version 9.7)
DB2 requires that the IMMEDIATE keyword be added the the ordinary TRUNCATE TABLE statement, e.g.:
TRUNCATE TABLE someschema.sometable IMMEDIATE
TRUNCATE TABLE must be the first statement in a transaction. A transaction starting with TRUNCATE TABLE may include other statements, but if the transaction is rolled back, the TRUNCATE TABLE operation is not undone.
DB2s TRUNCATE TABLE operation has a number of optional arguments, see the documentation for more on this; especially, the REUSE STORAGE argument may be important for ad-hoc DBA tasks.
In DB2 versions < 9.7, you may abuse the IMPORT statement. Unfortunately, you need to know which operating system the command is executed from for this to work:
On unix-like systems:
IMPORT FROM /dev/null OF DEL REPLACE INTO tablename
On Windows:
IMPORT FROM NUL OF DEL REPLACE INTO tablename
IMPORT cannot be abused in all contexts. E.g., when working with dynamic SQL (from Java/.NET/PHP/...—not using the db2 command line processor), you need to wrap the IMPORT command in a call to ADMIN_CMD, e.g.:
CALL ADMIN_CMD('IMPORT FROM /dev/null OF DEL REPLACE INTO tablename')
IMPORT seems to be allowed in a transaction involving other operations, however it implies an immediate COMMIT operation.
The ALTER TABLE command may also be abused to quickly empty a table, but it requires more privileges, and may cause trouble with rollforward recovery.
This was taken from the website:
http://troels.arvin.dk/db/rdbms/#bulk-truncate_table-db2
If you are using DB2 for AS400, IMMEDIATE TRUNCATE TABLE will NOT work. The equivallent work around is to either:
DELETE FROM [tableName] then if it is an auto increment equivalant column, run:
ALTER TABLE ALTER COLUMN RESTART WITH 1
OR the faster (most efficient way)
Pass a command to the system to clear out the Physical File
Java syntax:
CommandCall command = new CommandCall(new AS400(AS400SystemName, AS400JavaUser, AS400JavaPwd));
try {
command.run("CLRPFM FILE(as400SchemaName/" + tableName + ")");
Which version of DB2 are you using? The truncate table command was introduced in DB2 v9 (at least on the mainframe, which appears to be what you're asking about based on the link).
You may have to resort to the delete from option although this article gives a stored procedure way of doing it in DB2 v8.
use truncate 'table_name' immediate
This is the exact reference documentation available for TRUNCATE in DB2 from 9.7 version
DB2 Reference for TRUNCATE
DB2 on z/OS V10
Empty one of your tables: truncate table; followed by commit work. Ex. truncate temp;
Someone else table: truncate owner.table Ex: truncate student.work ;
I have not tried this on a linked DB2. I do not know if truncate node2.student.work; is good.
SQL for creating list of tables automatically. Substring (substr) used because column width for table name and creator are sooo long. Your values may be different.
select 'truncate table '||substr(creator,1,9)||'.'||substr(name,1,20)
from sysibm.systables
where creator = 'Student';
in Java make sure it's the first statement in the transaction