SQL to get table structure

Does anybody know of a SQL statement that will give me structure of a table? I've uses DESC, but if possible need to get the primary key, foreign key, and any constraints for the table. I've done searches on forum, but haven't found anything close, with the exception of DESC.
Thanks for any help anybody can provide.
Darrel

Does anybody know of a SQL statement that will give me structure of a table? I've uses DESC, but if possible need to get the primary key, foreign key, and any constraints for the table. I've done searches on forum, but haven't found anything close, with the exception of DESC.
Thanks for any help anybody can provide.
Darrel SELECT uc.constraint_name, uc.constraint_type, uc.table_name, ucc.column_name
FROM user_constraints uc, user_cons_columns ucc
WHERE uc.constraint_name = ucc.constraint_name;
Darrel,
The above query from the data dictionary view should help you. You can also use the user_ views below to get other information (just DESC any of these views to see the column names).
Regards,
Emily
USER_ALL_TABLES
USER_ARGUMENTS
USER_ASSOCIATIONS
USER_AUDIT_OBJECT
USER_AUDIT_SESSION
USER_AUDIT_STATEMENT
USER_AUDIT_TRAIL
USER_CATALOG
USER_CLU_COLUMNS
USER_CLUSTER_HASH_EXPRESSIONS
USER_CLUSTERS
USER_COL_COMMENTS
USER_COL_PRIVS
USER_COL_PRIVS_MADE
USER_COL_PRIVS_RECD
USER_COLL_TYPES
USER_CONS_COLUMNS
USER_CONSTRAINTS
USER_DB_LINKS
USER_DEPENDENCIES
USER_DIM_ATTRIBUTES
USER_DIM_CHILD_OF
USER_DIM_HIERARCHIES
USER_DIM_JOIN_KEY
USER_DIM_LEVEL_KEY
USER_DIM_LEVELS
USER_DIMENSIONS
USER_DUMP_DEST
USER_DUMP_DEST
USER_ERRORS
USER_EXTENTS
USER_EXTENTS
USER_FREE
USER_FREE_SPACE
USER_HISTOGRAMS
USER_ID
USER_IND_COLUMNS
USER_IND_PARTITIONS
USER_IND_SUBPARTITIONS
USER_INDEXES
USER_INDEXTYPE_OPERATORS
USER_INDEXTYPES
USER_JOBS
USER_LIBRARIES
USER_LOB_PARTITIONS
USER_LOB_SUBPARTITIONS
USER_LOBS
USER_METHOD_PARAMS
USER_METHOD_RESULTS
USER_MVIEW_AGGREGATES
USER_MVIEW_ANALYSIS
USER_MVIEW_DETAIL_RELATIONS
USER_MVIEW_JOINS
USER_MVIEW_KEYS
USER_NESTED_TABLES
USER_OBJ_AUDIT_OPTS
USER_OBJECT_SIZE
USER_OBJECT_TABLES
USER_OBJECTS
USER_OPANCILLARY
USER_OPARGUMENTS
USER_OPBINDINGS
USER_OPERATORS
USER_OULTINE_HINTS
USER_OUTLINE_HINTS
USER_OUTLINES
USER_OUTLINES
USER_PART_COL_STATISTICS
USER_PART_HISTOGRAMS
USER_PART_INDEXES
USER_PART_KEY_COLUMNS
USER_PART_LOBS
USER_PART_TABLES
USER_PARTIAL_DROP_TABS
USER_PASSWORD_LIMITS
USER_POLICIES
USER_QUEUE_SCHEDULES
USER_QUEUE_TABLES
USER_QUEUES
USER_REFRESH
USER_REFRESH_CHILDREN
USER_REFS
USER_REGISTERED_SNAPSHOTS
USER_REPCATLOG
USER_REPCOLUMN
USER_REPCOLUMN_GROUP
USER_REPCONFLICT
USER_REPDDL
USER_REPGENERATED
USER_REPGENOBJECTS
USER_REPGROUP
USER_REPGROUPED_COLUMNS
USER_REPKEY_COLUMNS
USER_REPOBJECT
USER_REPPARAMETER_COLUMN
USER_REPPRIORITY
USER_REPPRIORITY_GROUP
USER_REPPROP
USER_REPRESOL_STATS_CONTROL
USER_REPRESOLUTION
USER_REPRESOLUTION_METHOD
USER_REPRESOLUTION_STATISTICS
USER_REPSITES
USER_RESOURCE_LIMITS
USER_ROLE_PRIVS
USER_RSRC_CONSUMER_GROUP_PRIVS
USER_RSRC_MANAGER_SYSTEM_PRIVS
USER_RULESETS
USER_SEGMENTS
USER_SEGMENTS
USER_SEQUENCES
USER_SNAPSHOT_LOGS
USER_SNAPSHOT_REFRESH_TIMES
USER_SNAPSHOTS
USER_SOURCE
USER_SUBPART_COL_STATISTICS
USER_SUBPART_HISTOGRAMS
USER_SUBPART_KEY_COLUMNS
USER_SYNONYMS
USER_SYS_PRIVS
USER_TAB_COL_STATISTICS
USER_TAB_COLUMNS
USER_TAB_COLUMNS
USER_TAB_COMMENTS
USER_TAB_HISTOGRAMS
USER_TAB_PARTITIONS
USER_TAB_PRIVS
USER_TAB_PRIVS_MADE
USER_TAB_PRIVS_RECD
USER_TAB_SUBPARTITIONS
USER_TABLES
USER_TABLESPACES
USER_TRIGGER_COLS
USER_TRIGGERS
USER_TS_QUOTAS
USER_TYPE_ATTRS
USER_TYPE_METHODS
USER_TYPES
USER_UPDATABLE_COLUMNS
USER_USERS
USER_USTATS
USER_VARRAYS
USER_VIEWS

