How are these null values stored in a NOT NULL column?
4
votes
2
answers
2310
views
We are replicating tables from SAP ECC 6.0 on HANA into an Oracle 10g warehouse, using SAP SLT.
Since starting this, we have noticed the
NOT NULL
column definitions from HANA are retained in the Oracle copies of the tables, but HANA stores many values as empty strings. Oracle stores empty (varchar) strings as NULL
s and somehow this does not conflict with the NOT NULL
column definition (i.e. we have NULL
in a column defined as NOT NULL
).
Querying these tables is producing strange results:
SELECT COUNT(*) FROM warehouse.table WHERE col IS NULL;
0
SELECT COUNT(*) FROM warehouse.table WHERE col = '';
0
SELECT COUNT(*) FROM warehouse.table GROUP BY NVL(col,'N');
X 503206
N 2377222
So we can tell that there **are** NULL
values in these columns by using NVL
or DECODE
functions, but querying them is returning odd results.
We do get proper results once we alter the column:
ALTER TABLE warehouse.table MODIFY (col NULL);
Table altered.
SELECT COUNT(*) FROM warehouse.table WHERE col IS NULL;
390986
But of course we can't alter the column back:
ALTER TABLE warehouse.table MODIFY (col NOT NULL);
ERROR at line 1:
ORA-02296: cannot enable (warehouse.) - null values found
I can't tell if this is a problem with Oracle's implementation of empty string storage, or possibly just a quirk of interacting with SAP's SLT replication. It seems Oracle should not allow these rows with ''
or NULL
values as replication tries to place them there but we have not seen any errors indicating this.
---
Edit to add query requested by hypercube:
SELECT LENGTH(col) FROM warehouse.table GROUP BY LENGTH(col);
2377222
1 503206
Asked by Fredric Shope
(596 rep)
Nov 28, 2018, 03:19 PM
Last activity: Nov 30, 2018, 04:38 AM
Last activity: Nov 30, 2018, 04:38 AM