Convert from VARCHAR2 to NCLOB (oracle) - oracle

I got a column message with data_type = VARCHAR2. It already has some data stored. I want this column to be of type NCLOB. Code-Set for this column should be UTF-8.
I did the following:
added a column tempmessage to my table of type NCLOB
filled tempmessage with message
renamed message to message old (so that i don't use any data (until it works))
renamed tempmessage to message
Then i tried out my integration tests and i got the exception:
java.sql.BatchUpdateException: ORA-01400: Insert of NULL into ("BATCH_LOG"."MESSAGEOLD") not possible.
What have I done wrong?

The original column was defined as NOT NULL, when you renamed that to MESSAGEOLD, this constraint was kept. You need to remove the NOT NULL constraint from the MESSAGEOLD column:
ALTER TABLE foo MODIFY MESSAGEOLD NULL;

Related

Oracle pushing me ORA-00902: invalid datatype

create table accountDetails(
accountNumber int unique,
customerId int unique,
balance int not null,
password varchar(255) not null,
type varchar(255) not null check(type in ('Savings','Current')),
primary key(accountNumber,customerId) )
create table statusDetails(
customerId int references accountDetails(customerId),
primarykey(customerId))
The last table resulted in an error
The last table resulted in an error
ORA-00902: invalid datatype error happens when we try to define a column using an invalid datatype. It's logical really.
Now, you think you haven't declared a column with an invalid datatype, because you think statusdetails table has only one column, customerid. But if you look at your actual statement you follow that column with this:
primarykey(customerId))
Because you mis-typed primary key Oracle treats that line as an attempt to create a second column. Hence the error, because (customerId) is an invalid datatype. So all you need do is pop in the missing space and Oracle will create the table for you.
create table statusDetails(
customerId int references accountDetails(customerId),
primary key(customerId))
You had a compilation error caused by a simple typo. A key skill for a developer is the ability to turn a cool eye on our own code. I urge you to work on acquiring that skill as soon as you can.
Your second table declaration is all wrong. Try this:
CREATE TABLE statusdetails (
customerid INT,
CONSTRAINT fk_cust FOREIGN KEY ( customerid )
REFERENCES accountdetails ( customerid )
)
Note: using "int" data type maps to a NUMBER(38), which may not be what you want. Use the proper oracle data type names.

Oracle converted Varchar field to number how to convert it back to Varchar

Till today we use to enter numeric value in the Varchar column so Oracle converted that varchar field to Numeric field.
And now when we are trying to insert Character value it is throwing ORA-01722 (invalid number).
Could anyone help me out in order to convert it back to varchar field?
The commenters are correct: the database does not change column types on its own. In general, you must create a new column, copy the old data over to the new column, drop the original column, and rename the new column.
drop table deleteme_table;
-- zippy s/b varchar2(30), not integer
CREATE TABLE deleteme_table
(
adate DATE
, zippy INTEGER
);
-- Add the correct type to the table as a new column
ALTER TABLE deleteme_table
ADD (tempcol VARCHAR2 (30));
-- Copy the old values to the new column
UPDATE deleteme_table
SET tempcol = zippy;
-- Get rid of the original column
ALTER TABLE deleteme_table
DROP COLUMN zippy;
-- Rename to original column name
alter table deleteme_table rename column tempcol to zippy;

DBUnit fails with Oracle mixed-case column names

The problem is an existing Oracle table (that I cannot change) with mixed case column names, eg
create table BADTAB ( ID varchar(16) not null, "Name" varchar2(64),
constraint I_BADTAB_PK PRIMARY KEY(ID) );
When I try to do a DBUnit INSERT from an XML dataset it fails
Caused by: java.sql.SQLException: ORA-00904: "NAME": invalid identifier
When I enclose the column name in quotes it fails
<column>"Name"</column>
org.dbunit.dataset.NoSuchColumnException: BADTAB."NAME" - (Non-uppercase input column: "ReadingsPres") in ColumnNameToIndexes cache map.
Note that the map's column names are NOT case sensitive.
at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:117)
...
QUESTION:
How can I override DBUnit's column metadata to make it recognize the lowercase column name?
What classes do I override and how do I inject them into the DBUnit test run?
There have been some previous discussions around this org.dbunit.dataset.NoSuchTableException: Did not find table 'xxx' in schema 'null'
You should be able to set a database configuration property to cater for case-sensitive names:
DatabaseConfig config = databaseConnection.getConfig();
config.setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, true);

date Not null , error ora_01758

why I am getting this error ?
In the table DDL I only have 2 columns , id (number) and name (varchar)
ALTER TABLE mytable ADD SUSPEND date NOT NULL
ORA-01758: table must be empty to add mandatory (NOT NULL) column
ORA-06512: at line 7
ORA-01758: table must be empty to add mandatory (NOT NULL) column ORA-06512: at line 7
And is your table empty? I think not.
There's probably a way around this involving adding the column as nullable, then populating every row with a non-NULL value, the altering the column to be not null.
Alternatively, since the problem is that these current rows will be given NULL as a default value, and the column is not allowed to be NULL, you can also get around it with a default value. From the Oracle docs:
However, a column with a NOT NULL constraint can be added to an existing table if you give a default value; otherwise, an exception is thrown when the ALTER TABLE statement is executed.
Here is a fiddle, how you could do it
Would a date in the future be acceptable as a temporary default? If so, this would work:
ALTER TABLE MYTABLE ADD (SUSPEND_DATE DATE DEFAULT(TO_DATE('21000101', 'YYYYMMDD'))
CONSTRAINT SUSPEND_DATE_NOT_NULL NOT NULL);
If table already contain the records then table won't allowes to add "Not null" column.
If you need same then set default value for the column or truncate the table then try.

UPDATE in procedure ORA-00001

I have w problem with UPDATE in procedure. Procedure compiling and I see(DBMS...) results example 100records and error
ORA-00001: unique constraint violated (CUSTOMER_INFO_COMM_METHOD_UX)
My update:
UPDATE customer_info_comm_method_tab SET Value=wynikOK WHERE
customer_id=cus_rec.customer_id AND method_id='E_MAIL' AND Value = p_stringWyn;
wynikOK - actual new Value
cus_rec.customer_id - actual customer_id from cursor
p_stringWyn - old Value in table
key is founded on three attributes that I use (CUSTOMER_ID, VALUE, METHOD_ID)
Of course I can't remove index CUSTOMER_INFO_COMM_METHOD_UX because Its not my database
If I commented update procedure compile 100% without error but I need to do this update
It means that your new value (wynikOK) is causing the violation. The combination of customer_id , your new value(wynikOK) and method id is already existing in another row of your table. But this has to be unique...
If this combination of values(customer,value,method) is not gonna be unique , then remove the unique constraint in the table..
Else value has to be unique. Try appending some strings for your new value so that it will be unique. Say if your value is 1234, try appending the date to this value 1234_23112012 so that this will be unique always.

Resources