Cause : Some portion of datafile are using by database Segment which you trying to trim.
Solution : Move / Drop all Segment extends from the region prior that you want to trim.
SQL> ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orcln1/tbs_data01.dbf' RESIZE 1700M;
ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orcln1/tbs_data01.dbf' RESIZE 1700M
*
ERROR at line 1:
ORA-03297: file contains used data beyond requested RESIZE value
SQL> SELECT TABLESPACE_NAME
2 FROM DBA_DATA_FILES
3 WHERE FILE_NAME ='/u01/app/oracle/oradata/orcln1/tbs_data01.dbf';
TABLESPACE_NAME
------------------------------
TBS_DATA
SQL> SELECT DISTINCT SEGMENT_TYPE,SEGMENT_NAME
2 FROM DBA_EXTENTS
3 WHERE TABLESPACE_NAME = 'TBS_DATA';
SEGMENT_TYPE SEGMENT_NAME
------------------ ---------------------------------------------------------------------------------
TABLE TEST_RECLAIM_SPACE
INDEX IND_SERIAL_NO_TEST_RECL
SQL> ALTER TABLE TEST_RECLAIM_SPACE MOVE;
Table altered.
SQL> ALTER INDEX IND_SERIAL_NO_TEST_RECL REBUILD TABLESPACE TBS_DATA;
Index altered.
SQL> purge recyclebin;
Recyclebin purged.
SQL> ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orcln1/tbs_data01.dbf' RESIZE 1700M;
Database altered.
SQL>
Solution : Move / Drop all Segment extends from the region prior that you want to trim.
SQL> ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orcln1/tbs_data01.dbf' RESIZE 1700M;
ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orcln1/tbs_data01.dbf' RESIZE 1700M
*
ERROR at line 1:
ORA-03297: file contains used data beyond requested RESIZE value
SQL> SELECT TABLESPACE_NAME
2 FROM DBA_DATA_FILES
3 WHERE FILE_NAME ='/u01/app/oracle/oradata/orcln1/tbs_data01.dbf';
TABLESPACE_NAME
------------------------------
TBS_DATA
SQL> SELECT DISTINCT SEGMENT_TYPE,SEGMENT_NAME
2 FROM DBA_EXTENTS
3 WHERE TABLESPACE_NAME = 'TBS_DATA';
SEGMENT_TYPE SEGMENT_NAME
------------------ ---------------------------------------------------------------------------------
TABLE TEST_RECLAIM_SPACE
INDEX IND_SERIAL_NO_TEST_RECL
SQL> ALTER TABLE TEST_RECLAIM_SPACE MOVE;
Table altered.
SQL> ALTER INDEX IND_SERIAL_NO_TEST_RECL REBUILD TABLESPACE TBS_DATA;
Index altered.
SQL> purge recyclebin;
Recyclebin purged.
SQL> ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orcln1/tbs_data01.dbf' RESIZE 1700M;
Database altered.
SQL>