DATA_DEFAULT In ALL_TAB_COLUMNS...
Hi all,
I'm working in an existing codebase (VB.Net) that is using an Oracle Database. One of the things the application is doing is getting a copy of the default value for the different columns. It looks something like this:
If Not String.IsNullOrEmpty(myRow(0).Item("Data_Default").ToString) Then
myCol.DefaultValue=myRow(0).Item("Data_Default").ToString
End If
That Data_Default value is being populated from the ALL_TAB_COLUMNS table; using a DataAdapter.Fill statement.
Currently, the system is using a stored procedure, and inside that stored proc we're converting the DATA_DEFAULT column (which is a LONG) into a VARCHAR2. If that conversion doesn't happen, and we simply include the DATA_DEFAULT column in our SELECT statement, the datatable that the adapter fills will have a value of 'NULL' for DATA_DEFAULT in each and every row.
This conversion takes a long time. Doing the query without the conversion in PL/SQL takes .2 seconds. Doing the conversion takes *40* seconds. That's 200x as long!
I'm certain that something is being done incorrectly here. Can someone let me know where I've gone wrong? I just feel like there has to be a better way to do this; but I'm not sure what.
First - I want to apologize for asking such a silly question.
Second - I'll respond in the hopes that someone else with my question will find this on google and save himself the embarassment.
By default, when you perform a SELECT and pull back a LONG, you get the first 0 bytes of it. You get nothing. That's why, when I filled my datatable it was always null.
What you want to do (instead of all this on the fly conversion crap I was doing) is simply tell Oracle to give you more than 0 bytes for each long.
cdLookup = New Oracle.DataAccess.Client.OracleCommand
cdLookup.InitialLONGFetchSize = 500
Nice and simple; problem solved. Sorry again!
Similar Messages
-
LONG column and translate function
I want to get the default values of columns through all_tab_columns.
I have written the query :
select a.COLUMN_NAME, translate(a.DATA_DEFAULT,'''',' ')
from all_tab_columns a
where a.TABLE_NAME like 'T_MPR_MBT'
But it gives the following error:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG
Is there a way to convert long to string?
Thanks
Ameya.SQL> describe long_tab;
Name Null? Type
COL1 NUMBER
COL2 LONG
COL3 VARCHAR2(40)
SQL> select * from long_tab;
COL1 COL2 COL3
1 1st value for long characters 1st value for long characters
2
3 3rd value for long characters 3rd value for long characters
SQL> select * from long_tab
2 where nvl(col2,'x') = nvl(col2,'x');
where nvl(col2,'x') = nvl(col2,'x')
ERROR at line 2:
ORA-00932: inconsistent datatypes: expected LONG got CHAR
-- we know that we cannot compare a column with long datatype to other column that is not a long datatype.
-- we have to create some custom function to convert the long into a character type.
SQL> CREATE OR REPLACE Function convert_long_to_char( pTableName in varchar2,
2 pColumnName in varchar2,
3 pRowId in rowid ) return varchar2 As
4 vCursor integer default dbms_sql.open_cursor;
5 vN number;
6 vLongVal varchar2(4000);
7 vLongLen number;
8 vBuflen number := 4000;
9 vCurPos number := 0;
10 begin
11 dbms_sql.parse( vCursor,'select ' || pColumnName || ' from ' || pTableName ||
12 ' where rowid = :x',
13 dbms_sql.native );
14 dbms_sql.bind_variable( vCursor, ':x', pRowId );
15
16 dbms_sql.define_column_long(vCursor, 1);
17 vN := dbms_sql.execute(vCursor);
18
19 if (dbms_sql.fetch_rows(vCursor)>0) then
20 dbms_sql.column_value_long(vCursor, 1, vBuflen, vCurpos ,
21 vLongVal, vLongLen );
22 end if;
23 dbms_sql.close_cursor(vCursor);
24 return vLongVal;
25 end convert_long_to_char;
26 /
Function created.
SQL> select * from long_tab
2 where nvl(convert_long_to_char('long_tab','col2',rowid),'x') = nvl(col3,'x');
COL1 COL2 COL3
1 1st value for long characters 1st value for long characters
2
3 3rd value for long characters 3rd value for long characters
SQL>
-- in your case it would something like:
select a.COLUMN_NAME,
translate(convert_long_to_char('all_tab_columns','DATA_DEFAULT',rowid),'''',' ')
from all_tab_columns a
where a.TABLE_NAME like 'T_MPR_MBT'; -
How to get column default value define on table?
Hi,
I am trying to get a table column default value with no success. I am using the Oracle Data Provider for .NET 10g Release 2 (10.2.0.2)
1). OracleConnection.GetSchema( "Columns", New System.String() {"<Owner>", "<Table_Name>"} returns everything BUT default value.
2). I tried querying oracle directly (sample below) but the default value comes back blank even though the column has one defined.
Dim oracleConnection As Oracle.DataAccess.Client.OracleConnection = factory.CreateConnection
Dim oracleCommand As New Oracle.DataAccess.Client.OracleCommand( _
"SELECT data_default FROM DBA_TAB_COLUMNS WHERE OWNER = 'TEST_SCHEMA' AND UPPER( TABLE_NAME ) = 'TEST' AND UPPER(COLUMN_NAM) = 'TESTCOL'")
oracleConnection.Open()
oracleCommand.Connection = oracleConnection
Dim oracleReader As Oracle.DataAccess.Client.OracleDataReader = oracleCommand.ExecuteReader
oracleReader.GetValue(0) 'This will return blank rather than default value for the column.
oracleReader.Read()
oracleReader.Close()
oracleConnection.Close()
Any help would be appreciated.
Thanks,
Rob Panosh
Advanced Software DesignsHi Rob,
I just ran up a quick test and I can't duplicate the behavior you describe.
I created a simple table as "scott":
SQL> create table def_test(c varchar2(32) default 'hello, world');
Table created.In my simple test I used the following C# code:
NOTE: There is an error in this code if using ODP.NET (see my post below for details on this)
using System;
using System.Data;
using System.Data.OracleClient;
class Program
static void Main(string[] args)
string constr = "user id=scott;" +
"password=tiger;" +
"data source=orademo;" +
"pooling=false;" +
"enlist=false";
OracleConnection con = new OracleConnection(constr);
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "select data_default " +
"from all_tab_columns " +
"where owner='SCOTT' " +
"and table_name='DEF_TEST' " +
"and column_name='C'";
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
string defaultValue = (string) dr.GetValue(0);
Console.WriteLine("Default value is: {0}", defaultValue);
dr.Dispose();
cmd.Dispose();
con.Dispose();
}Since the GetValue method returns an "object" I cast the value to a string and got the correct result.
However, I don't have a 10.2 ODP.NET environment right now so I was using 11.1 for this.
In your real code I suspect that you assign "oracleReader.GetValue(0)" to something - when you say "blank" do you mean zero length or a space or something else?
Regards,
Mark
Edited by: Mark Williams on Jul 31, 2009 10:02 AM -
Generate DDL for objects (just for fun)
I'm been putting together queries that generate DDL. Considering exp/imp ROWS=0 can be used, or DBMS_METADATA there is little point. Though, with restricted access those may not be possible options, but then an external tool like TOAD could do it. Therefore, my justification for this is "just for fun".
Here is one for TABLEs. It does not generate the CONSTRAINTs (which i try to get in the next query), and no storage clauses. This query is also formatted for fixed width font with tabs equivalent to eight characters:
SELECT
SUBSTR
REPLACE
CASE
WHEN Columns.Column_Id = 1 THEN
'CREATE TABLE ' || Columns.Table_Name
|| CHR(10) || '('
|| CHR(10)
END
|| ' ' || Columns.Column_Name
|| RPAD(CHR(09), Tabs - FLOOR((LENGTH(Column_Name) +1) / 8), CHR(09))
|| Data_Type
|| CASE
WHEN Data_Type IN ('CHAR', 'VARCHAR2') THEN '(' || Char_Length || ')'
WHEN Data_Type = 'FLOAT' THEN '(' || Data_Precision ||')'
WHEN Data_Type = 'NUMBER' THEN
CASE WHEN Data_Precision IS NOT NULL THEN '(' || Data_Precision
|| CASE WHEN Data_Scale IS NOT NULL THEN ', ' || Data_Scale END
||')'
END
END
|| CASE
WHEN Data_Default IS NOT NULL
THEN
RPAD
CHR(09),
CASE Data_Type
WHEN 'CHAR' THEN CASE Char_Length WHEN 1 THEN 2 ELSE 1 END
WHEN 'DATE' THEN 2
ELSE 1
END,
CHR(09)
|| 'DEFAULT '
|| (
SELECT
ExtractValue
DBMS_XMLGEN.GetXMLType
SELECT
Data_Default
FROM
All_Tab_Columns
WHERE
Owner = ''' || Columns.Owner || '''
AND Table_Name = ''' || Columns.Table_Name || '''
AND Column_Name = ''' || Columns.Column_Name ||'''
'ROWSET/ROW/DATA_DEFAULT'
FROM
Dual
END
|| CASE
WHEN Columns.Column_Id = Info.Total_Columns
THEN CHR(10) || ');' || CHR(10) || CHR(10)
ELSE ','
END,
',' || CHR(10) || CHR(10),
',' || CHR(10)
1,
181
) Statement
FROM
All_Tab_Columns Columns,
SELECT
Owner,
Table_Name,
MAX(Column_Id) Total_Columns,
MAX(FLOOR((LENGTH(Column_Name) + 1) / 8)) + 1 Tabs
FROM
All_Tab_Columns
WHERE
Owner = 'SYS'
GROUP BY
Owner,
Table_Name
) Info
WHERE
Columns.Owner = Info.Owner
AND Columns.Table_Name = Info.Table_Name
ORDER BY
Columns.Owner,
Columns.Table_Name,
Columns.Column_Id;This next query get CONSTRAINTs. No formatting is used, because it becomes quite unweildy (though, if it used multiple lines, that would change). Another interesting thing is whether the CONSTRAINT names were generated or not. If they were generated, this still uses the old name and does not generate a new one:
WITH
Cons_Columns
AS
SELECT
Owner,
Constraint_Name,
SUBSTR
REPLACE
REPLACE
XMLAgg(XMLElement("A", Column_Name)
'<A>',
'</A>'
4
) || '"' List
FROM
SELECT
Owner,
Constraint_Name,
Column_Name
FROM
All_Cons_Columns
ORDER BY
Position
GROUP BY
Owner,
Constraint_Name
SELECT
'ALTER TABLE ' || Table_Name
|| ' ADD CONSTRAINT ' || Constraint_Name
|| ' '
|| CASE Constraint_Type
WHEN 'C' THEN 'CHECK'
WHEN 'U' THEN 'UNIQUE'
WHEN 'P' THEN 'PRIMARY KEY'
WHEN 'R' THEN 'FOREIGN KEY'
END
|| '('
|| CASE
WHEN Constraint_Type = 'C' THEN
SELECT
ExtractValue
DBMS_XMLGEN.GetXMLType
SELECT
Search_Condition
FROM
All_Constraints
WHERE
Owner = ''' || Cons.Owner || '''
AND Constraint_Name = ''' || Cons.Constraint_Name || '''
'ROWSET/ROW/SEARCH_CONDITION'
FROM
Dual
WHEN Constraint_Type IN ('P', 'R', 'U') THEN
SELECT
List
FROM
Cons_Columns
WHERE
Cons_Columns.Owner = Cons.Owner
AND Cons_Columns.Constraint_Name = Cons.Constraint_Name
END
|| ')'
|| CASE Constraint_Type
WHEN 'R' THEN
SELECT
' REFERENCES (' || List || ')'
FROM
Cons_Columns
WHERE
Cons_Columns.Owner = Cons.R_Owner
AND Cons_Columns.Constraint_Name = Cons.R_Constraint_Name
|| ' ON DELETE ' || Delete_Rule
ELSE ''
END
|| ' ' || DEFERRABLE || ' ' || DEFERRED
|| ' ' || VALIDATED || ' ' || STATUS || RTRIM(' ' || RELY)
|| ';'
FROM
All_Constraints Cons
WHERE
Owner = 'SYS'
ORDER BY
1,
Constraint_Name;Shoblock, thanx!
For NUMBER is was using a wrong COLUMN, and also in the wrong order. Serves me right for not following the documentation. And, i just ignored FLOAT. But not it mostly matches DESC (except this query shows the ", 0" where DESC drop it instead).
I fixed the query above.
The XML part that gets the long has a failure. If the Data_Default contains an XML special char it will get encoded. The way to not encode it, it looks, requires PL/SQL. Which means it would not be done in one query (without a FUNCTION).
I am curious if anyone else is interested in such queries, whether for "fun" or otherwise. -
SQL*Plus: Comment appears in Default-Column
Please look at this commands, executed in SQL*Plus (Oracle 10g):
create table t1 (
c1 number,
c2 number default 0 -- comment in sqlplus
select column_name,data_default from all_tab_columns where table_name='T1';
COLUMN_NAME DATA_DEFAULT
C1
C2 0 -- comment in sqlplus
The comment is stored in the data dictionary! ?:|
insert into t1 (c1) values (0);
commit;
But the default clause works:
select c1,c2 from t1;
C1 C2
+0 0+
Is it a bug or is it a feature???
Greetings from Germany
WolfgangFrom: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_constraints.htm#sthref626
Setting Default Column Values
Default values can be defined using any literal
Bug or feature?
It depends on how literal you interprete literals?
!http://www.designer-daily.com/wp-content/uploads/2009/06/bug-feature.jpg! -
How to concatenage text to data_default col of all_tab_columns.
Hi,
i want to concatinate text to a columen like this but it is show error ,so i thought to convert it but could not get correct code.
select 'dff' || data_default || 'df' from all_tab_columns
yours sincerleyHi,
data default is a LONG datatype. You cannot convert it straight away to VARCHAR2.
I would suggest you to have a look at this: Ask Tom: Long to Varchar2 conversion.
In the same page Tom has put an example about getting default value for columns:
ops$tkyte%ORA11GR2> create or replace function get_col_default
2 (
3 p_owner in all_tab_cols.owner%type,
4 p_table_name in all_tab_cols.table_name%type,
5 p_column_name in all_tab_cols.column_name%type
6 )
7 return varchar2
8 as
9 l_data_default LONG;
10 begin
11 select data_default into l_data_default
12 from all_tab_cols
13 where owner = p_owner
14 and table_name = p_table_name
15 and column_name = p_column_name;
16
17 return substr( l_data_default, 1, 4000 );
18 end;
19 /
Function created.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> column d format a20
ops$tkyte%ORA11GR2> select owner, table_name, column_name, get_col_default( owner, table_name,
column_name ) d
2 from all_tab_cols
3 where get_col_default( owner, table_name, column_name ) is not null
4 and rownum <= 5
5 /
OWNER TABLE_NAME COLUMN_NAME D
SYS HS$_PARALLEL_METADATA PARALLEL 'Y'
SYS HS$_PARALLEL_METADATA PARALLEL_DEGREE 4
SYS HS$_PARALLEL_METADATA RANGE_PARTITIONED 'N'
SYS HS$_PARALLEL_METADATA SAMPLED 'N'
SYS HS$_PARALLEL_METADATA HISTOGRAM 'N'Regards.
Al -
Getting all_tab_columns.data_default in a ddl trigger
Under 10.1.0.3 I'm working on an AFTER CREATE or ALTER on DATABASE system trigger, and I'm querying all_tab_columns in the trigger body. It seems that if the trigger fires in response to DDL that modifies a column's default value, then all_tab_columns.data_default is giving me the column's old default. I want to get the current default value. If I create the table or add a column, then, in the resulting fire of the system trigger, all_tab_columns.data_default seems to be correct.
Is this documented behavior? Should I be looking somewhere (or somewhen) else for the column default?Thanks.
I tried working around this by putting my code into a procedure, and then using the DDL trigger to create a job that runs the code. My idea was to defer the all_tab_columns query until after the DDL trigger was done, and thus get a clean look at the data dictionary.
I put what looks like the appropriate dbms_scheduler calls into the trigger, but when I then execute DDL to fire the trigger I get "ORA-04092: cannot in a trigger"
The doc for this error number says that I am trying to commit or rollback in a trigger, but I'm not explicitly doing that. Also, the error message is supposed to have either the word "commit" or the word "rollback" in the message to tell me what I am doing. Instead, though, the error message just has a space there.
Maybe I'll start a TAR and see if 10.1.0.3 can get appended to the growing list of versions tied to this bug. -
NEED HELP IN USING ALL_TAB_COLUMNS FOR RETRIEVING DATA???
A table say T1 contains column like Emp_id,Code.
and there are several Code like C1,C2,C3.
Another table say T2 contains column like
Emp_id,C1,C2,C3.Here the value of the code field of the
T1 table is now column of the T2 table.And the amount of
each code of T1 table is equal to column value of T2
table.
Now I want to retrieve data from T2 table like
C1 200
C2 300
C3 140
I cannot retrieve data like this using all_tab_columns.
I can only getting the column_name but cannot its value.
PLEASE HELP ME...
Edited by: user630863 on Apr 8, 2009 11:37 AMemp_id | code
001 | C1
001 | C2
005 | C3
005 | C1
002 | C2
002 | C3
Table T1
emp_id | C1 | C2 | C3
001 | 10 | 15 |
002 | | 7 | 12
005 | 45 | | 94
Table T2
I have written a query
select column_name from all_tab_columns a,T1 b
where a.column_name=b.code
and table_name='T2'
OUTPUT:
C1
C2
C3
But I Need data for each employee like
001 C1 10
001 C2 15
002 C2 7
002 C3 12
005 C1 45
005 C3 94
Edited by: user630863 on Apr 8, 2009 1:28 PM -
Good morning,
I have here a SQL query that searches for entries in "user_tab_columns".
Unfortunately the mentioned entries are not present there (but they are present in "all_tab_columns", but I also think that the query is correct.
Therefore I wonder:
is it possible to modify the database (using granting permissions, DB links or other) so that the mentioned entries in "all_tab_columns" also get visible in "user_tab_columns"?
Thanks
DominiqueHi, Dominique,
You can create a private synonym called user_tab_columns that will stand for all_tab_columns
CREATE SYNONYM user_tab_columns FOR sys.all_tab_columns;That means, whenever you say user_tab_columns, Oracle will understand you really want sys.all_tab_columns.
If you need to reference the real user_tab_columns, then you can create another synonym like this:
CREATE SYNONYM real_user_tab_columns FOR sys.user_tab_columns;This will affect only the user who creates the synonym. If you log in as DOMINIQUE, then anyone logged in as DOMINIQUE will be affected, but people who log in as SCOTT (for example) will not be. (Of course, SCOTT can also create a priovate synonym, which would only affect users logged in as SCOTT).
Remember that sys.all_tab_columns and sys.user_table_columns are different. Something that was designed to work in user_tab_columns will not necessarily work in all_tab_columns. For example, a query that finds how many columns are in the emp table. If dominique.emp has 5 columns, then when dominique runs
SELECT COUNT (*) AS total_columns
FROM user_tab_columns
WHERE table_name = 'EMP';the answer will be 5, but if dominque has privileges on the scott.emp table, which has 8 columns, then the results of:
SELECT COUNT (*) AS total_columns
FROM all_tab_columns
WHERE table_name = 'EMP';will be 5 + 8 = 13, which is not the correct number of columns in either emp table.
Edited by: Frank Kulash on Aug 11, 2011 12:46 PM
Corrected typos -
Accessing ALL_TAB_COLUMNS from a Procedure
Hi,
I want a help in Accessing ALL_TAB_COLUMNS from a procedure.
I am an getting Error as Insufficient Privileges while Executing the Procedure.
Any help will be Benefitial
Thanks and RegardsYou should not really be using SYS.
Is this a general issue with accessing "ALL_" views (i.e. information about other schemas than your own) within procedures? If so perhaps the account needs SELECT ANY DICTIONARY system privilege. although as with any system privilege you should consider the security implications.
If it's specifically ALL_TAB_COLUMNS and not the rest of the dictionary views, then a grant on that view to the owner of the package will do it. -
Duplicates in all_tab_columns
I have found duplicates in the all_tab_columns data dictionary view, where both rows have the same owner, table_name, and column_name, but have different column_id and one row shows the column as nullable and the other row shows the column as not nullable. However, only one such entry exists in the user_tab_columns data dictionary view. Is there any rational explanation for this or is corruption the only possibility?
The database in question is used for development and testing and is periodically modified to match the production database. I know that one of the DBA's has been using TOAD to do this, but I don't know what the exact process has been and he is on vacation at the moment.
This problem exists in multiple tables and multiple columns. In each case, the columns in question were formerly part of a primary key, but that has been changed so that the primary key now uses other columns.
Below is just one small example that shows the duplicates in all_tab_columns, but not in user_tab_columns.
Barbara Boehmer
SQL*Plus: Release 8.0.6.0.0 - Production on Wed Mar 12 23:57:07 2003
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
SQL> SELECT table_name, column_name, column_id, nullable
2 FROM all_tab_columns
3 WHERE user = USER
4 AND table_name = 'ADDRESSES'
5 AND column_name = 'ADDR__EVNT_SEQ'
6 /
TABLE_NAME COLUMN_NAME COLUMN_ID N
ADDRESSES ADDR__EVNT_SEQ 39 Y
ADDRESSES ADDR__EVNT_SEQ 4 N
SQL> SELECT table_name, column_name, column_id, nullable
2 FROM user_tab_columns
3 WHERE user = USER
4 AND table_name = 'ADDRESSES'
5 AND column_name = 'ADDR__EVNT_SEQ'
6 /
TABLE_NAME COLUMN_NAME COLUMN_ID N
ADDRESSES ADDR__EVNT_SEQ 39 YBarbara, in your all_tab_columns query, you have put a condition 'user = USER'.
I think you meant to say 'owner = USER'. If you add owner to the result set, the two rows should have different owners.
barryt> create table addresses (addr__evnt_seq int not null);
Table created.
barryt> grant select on addresses to rms;
Grant succeeded.
barryt> @connect
rms> create table addresses (dummy int not null, addr__evnt_seq int);
Table created.
rms> select table_name, column_name, column_id, nullable
2 from all_tab_columns
3 where user = USER -- applies no filter
4 and table_name = 'ADDRESSES'
5 and column_name = 'ADDR__EVNT_SEQ';
TABLE_NAME COLUMN_NAME COLUMN_ID N
ADDRESSES ADDR__EVNT_SEQ 2 Y
ADDRESSES ADDR__EVNT_SEQ 1 N
2 rows selected.
rms> select owner, table_name, column_name, column_id, nullable
2 from all_tab_columns
3 where table_name = 'ADDRESSES'
4 and column_name = 'ADDR__EVNT_SEQ';
OWNER TABLE_NAME
COLUMN_NAME COLUMN_ID N
RMS ADDRESSES
ADDR__EVNT_SEQ 2 Y
BARRYT ADDRESSES
ADDR__EVNT_SEQ 1 N
2 rows selected.
rms> select table_name, column_name, column_id, nullable
2 from all_tab_columns
3 where owner = USER
4 and table_name = 'ADDRESSES'
5 and column_name = 'ADDR__EVNT_SEQ';
TABLE_NAME COLUMN_NAME COLUMN_ID N
ADDRESSES ADDR__EVNT_SEQ 2 Y
1 row selected.
rms> select table_name, column_name, column_id, nullable
2 from user_tab_columns
3 where table_name = 'ADDRESSES'
4 and column_name = 'ADDR__EVNT_SEQ';
TABLE_NAME COLUMN_NAME COLUMN_ID N
ADDRESSES ADDR__EVNT_SEQ 2 Y -
DATA_LENGTH in all_tab_columns in BYTE/CHAR???
Hi
in the Oracle 11gR2 or 10gR2 documentation you find the following description of ALL_TAB_COLUMNS.DATA_LENGTH.
DATA_LENGTH NUMBER NOT NULL Length of the column (*in bytes*)But what about VARCHAR2 fields which have been created with
NLS_LENGTH_SEMANTICS='CHAR'My observation is, that in 10g ALL_TAB_COLUMNS.DATA_LENGTH shows the length in what ever mode, you have created the table. So, if I have created a VARCHAR2 field as VARCHAR2(4 CHAR), then ALL_TAB_COLUMNS.DATA_LENGTH will show 4. In 11g however the field shows really the length in bytes. So I observed data_length=16 for a field which had been defined as VARCHAR2(4 CHAR) on a 11gR2 database with NLS_CHARACTERSET= "AL32UTF8".
Is there any contrary observation or experience?Thanks guys,
you are right my 10g DB used to have
NLS_CHARACTERSET WE8ISO8859P1which makes everything very clear.
Very helpful is the field CHAR_LENGTH and CHAR_USED which indeed contain the information I need.
Thanks. -
Raw Values in all_tab_columns (8i)
I want to retreive Low_value and High_value from all_tab_columns. These fields use the raw datatype. How do I convert them to a decimal number. I am using Oracle 8i.
Thanks,
Les SmithHi,
Thanks everyone who replied to my question. I found the stats table created by the DBMS_STATS package would store the low_value and high_value in a decimal format. I used the DBMS_STATS.EXPORT_TABLE_STATS procedure to take the system statistics and place them in a user stats table.
Here is the approach I took:
DECLARE
BEGIN
--CREATE A USER TABLE TO HOLD THE STATISTICS
DBMS_STATS.CREATE_STAT_TABLE (
'ADW',
'STATS_TAB');
--RUN STATS TO POPULATE SYSTEM STAT TABLE
SYS.DBMS_STATS.GATHER_TABLE_STATS (
'ADW',
'MSF');
DBMS_STATS.EXPORT_TABLE_STATS (
ownname => 'ADW',
tabname => 'MSF',
stattab => 'STATS_TAB');
END;
SELECT
C4 AS COLUMN_NAME,
N1 AS NUM_DISTINCT,
N5 AS NUM_NULLS,
N6 AS LOW_VALUE,
N7 AS HIGH_VALUE,
N8 AS AVG_COL_LENGTH
FROM STATS_TAB
WHERE TYPE ='C' -
Difference between user_tab_columns and all_tab_columns
Hi,
Can anybody please let me know what are the differeneces between user_tab_columns and all_tab_columns.
Thank you.Hi,
In addition to sybrand_b information
ALL_TAB_COLUMNS is a view that has an entry for every column of every table of every users schema, describes the columns of the tables, views, and clusters accessible to the current user
USER_TAB_COLUMNS is a view that has an entry for every column of every table in a certain user's schema. When you use desc on a table to show the columns of that table the order of the columns shown is determined by the position that you can see when you look at the column_id in all_tab_columns and/or user_tab_columns. The DBA may change the order of these columns. It is very important not to assume that the columns are in a certain order and will stay that way, describes the columns of the tables, views, and clusters owned by the current user. Its columns (except for OWNER) are the same as those in "ALL_TAB_COLUMNS
:) -
Want to construct insert statement from all_tab_columns
I am using Oracle 10GR2 and a new user for plsql
I want to write a plsql block or SQL in order to insert some dummy data.
I want to use the column list from all_tab_columns and want to construct insert statement
EX: I am trying to construct SQL as below
for i in (select column_name from all_tab_columns where table_name='EMP')
loop
v_sql := insert into emptest valuesi.column_name
could you please let me know any pointer for the same ..?
can I use any other technique for the same .. like collection, nested table etcAm not clear for this requirement, if possible could you please elaborate.
Also specify the requirement, inputs and expected outputs with your query in code format...
This will help..
Maybe you are looking for
-
Service billing for the material and service registers
Dear All, I have doubt, if i do a sale of material 'X' and for the same material if i have to do a service invoice for rendering some service at the customer end. eg:- service charges for transportaion of the material to the customer place, doing ins
-
Not getting profile in Target Info for Distribution
Hi, I have followed all the required steps given in Program Portal. I created distribution certificates, profile and etc. When i am trying to install this mobile profile into iphone, it doesn't take this profile. I am not getting my profile in Target
-
I need help setting up a network
I am not sure how to go about doing this or if it even possible. I would like to setup a network where 4 or 5 computers will have access to each others shared folders and be able to used the printer on the main computer. I have one desktop that will
-
Linking parameters in a subreport
Hello All, How do i link parameters in a sub report. I have 2 subreports and I have to link them with cascading dynamic parameters For the first sub report I an using 1st level of the parameter and for second report I am using 2 level of the dynamic
-
How to export dynpros to files
Hi, I have to export several sap objets (reports, smartforms, dynpros, alvs, etc.) to files (binary or text) in order to store it in a external database. For example, I use RSTXSCRP report to export sapscript and smartforms, but now I need to export