1

我正在尝试获取列的默认值,但不幸的是我什么也没得到。这是我的代码:

'ColumnName is the Column Name in question
'BaseTableName is the Table Name
   Dim myCon As New OracleConnection
   myCon.ConnectionString = gApp.ConnectString
   myCon.Open()
   Dim myCmd As New OracleCommand
   myCmd.Connection = myCon
   myCmd.CommandType = CommandType.Text
   myCmd.CommandText = "select data_default " & _
          "from all_tab_columns " & _
          "where table_name='" & BaseTableName & "' " & _
          "and column_name='" & ColumnName & "'"
   Dim dr As OracleDataReader
   dr = myCmd.ExecuteReader
   dr.Read()
   Dim val = dr.GetValue(0).ToString

   '  Dim val = myCmd.ExecuteScalar 'I tried also with executeScalar but it was the same

   myCon.Close()

当我在 oracle 中执行相同的字符串时,它返回一个 Long 并且 long 里面是默认值 oracle中的结果

如何在 long 中获取原始值?

4

1 回答 1

0

假设问题是因为您的环境不支持 LONG,您可以先创建一个函数将值转换为 VARCHAR2。例如:

create table test1(a number default 0);

create or replace function get_data_default(
    p_owner varchar2,
    p_table_name varchar2,
    p_column_name varchar2
) return varchar2 authid current_user is
    v_data_default varchar2(4000);
begin
    select data_default
    into v_data_default
    from all_tab_columns
    where owner = p_owner
        and table_name = p_table_name
        and column_name = p_column_name;

    return v_data_default;
end;
/

select get_data_default(USER, 'TEST1', 'A') from dual;

0

如果您对其他列有此问题,您可以使函数更通用,或者您可以查看实用程序将所有字典 LONG 转换为 CLOB。Dictionary Long Application可以做到这一点,尽管它会变得非常复杂。

于 2012-11-08T19:40:32.873 回答