Similar Messages

  • EXEC SQL - GET DATABASE STRUCTURE - RECREATE IN SAP

    Our system is connected to PS.
    II'd like to write a program that does the following
    get the structure of the database
    create the structure in SAP
    SELECT THE DATA OF THE TABLE
    This would be done in order to maintain the structure manually
    The problem is to get the structure from external database (exec sql)
    Thanks for your help!
    Regards,

    Hi stephan,
    1. In oracle , there is one standard view
       eg. V_ALL_TAB_FIELDS
       in which we pass the table name,
      and it returns, the records,
      for the fieldnames, field type, its length, its sequence number etc.
    2. Similarly u may discover for PS also.
    regards,
    amit m.

  • ORA-31603:While Extracting SQL of a table I am getting this error.

    Hi,
    I am getting below error whenever I try to get the SQL for any table. I tried executing DBMS_METADATA() also but the same error is coming.
    Please let me know what needs to be done IF I want to extract the DDL for any object.
    ORA-31603: object "EMP" of type TABLE not found in schema "MKT"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 3241
    ORA-06512: at "SYS.DBMS_METADATA", line 4812
    ORA-06512: at line 1
    Thanks,
    Rusty....

    Hi,
    use AUTHID CURRENT_USER show as below exmaple...
    CREATE OR REPLACE FUNCTION xx_get_ddl(
    p_object_type IN VARCHAR2
    , p_object_name IN VARCHAR2
    , p_owner IN VARCHAR2
    RETURN CLOB AUTHID CURRENT_USER
    IS
    v_string CLOB;
    BEGIN
    SELECT DBMS_METADATA.get_ddl(p_object_type
    , p_object_name
    , p_owner
    INTO v_string
    FROM DUAL;
    RETURN v_string;
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN NULL;
    END;

  • How to generate sql script based on table structure

    I want to generate a sql script based on a table structure.
    For example:
    if the table is:
    cid id c_value
    1 1 zz
    2 1 yy
    3 2 zz
    4 2 xx
    5 3 ss
    6 3 tt
    The expected output is:
    WITH
    CHILD_tab as (
    SELECT 1 cid, 1 id,'zz' c_value from dual union all
    SELECT 2 cid, 1 id,'yy' c_value from dual union all
    SELECT 3 cid, 2 id,'zz' c_value from dual union all
    SELECT 4 cid, 2 id,'xx' c_value from dual union all
    SELECT 5 cid, 3 id,'ss' c_value from dual union all
    SELECT 6 cid, 3 id,'tt' c_value from dual )
    Release 11.1.0.7.0

    I'm doing a lot of XML these days (too much perhaps) so here's a solution involving XQuery.
    We pass a query string and it outputs a CLOB containing the WITH clause :
    SELECT DBMS_XMLGEN.Convert(
    XMLQuery(
    q'[concat(
    "WITH t AS (
    string-join(
    for $i in /ROWSET/ROW
    return concat( " SELECT ",
                    string-join($i/*/concat("'",ora:replace(text(),"'","''"),"' ",local-name()),", "),
                    " FROM dual" ),
    " UNION ALL
    passing dbms_xmlgen.getXMLType('SELECT * FROM scott.emp')
    returning content
    ).getClobVal(), 1) AS WITH_CLAUSE
    FROM dual;
    WITH_CLAUSE
    WITH t AS (
    SELECT '7369' EMPNO, 'SMITH' ENAME, 'CLERK' JOB, '7902' MGR, '17/12/80' HIREDATE, '800' SAL, '20' DEPTNO FROM dual UNION ALL
    SELECT '7499' EMPNO, 'ALLEN' ENAME, 'SALESMAN' JOB, '7698' MGR, '20/02/81' HIREDATE, '1600' SAL, '300' COMM, '30' DEPTNO FROM dual UNION ALL
    SELECT '7521' EMPNO, 'WARD' ENAME, 'SALESMAN' JOB, '7698' MGR, '22/02/81' HIREDATE, '1250' SAL, '500' COMM, '30' DEPTNO FROM dual UNION ALL
    SELECT '7566' EMPNO, 'JONES' ENAME, 'MANAGER' JOB, '7839' MGR, '02/04/81' HIREDATE, '2975' SAL, '20' DEPTNO FROM dual UNION ALL
    SELECT '7654' EMPNO, 'MARTIN' ENAME, 'SALESMAN' JOB, '7698' MGR, '28/09/81' HIREDATE, '1250' SAL, '1400' COMM, '30' DEPTNO FROM dual UNION ALL
    SELECT '7698' EMPNO, 'BLAKE' ENAME, 'MANAGER' JOB, '7839' MGR, '01/05/81' HIREDATE, '2850' SAL, '30' DEPTNO FROM dual UNION ALL
    SELECT '7782' EMPNO, 'CLARK' ENAME, 'MANAGER' JOB, '7839' MGR, '09/06/81' HIREDATE, '2450' SAL, '10' DEPTNO FROM dual UNION ALL
    SELECT '7788' EMPNO, 'SCOTT' ENAME, 'ANALYST' JOB, '7566' MGR, '19/04/87' HIREDATE, '3000' SAL, '20' DEPTNO FROM dual UNION ALL
    SELECT '7839' EMPNO, 'KING' ENAME, 'PRESIDENT' JOB, '17/11/81' HIREDATE, '5000' SAL, '10' DEPTNO FROM dual UNION ALL
    SELECT '7844' EMPNO, 'TURNER' ENAME, 'SALESMAN' JOB, '7698' MGR, '08/09/81' HIREDATE, '1500' SAL, '0' COMM, '30' DEPTNO FROM dual UNION ALL
    SELECT '7876' EMPNO, 'ADAMS' ENAME, 'CLERK' JOB, '7788' MGR, '23/05/87' HIREDATE, '1100' SAL, '20' DEPTNO FROM dual UNION ALL
    SELECT '7900' EMPNO, 'JAMES' ENAME, 'CLERK' JOB, '7698' MGR, '03/12/81' HIREDATE, '950' SAL, '30' DEPTNO FROM dual UNION ALL
    SELECT '7902' EMPNO, 'FORD' ENAME, 'ANALYST' JOB, '7566' MGR, '03/12/81' HIREDATE, '3000' SAL, '20' DEPTNO FROM dual UNION ALL
    SELECT '7934' EMPNO, 'MILLER' ENAME, 'CLERK' JOB, '7782' MGR, '23/01/82' HIREDATE, '1300' SAL, '10' DEPTNO FROM dual
    )It may be useful for small data sets only because we quickly hit ORA-01706.

  • Howto export table structure as sql script.

    is there any way to export the table structure and thier linkage from oracle db into standard sql script?
    thanks

    Sorry, this is the Oracle Repository forum.
    However, Perform an oracle export from the schema i.e.
    exp un/pw rows=n
    and then perform an import:
    imp un/pw indexfile=afile.txt
    This will will have all the structure you need but will need editing to create a runnable script.
    Alternatively use Oracle Designer to reverse engineer your schema, the DDL can then be generated.
    David

  • Load table structure definition from Sql server and mirroring

    Hi, we have to replicate some tables from sql server
    into SAP dictionary.
    Is there a tool/transaction for import the table structure
    from a DBRMS like sql/oracle ?
    Adn is there some third part solution for replicate data
    from/to sql server and Sap ?
    Thanks in advance.
    Riccardo Galli.

    Hi,
    Dont know if there are any tools for this but onething is sure you will need to create the table thru SE11.
    I had done something similar, created a BDC to create table and it works.
    Provide the BDC with list of fields, datatype, len, key fields and the BDC will create the table.
    You will need to activate the table once its created, for some reason sap put the table in "partial active" status after creation .
    Good luck.
    Ravi

  • Load Data from a table on one server's database, to the same table structure in multiple server databases

    Hi,
    I have a situation where i have to load data from one server/database table to multiple servers/databases.
    Example:
    I need to load data from dbo.TABLE_A  (on Server: Server_A & Database: Database_A)  to the same table on the list of server databases like
    Server: Server_B , Database: Database_B
    Server: Server_C , Database: Database_C
    Server: Server_D , Database: Database_D
    Server: Server_E , Database: Database_E
    Server: Server_F , Database: Database_F
    Server: Server_G , Database: Database_G
    Server: Server_H , Database: Database_H
    so on and so forth on 250 such server database combinations.
    The table structure is the same on all the servers.
    If i make the source or destination dynamic, it throws an error while mapping ?
    I cannot get Linked server permissions and SQL Server Config thing doesn't work as well.
    Please suggest on how to load data from one source to multiple server/databases.
    Thank you.

    I just need to transfer one table's data. its like i have to use a query to pick data for
    the most recent data. So i use something like, select A, B, C, D from dbo.table where ETL_TIMESTAMP > (the max(etltimestamp) in the destination on different server). There are no foreign key relationships and the data should not be truncated. it just had
    to append the new records.

  • TIPS(18) : CREATING SCRIPTS TO RECREATE A TABLE STRUCTURE

    제품 : SQL*PLUS
    작성날짜 : 1996-11-12
    TIPS(18) : Creating Scripts to Recreate a Table Structure
    =========================================================
    The script creates scripts that can be used to recreate a table structure.
    For example, this script can be used when a table has become fragmented or to
    get a defintion that can be run on another database.
    CREATES SCRIPT TO RECREATE A TABLE-STRUCTURE
    INCL. STORAGE, CONSTRAINTS, TRIGGERS ETC.
    This script creates scripts to recreate a table structure.
    Use the script to reorganise a table that has become fragmented,
    to get a definition that can be run on another database/schema or
    as a basis for altering the table structure (eg. drop a column!).
    IMPORTANT: Running the script is safe as it only creates two new scripts and
    does not do anything to your database! To get anything done you have to run the
    scripts created.
    The created scripts does the following:
    1. save the content of the table
    2. drop any foreign key constraints referencing the table
    3. drop the table
    4. creates the table with an Initial storage parameter that
    will accomodate the entire content of the table. The Next
    parameter is 25% of the initial.
    The storage parameters are picked from the following list:
    64K, 128K, 256K, 512K, multiples of 1M.
    5. create table and column comments
    6. fill the table with the original content
    7. create all the indexes incl storage parameters as above.
    8. add primary, unique key and check constraints.
    9. add foreign key constraints for the table and for referencing
    tables.
    10.Create the table's triggers.
    11.Compile any depending objects (cascading).
    12.Grant table and column privileges.
    13.Create synonyms.
    This script must be run as the owner of the table.
    If your table contains a LONG-column, use the COPY
    command in SQL*Plus to store/restore the data.
    USAGE
    from SQL*Plus:
    start reorgtb
    This will create the scripts REORGS1.SQL and REORGS2.SQL
    REORGS1.SQL contains code to save the current content of the table.
    REORGS2.SQL contains code to rebuild the table structure.
    undef tab;
    set echo off
    column a1 new_val stor
    column b1 new_val nxt
    select
    decode(sign(1024-sum(bytes)/1024),-1,to_char((round(sum(bytes)/(1024*1
    024))+1))||'M', /* > 1M new rounded up to nearest Megabyte */
    decode(sign(512-sum(bytes)/1024), -1,'1M',
    decode(sign(256-sum(bytes)/1024), -1,'512K',
    decode(sign(128-sum(bytes)/1024), -1,'256K',
    decode(sign(64-sum(bytes)/1024) , -1,'128K',
    '64K'
    a1,
    decode(sign(1024-sum(bytes)/4096),-1,to_char((round(sum(bytes)/(4096*1
    024))+1))||'M', /* > 1M new rounded up to nearest Megabyte */
    decode(sign(512-sum(bytes)/4096), -1,'1M',
    decode(sign(256-sum(bytes)/4096), -1,'512K',
    decode(sign(128-sum(bytes)/4096), -1,'256K',
    decode(sign(64-sum(bytes)/4096) , -1,'128K',
    '64K'
    b1
    from user_extents
    where segment_name=upper('&1');
    set pages 0 feed off verify off lines 150
    col c1 format a80
    spool reorgs1.sql
    PROMPT drop table bk_&1
    prompt /
    PROMPT create table bk_&1 storage (initial &stor) as select * from &1
    prompt /
    spool off
    spool reorgs2.sql
    PROMPT spool reorgs2
    select 'alter table '||table_name||' drop constraint
    '||constraint_name||';'
    from user_constraints where r_constraint_name
    in (select constraint_name from user_constraints where
    table_name=upper('&1')
    and constraint_type in ('P','U'));
    PROMPT drop table &1
    prompt /
    prompt create table &1
    select decode(column_id,1,'(',',')
    ||rpad(column_name,40)
    ||decode(data_type,'DATE' ,'DATE '
    ,'LONG' ,'LONG '
    ,'LONG RAW','LONG RAW '
    ,'RAW' ,'RAW '
    ,'CHAR' ,'CHAR '
    ,'VARCHAR' ,'VARCHAR '
    ,'VARCHAR2','VARCHAR2 '
    ,'NUMBER' ,'NUMBER '
    ,'unknown')
    ||rpad(
    decode(data_type,'DATE' ,null
    ,'LONG' ,null
    ,'LONG RAW',null
    ,'RAW' ,decode(data_length,null,null
    ,'('||data_length||')')
    ,'CHAR' ,decode(data_length,null,null
    ,'('||data_length||')')
    ,'VARCHAR' ,decode(data_length,null,null
    ,'('||data_length||')')
    ,'VARCHAR2',decode(data_length,null,null
    ,'('||data_length||')')
    ,'NUMBER' ,decode(data_precision,null,' '
    ,'('||data_precision||
    decode(data_scale,null,null
    ,','||data_scale)||')')
    ,'unknown'),8,' ')
    ||decode(nullable,'Y','NULL','NOT NULL') c1
    from user_tab_columns
    where table_name = upper('&1')
    order by column_id
    prompt )
    select 'pctfree '||t.pct_free c1
    ,'pctused '||t.pct_used c1
    ,'initrans '||t.ini_trans c1
    ,'maxtrans '||t.max_trans c1
    ,'tablespace '||s.tablespace_name c1
    ,'storage (initial '||'&stor' c1
    ,' next '||'&stor' c1
    ,' minextents '||t.min_extents c1
    ,' maxextents '||t.max_extents c1
    ,' pctincrease '||t.pct_increase||')' c1
    from user_Segments s, user_tables t
    where s.segment_name = upper('&1') and
    t.table_name = upper('&1')
    and s.segment_type = 'TABLE'
    prompt /
    select 'comment on table &1 is '''||comments||''';' c1 from
    user_tab_comments
    where table_name=upper('&1');
    select 'comment on column &1..'||column_name||
    ' is '''||comments||''';' c1 from user_col_comments
    where table_name=upper('&1');
    prompt insert into &1 select * from bk_&1
    prompt /
    set serveroutput on
    declare
    cursor c1 is select index_name,decode(uniqueness,'UNIQUE','UNIQUE')
    unq
    from user_indexes where
    table_name = upper('&1');
    indname varchar2(50);
    cursor c2 is select
    decode(column_position,1,'(',',')||rpad(column_name,40) cl
    from user_ind_columns where table_name = upper('&1') and
    index_name = indname
    order by column_position;
    l1 varchar2(100);
    l2 varchar2(100);
    l3 varchar2(100);
    l4 varchar2(100);
    l5 varchar2(100);
    l6 varchar2(100);
    l7 varchar2(100);
    l8 varchar2(100);
    l9 varchar2(100);
    begin
    dbms_output.enable(100000);
    for c in c1 loop
    dbms_output.put_line('create '||c.unq||' index '||c.index_name||' on
    &1');
    indname := c.index_name;
    for q in c2 loop
    dbms_output.put_line(q.cl);
    end loop;
    dbms_output.put_line(')');
    select 'pctfree '||i.pct_free ,
    'initrans '||i.ini_trans ,
    'maxtrans '||i.max_trans ,
    'tablespace '||i.tablespace_name ,
    'storage (initial '||
    decode(sign(1024-sum(e.bytes)/1024),-1,
    to_char((round(sum(e.bytes)/(1024*1024))+1))||'M',
    decode(sign(512-sum(e.bytes)/1024), -1,'1M',
    decode(sign(256-sum(e.bytes)/1024), -1,'512K',
    decode(sign(128-sum(e.bytes)/1024), -1,'256K',
    decode(sign(64-sum(e.bytes)/1024) , -1,'128K',
    '64K'))))) ,
    ' next '||
    decode(sign(1024-sum(e.bytes)/4096),-1,
    to_char((round(sum(e.bytes)/(4096*1024))+1))||'M',
    decode(sign(512-sum(e.bytes)/4096), -1,'1M',
    decode(sign(256-sum(e.bytes)/4096), -1,'512K',
    decode(sign(128-sum(e.bytes)/4096), -1,'256K',
    decode(sign(64-sum(e.bytes)/4096) , -1,'128K',
    '64K'))))) ,
    ' minextents '||s.min_extents ,
    ' maxextents '||s.max_extents ,
    ' pctincrease '||s.pct_increase||')'
    into l1,l2,l3,l4,l5,l6,l7,l8,l9
    from user_extents e,user_segments s, user_indexes i
    where s.segment_name = c.index_name
    and s.segment_type = 'INDEX'
    and i.index_name = c.index_name
    and e.segment_name=s.segment_name
    group by s.min_extents,s.max_extents,s.pct_increase,
    i.pct_free,i.ini_trans,i.max_trans,i.tablespace_name ;
    dbms_output.put_line(l1);
    dbms_output.put_line(l2);
    dbms_output.put_line(l3);
    dbms_output.put_line(l4);
    dbms_output.put_line(l5);
    dbms_output.put_line(l6);
    dbms_output.put_line(l7);
    dbms_output.put_line(l8);
    dbms_output.put_line(l9);
    dbms_output.put_line('/');
    end loop;
    end;
    declare
    cursor c1 is
    select constraint_name, decode(constraint_type,'U',' UNIQUE',' PRIMARY
    KEY') typ,
    decode(status,'DISABLED','DISABLE',' ') status from user_constraints
    where table_name = upper('&1')
    and constraint_type in ('U','P');
    cname varchar2(100);
    cursor c2 is
    select decode(position,1,'(',',')||rpad(column_name,40) coln
    from user_cons_columns
    where table_name = upper('&1')
    and constraint_name = cname
    order by position;
    begin
    for q1 in c1 loop
    cname := q1.constraint_name;
    dbms_output.put_line('alter table &1');
    dbms_output.put_line('add constraint '||cname||q1.typ);
    for q2 in c2 loop
    dbms_output.put_line(q2.coln);
    end loop;
    dbms_output.put_line(')' ||q1.status);
    dbms_output.put_line('/');
    end loop;
    end;
    declare
    cursor c1 is
    select c.constraint_name,c.r_constraint_name cname2,
    c.table_name table1, r.table_name table2,
    decode(c.status,'DISABLED','DISABLE',' ') status,
    decode(c.delete_rule,'CASCADE',' on delete cascade ',' ')
    delete_rule
    from user_constraints c,
    user_constraints r
    where c.constraint_type='R' and
    c.r_constraint_name = r.constraint_name and
    c.table_name = upper('&1')
    union
    select c.constraint_name,c.r_constraint_name cname2,
    c.table_name table1, r.table_name table2,
    decode(c.status,'DISABLED','DISABLE',' ') status,
    decode(c.delete_rule,'CASCADE',' on delete cascade ',' ')
    delete_rule
    from user_constraints c,
    user_constraints r
    where c.constraint_type='R' and
    c.r_constraint_name = r.constraint_name and
    r.table_name = upper('&1');
    cname varchar2(50);
    cname2 varchar2(50);
    cursor c2 is
    select decode(position,1,'(',',')||rpad(column_name,40) colname
    from user_cons_columns
    where constraint_name = cname
    order by position;
    cursor c3 is
    select decode(position,1,'(',',')||rpad(column_name,40) refcol
    from user_cons_columns
    where constraint_name = cname2
    order by position;
    begin
    dbms_output.enable(100000);
    for q1 in c1 loop
    cname := q1.constraint_name;
    cname2 := q1.cname2;
    dbms_output.put_line('alter table '||q1.table1||' add constraint ');
    dbms_output.put_line(cname||' foreign key');
    for q2 in c2 loop
    dbms_output.put_line(q2.colname);
    end loop;
    dbms_output.put_line(') references '||q1.table2);
    for q3 in c3 loop
    dbms_output.put_line(q3.refcol);
    end loop;
    dbms_output.put_line(') '||q1.delete_rule||q1.status);
    dbms_output.put_line('/');
    end loop;
    end;
    col c1 format a79 word_wrap
    set long 32000
    set arraysize 1
    select 'create or replace trigger ' c1,
    description c1,
    'WHEN ('||when_clause||')' c1,
    trigger_body ,
    '/' c1
    from user_triggers
    where table_name = upper('&1') and when_clause is not null
    select 'create or replace trigger ' c1,
    description c1,
    trigger_body ,
    '/' c1
    from user_triggers
    where table_name = upper('&1') and when_clause is null
    select 'alter trigger '||trigger_name||decode(status,'DISABLED','
    DISABLE',' ENABLE')
    from user_Triggers where table_name='&1';
    set serveroutput on
    declare
    cursor c1 is
    select 'alter table
    '||'&1'||decode(substr(constraint_name,1,4),'SYS_',' ',
    ' add constraint ') a1,
    decode(substr(constraint_name,1,4),'SYS_','
    ',constraint_name)||' check (' a2,
    search_condition a3,
    ') '||decode(status,'DISABLED','DISABLE','') a4,
    '/' a5
    from user_constraints
    where table_name = upper('&1') and
    constraint_type='C';
    b1 varchar2(100);
    b2 varchar2(100);
    b3 varchar2(32000);
    b4 varchar2(100);
    b5 varchar2(100);
    fl number;
    begin
    open c1;
    loop
    fetch c1 into b1,b2,b3,b4,b5;
    exit when c1%NOTFOUND;
    select count(*) into fl from user_tab_columns where table_name =
    upper('&1') and
    upper(column_name)||' IS NOT NULL' = upper(b3);
    if fl = 0 then
    dbms_output.put_line(b1);
    dbms_output.put_line(b2);
    dbms_output.put_line(b3);
    dbms_output.put_line(b4);
    dbms_output.put_line(b5);
    end if;
    end loop;
    end;
    create or replace procedure dumzxcvreorg_dep(nam varchar2,typ
    varchar2) as
    cursor cur is
    select type,decode(type,'PACKAGE BODY','PACKAGE',type) type1,
    name from user_dependencies
    where referenced_name=upper(nam) and referenced_type=upper(typ);
    begin
    dbms_output.enable(500000);
    for c in cur loop
    dbms_output.put_line('alter '||c.type1||' '||c.name||' compile;');
    dumzxcvreorg_dep(c.name,c.type);
    end loop;
    end;
    exec dumzxcvreorg_dep('&1','TABLE');
    drop procedure dumzxcvreorg_Dep;
    select 'grant '||privilege||' on '||table_name||' to '||grantee||
    decode(grantable,'YES',' with grant option;',';') from
    user_tab_privs where table_name = upper('&1');
    select 'grant '||privilege||' ('||column_name||') on &1 to
    '||grantee||
    decode(grantable,'YES',' with grant option;',';')
    from user_col_privs where grantor=user and
    table_name=upper('&1')
    order by grantee, privilege;
    select 'create synonym '||synonym_name||' for
    '||table_owner||'.'||table_name||';'
    from user_synonyms where table_name=upper('&1');
    PROMPT REM
    PROMPT REM YOU MAY HAVE TO LOG ON AS SYSTEM TO BE
    PROMPT REM ABLE TO CREATE ANY OF THE PUBLIC SYNONYMS!
    PROMPT REM
    select 'create public synonym '||synonym_name||' for
    '||table_owner||'.'||table_name||';'
    from all_synonyms where owner='PUBLIC' and table_name=upper('&1') and
    table_owner=user;
    prompt spool off
    spool off
    set echo on feed on verify on
    The scripts REORGS1.SQL and REORGS2.SQL have been
    created. Alter these script as necesarry.
    To recreate the table-structure, first run REORGS1.SQL.
    This script saves the content of your table in a table
    called bk_.
    If this script runs successfully run REORGS2.SQL.
    The result is spooled to REORGTB.LST.
    Check this file before dropping the bk_ table.
    */

    Please do NOT cross-postings: create a deep structure for dynamic internal table
    Regards
      Uwe

  • Table structure and constraints in HTML table

    This script creates a html file (Structure.html) that contains structure of a specific table.
    When the following script is executed in sql * plus, it asks for the table name for which
    structure information is needed. after entering the table name, it writes the table structure
    into structure.html file.
    SET LINESIZE 150
    SET PAGESIZE 150
    SET FEEDBACK OFF
    SET VERIFY OFF
    COLUMN "COLUMN NAME" FORMAT A50
    COLUMN "DATA TYPE" FORMAT A15
    COLUMN "IS NULL" FORMAT A15
    COLUMN CONSTRAINTS FORMAT A15
    PROMPT Enter table name:
    ACCEPT TABNAME
    SET MARK HTML ON
    SPOOL STRUCTURE.html
    PROMPT &TABNAME
    -- Query ---
    SELECT TRIM(A.COLUMN_NAME) AS "COLUMN NAME",
    TRIM(DATA_TYPE||'('||DECODE(A.DATA_LENGTH,22,A.DATA_PRECISION||','||A.DATA_SCALE,
    A.DATA_LENGTH) || ')') AS "DATA TYPE",
    TRIM(DECODE(A.NULLABLE,'Y',' ','NOT NULL')) AS "IS NULL",
    TRIM(DECODE(C.CONSTRAINT_TYPE,'P','PRIMARY KEY','R','FOREIGN KEY('||D.TABLE_NAME||')','U','UNIQUE', 'C','CHECK')) AS CONSTRAINTS,
    TRIM(C.CONSTRAINT_NAME) AS "CONSTRAINT NAME",
    C.SEARCH_CONDITION AS "CHECK CONDITION",
    A.DATA_DEFAULT AS "DEFAULT VALUE"
    FROM USER_TAB_COLS A,
    USER_CONS_COLUMNS B,
    USER_CONSTRAINTS C,
    USER_CONS_COLUMNS D
    WHERE
    A.TABLE_NAME = '&TABNAME' AND
    A.TABLE_NAME = B.TABLE_NAME(+) AND
    A.COLUMN_NAME = B.COLUMN_NAME(+) AND
    B.CONSTRAINT_NAME = C.CONSTRAINT_NAME(+) AND
    C.R_CONSTRAINT_NAME = D.CONSTRAINT_NAME(+);
    SPOOL OFF
    SET MARK HTML OFF

    Hi,
    For Head Count you can use 0HR_PA_0 datasource and the other Employee details like start date and end date you can get them from employee master data and FTE can be calculated from the Emloyee Master Data and Head count data.
    Hope this helps...
    Thanks,

  • Export and import only table structure

    Hi ,
    I have two schema scott and scott2. scott schema is having table index and procedure and scott2 schema is fully empty.
    Now i want the table structure, indexes and procedure from scott schema to scott2 schema. No DATA needed.
    What is the query to export table structure, indexes and procedure from scott schema and import in scott2 schema.
    Once this done, i want scott schema should have full access to scott2 schema.
    Oracle Database 10g Release 10.2.0.1.0 - 64bit Production
    Please help...

    Pravin wrote:
    I used rows=n
    it giving me below error while importing dump file:-
    IMP-00003: ORACLE error 604 encountered
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01013: user requested cancel of current operation^CYou are getting this error because you hit "Ctrl C" during the import, which essentially cancels the import.
    IMP-00017: following statement failed with ORACLE error 604:
    "CREATE TABLE "INVESTMENT_DETAILS_BK210509" ("EMP_NO" VARCHAR2(15), "INFOTYP"
    "E" VARCHAR2(10), "SBSEC" NUMBER(*,0), "SBDIV" NUMBER(*,0), "AMOUNT" NUMBER("
    "*,0), "CREATE_DATE" DATE, "MODIFY_DATE" DATE, "FROM_DATE" DATE, "TO_DATE" D"
    "ATE) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 6684672"
    " FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "DMSTG" LOGG"
    "ING NOCOMPRESS"Srini

  • Getting DTD structure from Oracle DOMParser

    I am having trouble getting DTD structure from DOMParser after I parse the xml file with external DTD.
    When I do:
    xmlDOMParser.parse(new FileInputStream(xmlFile));
    XMLDocument xmlDoc=xmlDOMParser.getDocument();
    DTD docType=xmlDOMParser.getDoctype();
    NamedNodeMap nodeMap=docType.getElementDecls();
    the nodeMap is equal to null.
    I need to get the element structure of DTD, how can I do that?

    The below example is working fine for me
    create table t1
       as
        select object_id id, object_name text
          from all_objects;
    Create table t2
      as
      select t1.*, 0 session_id
        from t1
       where 1=0;
    CREATE OR REPLACE TYPE t2_type
    AS OBJECT (
      id         number,
      text       varchar2(30),
      session_id number
    create or replace type t2_tab_type
    as table of t2_type
    create or replace
      function parallel_pipelined( l_cursor in sys_refcursor )
      return t2_tab_type
      pipelined
      parallel_enable ( partition l_cursor by any )
      is
          l_session_id number;
          l_rec        t1%rowtype;
      begin
          select sid into l_session_id
            from v$mystat
           where rownum =1;
          loop
              fetch l_cursor into l_rec;
              exit when l_cursor%notfound;
              -- complex process here
              pipe row(t2_type(l_rec.id,l_rec.text,l_session_id));
          end loop;
          close l_cursor;
          return;
      end;
      /And its getting executed in parallel
    SQL> select DISTINCT session_id
      2    from table(parallel_pipelined
      3              (CURSOR(select /*+ parallel(t1) */ *
      4                        from t1 )
      5               ))
      6  ;
    SESSION_ID
           221
            76
            77
           241
           161
           152
           160
           302
           232
           313
            73
    SESSION_ID
           292
    12 rows selected.But why its getting disconnected in my scenario. ???

  • Com.sap.sql.log.OpenSQLException: table or view not exists

    Hi!.
    I'm developing a Portal Component over NW EP 2004s (7.0) which access to SQL Server database. I have created three tables on the system db (EPD). Connection is Ok, over datasource object, but i can't make a SELECT operation to my new tables.
    Hovewer, making a SELECT operation over older system tables is OK.
    I have adjusted permissions on my new tables, similar to the older tables. The table's owner is the same too.
    The exception i get is:
    **Exception of type com.sap.sql.log.OpenSQLException caught: The SQL statement "SELECT * FROM "SAPEPDDB"."UME_EP_UNLOCKUSERS"" contains the semantics error[s]: - 1:24 - the table or view >>UME_EP_UNLOCKUSERS<< does not exist**
    [EXCEPTION]
    *com.sap.sql.log.OpenSQLException: The SQL statement "SELECT * FROM "SAPEPDDB"."UME_EP_UNLOCKUSERS"" contains the semantics error[s]: - 1:24 - the table or view >>UME_EP_UNLOCKUSERS<< does not exist*
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.check(StatementAnalyzerImpl.java:38)
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.preprepareStatement(StatementAnalyzerImpl.java:101)
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.preprepareStatement(StatementAnalyzerImpl.java:87)
    at com.sap.sql.jdbc.common.CommonStatementImpl.executeQuery(CommonStatementImpl.java:114)
    at com.sap.engine.services.dbpool.wrappers.StatementWrapper.executeQuery(StatementWrapper.java:172)
    at com.uralita.database.DbManager.executeQuery(DbManager.java:105)
    at com.uralita.ListaSistemas$ListaSistemasDynPage.getSystemsR3(ListaSistemas.java:184)
    at com.uralita.ListaSistemas$ListaSistemasDynPage.doInitialization(ListaSistemas.java:93)
    at com.sapportals.htmlb.page.PageProcessor.handleRequest(PageProcessor.java:105)
    at com.sapportals.portal.htmlb.page.PageProcessorComponent.doContent(PageProcessorComponent.java:134)
    at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
    at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
    at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
    at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
    at com.sapportals.portal.prt.core.async.AsyncIncludeRunnable$1$DoDispatchRequest.run(AsyncIncludeRunnable.java:377)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sapportals.portal.prt.core.async.AsyncIncludeRunnable.run(AsyncIncludeRunnable.java:390)
    at com.sapportals.portal.prt.core.async.ThreadContextRunnable.run(ThreadContextRunnable.java:164)
    at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:729)
    at java.lang.Thread.run(Thread.java:534)
    Caused by: com.sap.sql.sqlparser.CommonSQLParserException: - 1:24 - the table or view >>UME_EP_UNLOCKUSERS<< does not exist
    at com.sap.sql.sqlparser.CommonSQLStatement.checkSemantics(CommonSQLStatement.java:171)
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.check(StatementAnalyzerImpl.java:35)
    ... 19 more
    caused by
    com.sap.sql.sqlparser.CommonSQLParserException: - 1:24 - the table or view >>UME_EP_UNLOCKUSERS<< does not exist
    at com.sap.sql.sqlparser.CommonSQLStatement.checkSemantics(CommonSQLStatement.java:171)
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.check(StatementAnalyzerImpl.java:35)
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.preprepareStatement(StatementAnalyzerImpl.java:101)
    at com.sap.sql.jdbc.common.StatementAnalyzerImpl.preprepareStatement(StatementAnalyzerImpl.java:87)
    at com.sap.sql.jdbc.common.CommonStatementImpl.executeQuery(CommonStatementImpl.java:114)
    at com.sap.engine.services.dbpool.wrappers.StatementWrapper.executeQuery(StatementWrapper.java:172)
    at com.uralita.database.DbManager.executeQuery(DbManager.java:105)
    at com.uralita.ListaSistemas$ListaSistemasDynPage.getSystemsR3(ListaSistemas.java:184)
    at com.uralita.ListaSistemas$ListaSistemasDynPage.doInitialization(ListaSistemas.java:93)
    at com.sapportals.htmlb.page.PageProcessor.handleRequest(PageProcessor.java:105)
    at com.sapportals.portal.htmlb.page.PageProcessorComponent.doContent(PageProcessorComponent.java:134)
    at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
    at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
    at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
    at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
    at com.sapportals.portal.prt.core.async.AsyncIncludeRunnable$1$DoDispatchRequest.run(AsyncIncludeRunnable.java:377)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sapportals.portal.prt.core.async.AsyncIncludeRunnable.run(AsyncIncludeRunnable.java:390)
    at com.sapportals.portal.prt.core.async.ThreadContextRunnable.run(ThreadContextRunnable.java:164)
    at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:729)
    at java.lang.Thread.run(Thread.java:534)
    Someone has been getting this problem? Any idea?
    Thanks!

    I have tried that.
    [EXCEPTION]
    *com.sap.sql.log.OpenSQLException: The SQL statement "SELECT * FROM EPD.SAPEPDDB.UME_EP_SLD" contains the syntax error[s]: - Open SQL syntax error: table names must not specify a catalog name (delete "EPD". before "SAPEPDDB"."UME_EP_SLD")*
    Database name must be Ok, because i can access to other tables which are in the same DB...
    Thanks for your help

  • PL/SQL: ORA-00942: table or view does not exist

    Hi
    i have logged into my schema and trying to access the database "DAD" which has the table name "SCHOOL"
    i wrote a function which should give me new_sno when i give it the old_sno
    and i have this errors , pls help
    CREATE OR REPLACE FUNCTION ORIG_SN(OSNO in Number,OTN in Number)
    RETURN Number IS
    NEW_SNO Number:=0;
    BEGIN
    SELECT new_sno AS NEW_SNO
    FROM DAD.SCHOOL
    WHERE ORIG_SNO = OSNO AND ORIG_TN = OTN;
    RETURN NEW_SNO;
    END ORIG_SN;
    Warning: Function created with compilation errors.
    Errors for FUNCTION ORIG_SN:
    LINE/COL ERROR
    5/1 PL/SQL: SQL Statement ignored
    6/15 PL/SQL: ORA-00942: table or view does not exist
    Thanks in advance ..

    Try this,
    CREATE VIEW SCHOOL_VIEW AS SELECT * FROM DAD.SCHOOL;and then change your function like
    CREATE OR REPLACE FUNCTION ORIG_SN(OSNO in Number,OTN in Number)
    RETURN Number IS
    my_new_sno Number:=0;
    BEGIN
    SELECT new_sno INTO my_new_sno FROM SCHOOL_VIEW WHERE ORIG_SNO = OSNO AND ORIG_TN = OTN;
    RETURN my_new_sno;
    END ORIG_SN;and see if it is getting created without any errors.
    -Arun
    Edited by: Arunkumar Ramamoorthy on Aug 15, 2009 1:56 AM

  • How to delete a row from a SQL Server CE Table with multiple JOINs?

    I want to delete a record from a SQL Server CE table.
    There are 3 tables scripts, options and results. I would like to remove a record from the results table. The where clause contains dynamic information which retrieved via other queries to different tables in the same database. These queries work fine and deliver
    the desired data.
    The Compact server is a clone of a remote table created using the sync framework. The same query to the remote table works fine.
    The error I get is:
    There was an error parsing the query. [ Token line number = 1,Token line offset = 10,Token in error = from ]
    The code that throws the exception is as follows:
    Dim connLoc As SqlCeConnection = New SqlCeConnection(My.Settings.ConnectionString)connLoc.Open()     Dim strDel As String = "Delete r from ResultsTable r inner join OptionsTable o ON o.TestName=r.TestName inner join ScriptTable c ON r.TestName=c.TestName WHERE r.TestName = '" & ds1Loc.Tables(0).Rows(0)(1) & "' AND [Index] = '" & lstIndex & "'"Dim cmdDel As SqlCeCommand = New SqlCeCommandcmdDel.CommandText = strDelcmdDel.Connection = connLoccmdDel.ExecuteNonQuery()
    The values held in ds1Loc.Tables(0).Rows(0)(1) and lstIndex are
    correct so should not be the problem.
    I also tried using parameterised queries
    Dim strDel As String = "Delete r from [ResultsTable] r inner join [OptionsTable] o ON o.TestName=r.TestName inner join [ScriptTable] c ON r.TestName=c.TestName WHERE r.TestName = @TestName AND [Index] = @lstIndex"
    Dim cmdDel As SqlCeCommand = New SqlCeCommand        cmdDel.CommandText = strDel       
    With cmdDel.Parameters           
    .Add(New SqlCeParameter("@TestName", ds1Loc.Tables(0).Rows(0)(1)))           
    .Add(New SqlCeParameter("@lstIndex", lstIndex))       
    End With 
    cmdDel.Connection = connLoc        cmdDel.ExecuteNonQuery()
    I have tried replacing the "=" with "IN" in the the WHERE clause but this has not worked.
    Is it the join that is causing the problem? I can do a select with the same search criteria and joins from the same database.
    Also this query works with SQL Server. Is it perhaps that SQL CE does not support the Delete function the same as SQL Server 2008? I have been looking at this for a while now and cannot find the source of the error. Any help would be greatly appreciated.

    Hello,
    In SQL Server Compact, we can use join in FROM clause. The DELETE statement fail may be caused by the FOREIGN KEY constraint.
    Please refer to:
    DELETE (SQL Server Compact)
    FROM Clause (SQL Server Compact)
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Error(20,22): PL/SQL: ORA-00942: table or view does not exist

    I am getting currently getting an error when I try and insert into a table from a different schema from my Stored Procedure:
    Error(20,22): PL/SQL: ORA-00942: table or view does not exist
    I am explicitly calling the table with the schema name infront i.e.
    INSERT INTO SAPSR3.ZTREC_NAME_TYPE
    MASTER_ID,
    NAME_TYPE,
    FAMILY_NAME,
    FIRST_NAME,
    MIDDLE_NAME,
    TITLE
    VALUES
    In_MasterID,
    In_NameType,
    In_FamilyName,
    In_FirstName,
    In_MiddleName,
    In_Title
    I only get this error when I try and compile my stored procedure. If I try this insert not within a stored procedure (i.e. a blank script) it works perfectly.
    Can anyone tell me what Im doing wrong?
    Thanks.

    Hi,
    It sounds like you (the procedure owner) have privileges on that table only through a role.
    Roles don't count in stored procedures created with AUTHID OWNER (which is the default).
    Either
    (1) Have user SAPSR3 grant the necessary privileges directly to you (or to PUBLIC), or
    (2) change the procedure so that it runs with the caller's privileges, by adding AUTHID CURRENT_USER after the argument list but before the keyword IS (os AS) like this:
    CREATE OR REPLACE PROCEDURE     foo
    (     x     IN     NUMBER
    AUTHID CURRENT_USER
    IS ...

Maybe you are looking for

  • OVI map problem with E52

    Hi,      Iv been using E52 for the past 11 months and loved the way OVI maps worked but about 2 months back i had some serious problem related to keypad and since the customer care couldn't fix it they replaced it with a new E52. I am not able to use

  • Mac pro part# FA356LL/A - need to add compatible Airport card?

    Mac pro part# FA356LL/A (refurbished i think changes the part number from MA356LL/A)- but im not sure... I need to know what airport card it can take?  802.11b/g/ or n It never had one and was always used via network cable. Now i want it to have wire

  • I cannot view clips on the viewer window - as it appears black, However, I can still hear the sounds in the background.

    Hello! I cannot view any of the clips (not from event browser nor from timeline) on the viewer window - as it appears black/or blank/ or static ! However, I can still hear the sounds in the background. P.S I have chosen the filter: ALL Please help me

  • Separate midi drum channels not showing in piano roll, only kick

    hey ya'll!  I separated my midi drum notes on to separate mudi tracks. But now only the kick track shows up in the piano roll window. I am using AD and need to be able to edit the drum midi tracks. I use the piano roll window for this. Can someone he

  • Create Proxy in PI Server error ?

    Dear XI Expert, I got problem when generating proxy class in PI server it selft. The error during activation of the Proxy class related to the Package. " Package ZPI-FI does not have sufficient use access " Please advise. Thank You and Best Regards F