Examine the description of the EMP_DETAILS table given below:
name NULL TYPE
EMP_ID NOT NULL NUMBER
EMP_NAME NOT NULL VARCHAR2 (40)
EMP_IMAGE LONG
Which two statements are true regarding SQL statements that can be executed on the EMP_DETAIL table?
(Choose two.)
A. An EMP_IMAGE column can be included in the GROUP BY clause.
B. An EMP_IMAGE column cannot be included in the ORDER BY clause.
C. You cannot add a new column to the table with LONG as the data type.
D. You can alter the table to include the NOT NULL constraint on the EMP_IMAGE column.
答案:BC(但是觉得答案是错的,应该是BCD,可以参看解析)
解析:
有关LONG的官方文档为:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#SQLRF00201
应该注意的如下:
You can reference LONG columns in SQL statements in these places:
-
SELECTlists -
SETclauses ofUPDATEstatements -
VALUESclauses ofINSERTstatements
The use of LONG values is subject to these restrictions:
-
A table can contain only one
LONGcolumn. -
You cannot create an object type with a
LONGattribute. -
LONGcolumns cannot appear inWHEREclauses or in integrity constraints (except that they can appear inNULLandNOTNULLconstraints). -
LONGcolumns cannot be indexed. -
LONGdata cannot be specified in regular expressions. -
A stored function cannot return a
LONGvalue. -
You can declare a variable or argument of a PL/SQL program unit using the
LONGdata type. However, you cannot then call the program unit from SQL. -
Within a single SQL statement, all
LONGcolumns, updated tables, and locked tables must be located on the same database. -
LONGandLONGRAWcolumns cannot be used in distributed SQL statements and cannot be replicated. -
If a table has both
LONGand LOB columns, then you cannot bind more than 4000 bytes of data to both theLONGand LOB columns in the same SQL statement. However, you can bind more than 4000 bytes of data to either theLONGor the LOB column.
In addition, LONG columns cannot appear in these parts of SQL statements:
-
GROUPBYclauses,ORDERBYclauses, orCONNECTBYclauses or with theDISTINCToperator inSELECTstatements -
The
UNIQUEoperator of aSELECTstatement -
The column list of a
CREATECLUSTERstatement -
The
CLUSTERclause of aCREATEMATERIALIZEDVIEWstatement -
SQL built-in functions, expressions, or conditions
-
SELECTlists of queries containingGROUPBYclauses -
SELECTlists of subqueries or queries combined by theUNION,INTERSECT, orMINUSset operators -
SELECTlists ofCREATETABLE...ASSELECTstatements -
ALTERTABLE...MOVEstatements -
SELECTlists in subqueries inINSERTstatements
Triggers can use the LONG data type in the following manner:
-
A SQL statement within a trigger can insert data into a
LONGcolumn. -
If data from a
LONGcolumn can be converted to a constrained data type (such asCHARandVARCHAR2), then aLONGcolumn can be referenced in a SQL statement within a trigger. -
Variables in triggers cannot be declared using the
LONGdata type. -
:
NEWand :OLDcannot be used withLONGcolumns.
You can use Oracle Call Interface functions to retrieve a portion of a LONG value from the database.
SQL> create table emp_details (
2 emp_id number not null,
3 emp_name varchar2(40) not null,
4 emp_image LONG);
Table created.
--A选项错,LONG类型的列不能出现在GROUP BY语句中,B选项对
SQL> select emp_image from emp_details group by emp_image;
select emp_image from emp_details group by emp_image
*
ERROR at line 1:
ORA-00997: illegal use of LONG datatype
--C选项对,一个表中不能出现两个LONG类型的字段
SQL> alter table emp_details add (emp_file long);
alter table emp_details add (emp_file long)
*
ERROR at line 1:
ORA-01754: a table may contain only one column of type LONG
--D选项也应该对,能够修改为not null约束
SQL> alter table emp_details modify emp_image not null;
Table altered.
SQL> desc emp_details;
Name Null? Type
----------------------------------------- -------- ----------------------
EMP_ID NOT NULL NUMBER
EMP_NAME NOT NULL VARCHAR2(40)
EMP_IMAGE NOT NULL LONG
本文详细介绍了Oracle数据库中LONG数据类型的使用限制,包括其在SQL语句中的适用场景及不适用部分,并通过实例验证了LONG类型列不能出现在GROUP BY子句中、一个表只能包含一个LONG类型列以及可以为LONG类型列添加NOT NULL约束。
2368

被折叠的 条评论
为什么被折叠?



