是否有空格或其他非打印字符可以插入到不会被修剪掉并导致 NULL 的 varchar2 列中?
我只想在列中插入一个空白,以便在 SSRS 2008 报告中不显示任何内容。该列是 PK 的一部分,因此它不能为 NULL。当然 using''
不起作用,因为这在 Oracle 中被视为 NULL,并且' '
不起作用,因为它是 varchar2 并修剪为 NULL。
那么是否有一个文字值我可以插入而不是在 SSRS 中显示为空,但也可以插入到 Oracle 11g 中的不可为空的 varchar2 列中?
想了一会儿,我想像制表符这样的东西可以完成这项工作。但我期待您的建议。
更新
哎呀。猜猜修剪行为从何而来?我自己的 RTRIM!对于那个很抱歉。假设我被我对 Oracle 的缺乏经验所误导,我对此感到沮丧,这导致我确定错误出在产品中,而不是在我的查询中。但是,嘿,这不是一个简单的查询。
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
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;