Index: src/com/metamatrix/modeler/jdbc/relational/impl/OracleCostAnalyzerImpl.java
===================================================================
--- src/com/metamatrix/modeler/jdbc/relational/impl/OracleCostAnalyzerImpl.java	(revision 1613)
+++ src/com/metamatrix/modeler/jdbc/relational/impl/OracleCostAnalyzerImpl.java	(working copy)
@@ -7,9 +7,15 @@
  */
 package com.metamatrix.modeler.jdbc.relational.impl;
 
+import java.sql.CallableStatement;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
 import org.eclipse.core.runtime.IProgressMonitor;
 import com.metamatrix.modeler.internal.jdbc.relational.util.JdbcRelationalUtil;
 import com.metamatrix.modeler.jdbc.JdbcSource;
@@ -18,7 +24,32 @@
  * @since 4.3
  */
 public class OracleCostAnalyzerImpl extends DefaultCostAnalyzerImpl {
+    /**
+     */
+    private static final String NUMBER = "number"; //$NON-NLS-1$
     private static String ORACLE_8 = "8."; //$NON-NLS-1$ 
+    
+    private final static Map<Integer, String> type_to_raw_mapping = new HashMap<Integer, String>();
+    private final static Map<String, String> native_to_raw_mapping = new TreeMap<String, String>();
+    
+    static {
+        type_to_raw_mapping.put(Types.BIGINT, NUMBER);
+        type_to_raw_mapping.put(Types.INTEGER, NUMBER);
+        type_to_raw_mapping.put(Types.SMALLINT, NUMBER);
+        type_to_raw_mapping.put(Types.BOOLEAN, NUMBER);
+        type_to_raw_mapping.put(Types.NUMERIC, NUMBER);
+        type_to_raw_mapping.put(Types.DECIMAL, NUMBER);
+        type_to_raw_mapping.put(Types.REAL, NUMBER);
+        type_to_raw_mapping.put(Types.DOUBLE, NUMBER);
+        type_to_raw_mapping.put(Types.FLOAT, NUMBER);
+        type_to_raw_mapping.put(Types.INTEGER, NUMBER);
+        
+        type_to_raw_mapping.put(Types.VARCHAR, "varchar2"); //$NON-NLS-1$
+        type_to_raw_mapping.put(Types.NVARCHAR, "nvarchar2"); //$NON-NLS-1$
+        
+        native_to_raw_mapping.put("binary_float", "binary_float"); //$NON-NLS-1$ //$NON-NLS-2$
+        native_to_raw_mapping.put("binary_integer", "binary_integer"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
     /** 
      * @param jdbcSource
      * @param password
@@ -97,38 +128,59 @@
         Statement stmt = null;
         ResultSet rs = null;
         boolean success = false;
+
         try {
-            stmt = this.connection.createStatement(); 
             DatabaseMetaData metadata = this.connection.getMetaData();
+            String sql = "select num_distinct, num_nulls"; //$NON-NLS-1$
+            boolean unknownType = false;
+            if (colStat.isMinMaxCalculationRequired()) {
+                int jdbcType = colStat.jdbcType;
+                String type = native_to_raw_mapping.get(colStat.nativeType);
+                if (type == null) {
+                    type = type_to_raw_mapping.get(jdbcType);
+                }
+                if (type != null) {
+                    sql += ", utl_raw.cast_to_"+type+"(low_value), utl_raw.cast_to_"+type+"(high_value)"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                } else {
+                    sql += ", low_value, high_value"; //$NON-NLS-1$
+                    unknownType = true;
+                }
+            }
+            sql += " from ALL_TAB_COL_STATISTICS"; //$NON-NLS-1$
             if(metadata.getDatabaseProductVersion().startsWith(ORACLE_8)) {
-                rs = stmt.executeQuery("select num_distinct, num_nulls, low_value, high_value from ALL_TAB_COL_STATISTICS where TABLE_NAME = '" + tblStat.getName() + "' and COLUMN_NAME = '" + colStat.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                sql += " where TABLE_NAME = '" + tblStat.getName() + "' and COLUMN_NAME = '" + colStat.getName() + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
             }else {
-                rs = stmt.executeQuery("select num_distinct, num_nulls, low_value, high_value from ALL_TAB_COL_STATISTICS where owner='" //$NON-NLS-1$
-                    + tblStat.getSchema() + "' and TABLE_NAME = '" + tblStat.getName() + "' and COLUMN_NAME = '" + colStat.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                sql += " where owner='" //$NON-NLS-1$
+                    + tblStat.getSchema() + "' and TABLE_NAME = '" + tblStat.getName() + "' and COLUMN_NAME = '" + colStat.getName() + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
             }
+            stmt = this.connection.createStatement();
+            rs = stmt.executeQuery(sql);
             if(rs.next()) {
                 colStat.setNumDistinctValues(rs.getInt(1));
                 colStat.setNumNullValues(rs.getInt(2));
 
-                //Can not use these statistics
-                //colInfo.getMin() = rs.getString(3);
-                //colInfo.getMax() = rs.getString(4);
+                if (colStat.isMinMaxCalculationRequired()) {
+                    if (unknownType) {
+                        int conversionType = colStat.jdbcType;
+                        if (conversionType == Types.TIME || conversionType == Types.TIMESTAMP) {
+                            conversionType = Types.DATE;
+                        }
+                        byte[] bytes = rs.getBytes(3);
+                        String val = getRawAsString(colStat, bytes, conversionType);
+                        colStat.setMin(val);
+                        bytes = rs.getBytes(4);
+                        val = getRawAsString(colStat, bytes, conversionType);
+                        colStat.setMax(val);
+                        //if not a known conversion type (rowid, date, char), then we could choose to compensate
+                    } else {
+                        colStat.setMin(rs.getString(3));
+                        colStat.setMax(rs.getString(4));
+                    }
+                }
                 
                 String tblName = tblStat.getFullyQualifiedEscapedName();
                 String colName = JdbcRelationalUtil.escapeDatabaseObjectName(colStat.getName());
-                if(colStat.isMinMaxCalculationRequired()) {
-                    String minMaxSql = "select min(" + colName + "), max(" + colName + ") from " + tblName; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                    
-                    rs = stmt.executeQuery(minMaxSql);
-                    if (rs.next()) {
-                        colStat.setMin(rs.getString(1));
-                        colStat.setMax(rs.getString(2));
-
-                        success = true;
-                    }                    
-                } else {
-                    success = true;
-                }
+                success = true;
                 
                 log("\t\t" + tblName + "." + colName +  //$NON-NLS-1$ //$NON-NLS-2$
                     ": NDV=" + colStat.getNumDistinctValues() +  //$NON-NLS-1$
@@ -148,6 +200,33 @@
         }
         return false;
     }
+
+    /**
+     * @param colStat
+     * @param bytes
+     * @return
+     * @throws SQLException
+     */
+    private String getRawAsString( ColumnStatistics colStat, byte[] bytes, int type ) {
+        CallableStatement cs = null;
+        try {
+            cs = this.connection.prepareCall("{call dbms_stats.convert_raw_value(?, ?)}"); //$NON-NLS-1$
+            cs.registerOutParameter(2, type);
+            cs.setBytes(1, bytes);
+            cs.execute();
+            String val = cs.getString(2);
+            return val;
+        } catch (SQLException e) {
+            return null; //TODO
+        } finally {
+            if (cs != null) {
+                try {
+                    cs.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
     
     
 }
Index: src/com/metamatrix/modeler/jdbc/relational/impl/DefaultCostAnalyzerImpl.java
===================================================================
--- src/com/metamatrix/modeler/jdbc/relational/impl/DefaultCostAnalyzerImpl.java	(revision 1613)
+++ src/com/metamatrix/modeler/jdbc/relational/impl/DefaultCostAnalyzerImpl.java	(working copy)
@@ -333,6 +333,7 @@
                 final ColumnStatistics colStat = (ColumnStatistics)colStats.get(colName);
                 if (colStat != null) {
                     colStat.setJdbcType(rs.getInt(5));
+                    colStat.setNativeType(rs.getString(6));
                     colStat.setNullable(rs.getInt(11) != DatabaseMetaData.attributeNoNulls);
                 }
             }
