Space character that persists in varchar2 in Oracle 11g for display in SSRS 2008
Is there a space or other non-printing character I can insert to a varchar2 column that will not be trimmed away and result in a NULL?
I just want to insert a blank into the column so it displays nothing on an SSRS 2008 report. The column is part of a PK so it cannot be NULL. Of course using ''
doesn't work as this is seen as NULL in Oracle, and ' '
doesn't work because it's varchar2 and trimmed to be NULL.
So is there a literal value I can insert instead that will display as nothing in SSRS but also can be inserted to a non-nullable varchar2 column in Oracle 11g?
Thinking about it for a moment, I guess something like a tab character could do the job. But I look forward to your suggestions.
UPDATE
Whoops. Guess where the trimming behavior came from? My own RTRIM! Sorry about that. Let's just say I was mislead by my inexperience with Oracle and my frustration over this leading me to determine the error was in the product rather than in my query. But hey, it's not exactly a simple query.
INSERT INTO WeeklyInvoice (GUID, Mo, VendorName, CostCenter, WkNum, Amt)
SELECT
ExecID,
Mo,
VendorName,
CostCenter,
WkNum,
Amt
FROM (
WITH CostCenters AS (
SELECT REGEXP_SUBSTR(CostCenterList, '[^,]+', 1, LEVEL) CostCenter
FROM DUAL
CONNECT BY LEVEL <= Length(CostCenterList) - Length(Replace(CostCenterList, ',', '')) + 1
), Invoices AS (
SELECT
TRUNC(I.Invoice_Dte, 'MM') Mo,
(TRUNC(I.Invoice_Dte, 'W') - TRUNC(I.Invoice_Dte, 'MM')) / 7 + 1 WkNum,
I.Vendor,
V.Vendor_VName,
RTrim(D.Dis_Acct_Unit) CostCenter,
D.To_Base_Amt
FROM
CostCenters CC
CROSS JOIN prod.IcCompany C
INNER JOIN prod.ApDistrib D
ON C.Company = D.Company
AND D.Dis_Acct_Unit = CC.CostCenter
INNER JOIN prod.ApInvoice I
ON D.Invoice = I.Invoice
AND D.Vendor = I.Vendor
AND D.Suffix = I.Suffix
AND D.Company = I.Company
INNER JOIN prod.ApVenMast V ON I.Vendor = V.Vendor
WHERE
D.Cancel_Seq = 0
AND I.Cancel_Seq = 0
AND I.Invoice_Dte >= ADD_MONTHS(FromDate, -2)
AND I.Invoice_Dte < ToDate
), Months AS (
SELECT ADD_MONTHS(FromDate, LEVEL - 1) Mo
FROM DUAL
CONNECT BY LEVEL <= MONTHS_BETWEEN(ToDate, ADD_MONTHS(FromDate, -2))
), Names AS (
SELECT DISTINCT
I.Mo,
I.Vendor,
I.Vendor_VName,
I.CostCenter
FROM Invoices I
UNION ALL
SELECT M.Mo, '0', 'No Paid Invoices', ' '
FROM Months M
WHERE
NOT EXISTS (
SELECT I.*
FROM Invoices I
WHERE I.Mo = M.Mo
)
), Weeks AS (
SELECT LEVEL WkNum FROM DUAL CONNECT BY LEVEL <= 5
)
SELECT
开发者_StackOverflow N.Mo,
N.Vendor_VName VendorName,
N.CostCenter,
W.WkNum,
Sum(I.To_Base_Amt) Amt
FROM
Names N
INNER JOIN Weeks W
ON W.WkNum < 5
OR EXTRACT (MONTH FROM (N.Mo + 28)) = EXTRACT (MONTH FROM N.Mo)
LEFT JOIN Invoices I
ON N.CostCenter = I.CostCenter
AND N.Vendor = I.Vendor
AND N.Mo = I.Mo
AND W.WkNum = I.WkNum
GROUP BY
N.Mo,
N.Vendor_VName,
N.CostCenter,
W.WkNum
) X;
In my test below, the single space was not converted to a null:
SQL> CREATE TABLE t (col VARCHAR2 (10) NOT NULL);
Table created.
SQL> INSERT INTO t (col)
2 VALUES (' ');
1 row created.
SQL> SELECT CASE col WHEN ' ' THEN 'I am a single space' ELSE 'I am not a space' END AS col FROM t;
COL
-------------------
I am a single space
1 row selected.
SQL> SELECT LENGTH (col) FROM t;
LENGTH(COL)
-----------
1
1 row selected.
Are you trimming the values before inserting?
精彩评论