因此,当我尝试执行以下代码时,我收到此错误
ociexecute(): ORA-00932: inconsistent datatypes: expected - got CLOB
$where_clause = "A.sent_newsletter='N' AND
A.validated='Y' AND
(TRUNC(A.date_validity_to) >= TRUNC(SYSDATE) OR A.date_validity_to IS NULL) AND
(TRUNC(A.date_validity_from) <= TRUNC(SYSDATE) OR A.date_validity_from IS NULL) AND
A.id_category=21 AND
A.id_category=B.id_category AND
B.id_type=C.id_type AND
C.id_subscription=".OCIResult($stmt_users, "ID_SUBSCRIPTION")." AND
C.id_type=D.id_type AND
E.id_news=A.id_news AND";
$stmt_news = OCIParse($conn, "SELECT *
FROM (
SELECT A.id_news,
A.id_category,
A.lang,
A.title,
A.subtitle,
TO_CHAR(A.date_creation, 'DD/MM/YYYY') AS DATE_CREATION,
D.description,
E.text
FROM ".$db_schema_name."news_header A,
".$db_schema_name."newsletter_typecat_profile B,
".$db_schema_name."newsletter_subtyp_profile C,
".$db_schema_name."newsletter_type D,
".$db_schema_name."news_paragraph E
WHERE ".$where_clause."
A.lang='".OCIResult($stmt_users, "LANG")."'
UNION
SELECT A.id_news,
A.id_category,
A.lang,
A.title,
A.subtitle,
TO_CHAR(A.date_creation, 'DD/MM/YYYY') AS DATE_CREATION,
D.description,
E.text
FROM ".$db_schema_name."news_header A,
".$db_schema_name."newsletter_typecat_profile B,
".$db_schema_name."newsletter_subtyp_profile C,
".$db_schema_name."newsletter_type D,
".$db_schema_name."news_paragraph E
WHERE ".$where_clause."
A.lang='".$default_language."' AND
A.id_news NOT IN (SELECT A.id_news
FROM ".$db_schema_name."news_header A,
".$db_schema_name."newsletter_typecat_profile B,
".$db_schema_name."newsletter_subtyp_profile C,
".$db_schema_name."newsletter_type D,
".$db_schema_name."news_paragraph E
WHERE ".$where_clause."
A.lang='".OCIResult($stmt_users, "LANG")."')
) ORDER BY id_category, id_news DESC");
E.text是一个clob,我想记住它而不是显示它。知道为什么? 如果我删除E表,代码工作正常。但现在我想显示新闻中的段落,为此我需要TEXT字段。
while(OCIFetch($stmt_news) && (OCIFetchInto($stmt_news, $fields,OCI_ASSOC))) {
$paragraph_text = $fields['TEXT']->load();
$id_newsletter_collection[$id_newsletter_collection_index++] = OCIResult($stmt_news, "ID_NEWS");
$newsletter_item[$newsletter_item_index++] = New newsletter_item(OCIResult($stmt_news, "ID_NEWS"),
OCIResult($stmt_news, "LANG"),
OCIResult($stmt_news, "TITLE"),
OCIResult($stmt_news, "SUBTITLE"),
OCIResult($stmt_news, "DATE_CREATION"),
$paragraph_text,
$sentence_local[OCIResult($stmt_news, "DESCRIPTION")][OCIResult($stmt_users, "LANG")]);
} /* end while */
答案 0 :(得分:2)
您不能将 DISTINCT 与 clob数据类型一起使用, UNION 意味着区别,因此您可以将其替换为 UNION ALL < / strong>即可。它将解决问题,但您可能需要重写查询(取决于您需要的数据)。
答案 1 :(得分:0)
@Leo已经回答了#34;为什么&#34;。您有比union all
更多的选项:
首先在选择列表中使用dbms_lob.substr(e.text)
代替e.text
。
select a.id_news, dbms_lob.substr(e.text)
from a join e on e.id_news = a.id_news
where <condition1>
union
select a.id_news, dbms_lob.substr(e.text)
from a join e on e.id_news = a.id_news
where <condition2>
第二 - 将union
条款与where
相结合,更改or
:
select a.id_news, e.text
from a
join e on e.id_news = a.id_news
where <condition1>
or <condition2>
第二个并不完全等同于您的原始查询,它不会删除重复项,但请检查是否合适。
在这两种情况下,您都应该重写from
和where
部分,使用joins
。