condition_de_recherche in user_constraints

Hello!

I would like to know how to do a select statement as follows:

SELECT * FROM USER_CONSTRAINTS WHERE SEARCH_CONDITION = 'PASS BETWEEN 0 AND 15';

I'm using Oracle 11 g Enterprise Edition Release 11.2.0.2.0.

If you can afford some time waiting for the result, you can use this:

select *
from xmltable(
      '/ROWSET/ROW'
      passing dbms_xmlgen.getXMLType('select constraint_name, search_condition from user_constraints where search_condition is not null')
      columns constraint_name  varchar2(30)   path 'CONSTRAINT_NAME'
            , search_condition varchar2(4000) path 'SEARCH_CONDITION'
     )
where search_condition = 'my string'
;

Tags: Database

Similar Questions

  • invalid column user_constraints

    Hi all

    What is the use of invalid, View_related columns in the user_constriants table. Can you tell me an example.

    Select invalid, View_related from user_constraints;

    I can give an example of "view_related" but I can't reproduce anything related to the column "invalid."

    SQL> --My database version.
    SQL> ----------------------
    SQL> SELECT * FROM v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE VIEW emp_view
      2  AS
      3    SELECT * FROM emp WHERE deptno=20
      4* WITH CHECK OPTION CONSTRAINT my_view_constraint
    SQL> /
    
    View created.
    
    SQL> ALTER VIEW emp_view ADD CONSTRAINT emp_view_pk PRIMARY KEY (empno) disable novalidate;
    
    View altered.
    
    SQL> set line 500
    SQL> ed
    Wrote file afiedt.buf
    
      1  SELECT owner,
      2    constraint_name,
      3    constraint_type,
      4    table_name,
      5    view_related
      6  FROM user_constraints
      7* WHERE constraint_name IN ('EMP_VIEW_PK', 'MY_VIEW_CONSTRAINT')
    SQL> /
    
    OWNER                                                                                                                    CONSTRAINT_NAME                C TABLE_NAME                     VIEW_RELATED
    ------------------------------------------------------------------------------------------------------------------------ ------------------------------ - ------------------------------ --------------
    SCOTT                                                                                                                    MY_VIEW_CONSTRAINT             V EMP_VIEW
    SCOTT                                                                                                                    EMP_VIEW_PK                    P EMP_VIEW                       DEPEND ON VIEW
    
    SQL> 
    

    You can see that WITH check option does not have the column "view_related."

  • Select the data in user_cons, user_constraints, user_cons_columns

    Dear Sirs, I want to select the name of the table and its referential tables and constraint_names and column used in this referencial constraints
    I use this selection, but it doesn't look good
    Select t.table_name, t.ref_name, c.constraint_name, m.column_name
    of user_cons t, user_constraints c, user_cons_columns m
    where
    c.table_name = t.table_name
    and m.table_name = c.table_name
    and m.constraint_name = c.constraint_name
    and constraint_type = 'R '.
    and c.table_name like '% STK '.
    order of table_name, constraint_name


    Please help me
    Yasser

    Yasser,

    Try this SQL.

    SELECT A.TABLE_NAME CHILD_TABLE_NAME, D.TABLE_NAME MASTER_TABLE_NAME, A.CONSTRAINT_NAME CHILD_CONSTRAINT_NAME, A.R_CONSTRAINT_NAME MASTER_CONSTRAINT_NAME, C.COLUMN_NAME CHILD_COLUMN, D.COLUMN_NAME MASTER_COLUMN
    FROM USER_CONSTRAINTS A, USER_CONS_COLUMNS C, USER_CONS_COLUMNS D
    WHERE A.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND A.R_CONSTRAINT_NAME = D.CONSTRAINT_NAME AND A.TABLE_NAME LIKE 'STK%'
    ORDER BY A.TABLE_NAME, A.CONSTRAINT_NAME
    

    Kind regards

    Manu.

    If my answer or the answer to another person has been useful or appropriate, please mark accordingly

    Published by: Manu. April 27, 2010 15:19

  • Need to retrieve the names of columns with PK

    Hi all

    guys I need to get two columns (PK information and secondly with the column name) for the table. I see that's not so easy with Oracle ;(

    I have this for now:

    SELECT all_tab_cols.column_name,user_constraints.constraint_type
    FROM   all_tab_cols, user_cons_columns, user_constraints,user_ind_columns, user_indexes
     WHERE  all_tab_cols.column_name = user_cons_columns.column_name (+)
       AND  all_tab_cols.table_name = user_cons_columns.table_name (+)
       AND  user_cons_columns.constraint_name = user_constraints.constraint_name (+)
       AND  user_constraints.constraint_type (+) = 'P'
       AND  user_ind_columns.column_name (+) = all_tab_cols.column_name
       AND  user_ind_columns.table_name (+) = all_tab_cols.table_name
       AND  user_indexes.uniqueness (+) = 'UNIQUE'
       AND  user_indexes.index_name (+) = user_ind_columns.index_name
       AND  all_tab_cols.table_name = 'MYTABLE' 
    

    but, if KP is then take result duplicate me lines and there is not a simpler way? just need to list all columns of the table with information about the PK

    SELECT acc.column_name,
      ac.constraint_name
    FROM all_constraints ac,
      all_cons_columns acc
    WHERE ac.owner        =acc.owner
    AND ac.constraint_name=acc.constraint_name
    AND ac.table_name     =acc.table_name
    AND ac.constraint_type='P'
    AND ac.table_name     = 'MY_TABLE'
    UNION
    SELECT column_name,NULL FROM all_tab_columns WHERE table_name='MY_TABLE';
    
  • All objects

    Hi Master,

    I have table in my schema, and I need to find all the db objects that are created on my table. (triggers, views, indexes, synonyms, etc.).

    How can I get the details? Please help me.

    the synonymous triggers views index table name

    EMP abc xyz kkk empl

    Dept xyz abc yyy det

    Concerning

    AR

    following queries might help

    Select * from USER_DEPENDENCIES where REFERENCED_name = 'TABLE_NAME ';

    SELECT TABLE_NAME FROM USER_CONSTRAINTS WHERE R_CONSTRAINT_NAME IN

    (SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'TABLE_NAME')

  • Large partition table with the primary key referenced by several child tables

    I tested this procedure and it works perfectly. Although when children tables refer to the key column, after execution of dbms_redefinition.finish_redef_table they all are referring to table exercised. In test I deal forced FK droped on tables children and recreated them. What could be the best way to do this in this scenario?

    Thanks for all comments/opinions!

    Are you sure? You should end up with the original FK constraint (disabled and renamed to have a prefix of $$ TMP) pointing to the staging table (which is of course the famous original table), and allowed a new constraint with the correct name, pointing to the new version of the table. so all you need to do to bring order to the top is to remove the constraint of renamed.

    This running-in of the SCOTT schema clearly indicates:

    create the table deptint in select * from dept where 1 = 2;

    exec dbms_redefinition.start_redef_table (user, 'dept', 'deptint')

    n number of var

    exec dbms_redefinition.copy_table_dependents (user, "dept', 'deptint', DBMS_REDEFINITION.") CONS_ORIG_PARAMS, TRUE, TRUE, TRUE, TRUE,: n)

    Print n

    exec dbms_redefinition.finish_redef_table (user, 'dept', 'deptint')

    Select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, user_constraints STATE;

  • Create procedure upsert (name of the existing table, incoming table name)

    Is it possible to create a procedure that makes a merge (upsert) with only two parameters:

    1. Existing Table name - name of table that will have data merged into it.
    2. Incoming Table name - name of the table that has developed data day/news.

    The method would be:

    1. Use primary keys on the "existing" table as the condition links
    2. Fact and update if exists and insert new
    3. no record
    4. no clues
    5. no removal clause

    Oracle 11g

    MERGE < tip > < table_name >

    USING < table_view_or_query >

    (< CONDITION >)

    WHEN MATCHED THEN < update_clause >

    DELETE < where_clause >

    WHEN NOT MATCHED THEN < insert_clause >

    [ERRORLOG < log_errors_clause > < reject limit < integer | unlimited >];

    < table_name > - from input parameter

    < table_view_or_query > -socket input parameter

    < condition > - primary key links (how search a single/multiple primary keys and return the list?)

    < update_clause > - update all columns (other than KP, how to get and use a dynamic list of columns)

    < where_clause > - not used

    < insert_clause > - insert new records for all columns (including the PK (s))

    declare

    p_source varchar2 (30): = "EMP_X";

    p_target varchar2 (30): = "EMP_Y";

    query varchar2 (32000);

    function get_cols (p_table in varchar2) return varchar2 is

    VARCHAR2 (32000) retval;

    Start

    Select the Group (order of column_id) listagg (column_name, ',')

    in retval

    of user_tab_cols

    where table_name = p_table

    Table_name group;

    Return retval;

    end;

    function get_keys (p_table in varchar2) return varchar2 is

    VARCHAR2 (4000) retval;

    Start

    Select listagg (cc.column_name, ',') in the Group (order by cc.position)

    in retval

    from user_constraints c,.

    user_cons_columns cc

    where cc.table_name = p_table

    and c.constraint_type = 'P '.

    and cc.table_name = c.table_name

    and cc.constraint_name = c.constraint_name

    C.table_name group;

    Return retval;

    end;

    function merge (p_merge1 varchar2, p_merge2 varchar2, p_link varchar2) return varchar2 is

    Merge1 varchar2 (32000): = p_merge1 | «, » ;

    merge2 varchar2 (32000): = p_merge2 | «, » ;

    VARCHAR2 (32000) retval;

    Start

    then merge1 is not null

    loop

    retval: = retval | » t.'|| substr (Merge1, 1, InStr (Merge1, ',') - 1) |'s =.' | substr (merge2, 1, InStr (merge2, ',') - 1);

    Merge1: = substr (merge1, instr(merge1,',') + 1);

    merge2: = substr (merge2, instr (merge2, ',') + 1);

    If merge1 is not null then

    retval: = retval | p_link;

    end if;

    end loop;

    Return retval;

    end;

    Chopper (p_cols p_keys varchar2, varchar2) return varchar2 is

    passes varchar2 (32000): = ', '. p_cols | «, » ;

    keys varchar2 (32000): = ', '. p_keys | «, » ;

    VARCHAR2 (32000) retval;

    Start

    While the keys! = «, »

    loop

    If instr (passes, substr (keys, 1, instr(keys,',',1,2))) = 1 then

    cols: = substr (collars, instr(cols,',',1,2));

    on the other

    cols: = substr (passes, 1, instr (passes, substr (keys, 1, instr(keys,',',1,2))) | substr (collars, InStr (collars, ',', InStr (passes, substr (Keys, 1, InStr(Keys,',',1,2))), 2) + 1);)

    end if;

    keys: = substr (keys, instr(keys,',',1,2));

    end loop;

    return trim (both ',' collar);

    end;

    Start

    query: = 'merge'. p_target |' t ' |' using (select ' | get_cols (p_source): ' from ' | p_source |') s '.

    ' on ('|) Merger (get_keys (p_target), get_keys (p_source), 'and') |') ' ||

    "When matched then update set ' | '. Merger (Chopper (get_cols (p_target), get_keys (p_target)), Chopper (get_cols (p_source), get_keys (p_source)), ',').

    «When not matched then insert ('|)» get_cols (p_target) |') values (s.'|) Replace (get_cols (p_source),', ', ', s') |') ';

    dbms_output.put_line (Query);

    end;


    Fusion in EMP_Y t using (select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO EMP_X) s on (t.EMPNO = s.EMPNO and t.ENAME = s.ENAME) when matched then update set t.JOB = s.JOB, t.MGR = s.MGR, t.HIREDATE = s.HIREDATE, t.SAL = s.SAL, t.COMM = s.COMM, t.DEPTNO = s.DEPTNO when not matched then insert (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (s.EMPNO, s.ENAME, s.JOB, s.MGR, s.HIREDATE, s.SAL, s.COMM, s.DEPTNO)

    Concerning

    Etbin

  • Online syntax to create Foreign key with Alter Table statement

    I am a pretty meticulous reader. That being said, from the 4 texts that I read to start to learn SQL, I do not remember and do more that probably not, find a syntax online for the creation of a CF with the statement alter table.

    Just something I thought while I was reading.

    Is there a such syntax?

    And if so someone can give me direction on my code?

    ALTER table emp4 change employee_id key foreign employees of references (employe_id);

    It gives me the option error invalid alter table.

    Any idea would be appreciated.

    Thank you.

    rp0428 wrote:

    A foreign key is a constraint, you must use ADD CONSTRAINT.

    Thare is more than one way to skin a cat:

    SQL > create table tbl (id number, name varchar2 (10))
    2.

    Table created.

    SQL > alter table tbl adds (foreign key references emp (empno))
    2.

    Modified table.

    SQL > select constraint_name,.
    2 constraint_type
    3 from user_constraints
    4 where table_name = 'TBL '.
    5.

    CONSTRAINT_NAME C
    ------------------------------ -
    SYS_C0021920 R

    SQL > drop table tbl purge
    2.

    Deleted table.

    SQL > create table tbl (id number, name varchar2 (10))
    2.

    Table created.

    SQL > alter table tbl change (foreign key references emp (empno))
    2.

    Modified table.

    SQL > select constraint_name,.
    2 constraint_type
    3 from user_constraints
    4 where table_name = 'TBL '.
    5.

    CONSTRAINT_NAME C
    ------------------------------ -
    SYS_C0021921 R

    SQL >

    SY.

  • Replacements of the passes of the constraint are not made.

    Hello

    I adjusted the following piece of code pl/sql - in order to show what's wrong. The complete pack is great - it has some errors, I try to debug and modify.

    It's so (as anonymous block) :

    declare

    TYPE columns_rec IS RECORD (c_name VARCHAR2 (32),)

    c_type VARCHAR2 (32),

    c_length number (4,0).

    c_scale number (4,0).

    c_null varchar (20));

    TYPE cols_t IS TABLE OF THE columns_rec;

    p_Pkcols cols_t;

    p_nonPkcols cols_t;

    l_allCols cols_t: = cols_t();

    l_str varchar2 (4000);

    p_prefix varchar2 (50): = 'FA_SITES_NEW.';

    CURSOR c_pk is

    SELECT c.column_name, data_type,

    Decode (data_precision,

    NULL, data_length,

    TO_NUMBER(data_precision-data_scale)) data_length,.

    data_scale,

    Nullable

    Of user_tab_columns c,.

    user_constraints uc,

    user_cons_columns cc

    WHERE uc.owner = USER

    AND uc.constraint_name = cc.constraint_name

    AND c.table_name = cc.table_name

    AND c.column_name = cc.column_name

    AND uc.table_name = cc.table_name

    AND uc.table_name = 'FA_SITES_NEW. '

    AND constraint_type = 'P '.

    ORDER BY cc.position;

    ---------------

    CURSOR c_non_pk is

    SELECT column_name, data_type,

    Decode (data_precision,

    NULL, data_length,

    TO_NUMBER(data_precision-data_scale)) data_length,.

    data_scale,

    Nullable

    C USER_TAB_COLUMNS

    WHERE table_name = 'FA_SITES_NEW '.

    AND NOT EXISTS)

    SELECT 1 FROM user_constraints uc, user_cons_columns cc

    WHERE uc.owner = cc.owner

    AND uc.table_name = c.table_name

    AND cc.column_name = c.column_name

    AND uc.constraint_name = cc.constraint_name

    AND uc.table_name = cc.table_name

    AND constraint_type = 'P')

    order by nullable;

    -------------

    CURSOR c_cons is

    SELECT cc.column_name, c.constraint_name, c.search_condition,

    Decode (c.constraint_type, 'P', 'Pk', 'U', 'Uk', 'R', 'Fk', 'Check') c_type

    From user_constraints c,.

    user_cons_columns cc

    WHERE c.owner = USER

    AND c.constraint_name = cc.constraint_name

    AND c.table_name = cc.table_name

    AND c.owner = cc.owner

    AND c.table_name = 'FA_SITES_NEW. '

    AND constraint_type in ('P', 'R', 'C', 'U')

    ORDER BY decode (c.constraint_type, 'P', 1, 'U', 2, 3);

    Start

    Open c_pk;

    collect the fetch c_pk in bulk in p_Pkcols;

    close c_pk;

    Open c_non_pk;

    collect the fetch c_non_pk in bulk in p_nonPkcols;

    close c_non_pk;

    l_allCols: = p_PkCols p_nonPkcols union multiset;

    FOR cfl_cons in c_cons

    LOOP

    IF upper (cfl_cons.c_type) = 'VERIFICATION' THEN

    l_str: = cfl_cons.search_condition;

    because me l_allCols.first... loop of l_allCols.Last

    l_str: = replace (l_str, l_allCols (i) .c_name, p_prefix | l_allCols (i) .c_name);

    dbms_output.put_line (l_str);

    end loop;

    END IF;

    END LOOP;

    end;

    The script that creates the table is:

    CREATE TABLE FA_SITES_NEW

    (

    AA              NUMBER(5)                     ,

    CODE_CC VARCHAR2 (12-BYTE),

    DESCR_CC VARCHAR2 (60 BYTE),

    CODE_EGK VARCHAR2 (5 BYTE),

    VARCHAR2 (80 BYTE) EGK,

    CODE_THESIS VARCHAR2 (5 BYTE),

    ADDRESS VARCHAR2 (100 BYTE),

    TK VARCHAR2 (8 BYTE),

    DATE OF VALIDDATE_FROM,

    DATE OF VALIDDATE_TO,

    VARCHAR2 (200 BYTE) NOTES,

    LASTINSU VARCHAR2 (20 BYTE),

    DATE OF LASTINSD,

    LASTUPDU VARCHAR2 (20 BYTE),

    DATE OF LASTUPDD,

    CODE_CC_VC VARCHAR2 (15 BYTE) GENERATED ALWAYS AS ("000" |) ("' CODE_CC")

    )

    ;

    ALTER TABLE FA_SITES_NEW ADD)

    CONSTRAINT FA_SITES_NEW_CHK

    CHECK (validdate_from < = validdate_to));

    Now the problem is - except that the constraint appears several times(let's leave it for now) - replacement is not done.

    In other words, the constraint is "validdate_from < = validdate_to ' and I want to be replaced as FA_SITES_NEW.validdate_from < = FA_SITES_NEW.validdate_to (that's why I use l_str: = replace (l_str, l_allCols (i) .c_name, p_prefix | l_allCols (i) .c_name);).

    Instead, the chain remains validdate_from < = validdate_to.

    I also tried to do the replacement in a sql stmt ' select replace (l_str, l_allCols (i) .c_name, p_prefix |)» "l_allCols (i) .c_name) in double l_str", but to no avail.

    Is it possible this minor change to the result?

    NOTE: I use oraDb 11.2.

    Thank you very much

    SIM

    I don't understand. Why do you want to include the name of table to the columns that are used inside the check constraint? This will make the invalid constraint if you rename the table. It seems much better to have the name of the column without a name to additional table.

    The problem could be that the expression within the constraint uses lowercase column names, while your system column names select uppercase letters in the data dictionary. This is why replacing is not picking up the names.

  • Fill a Table using XML?

    Hello

    Can read XML and the insertion/upgrade to update / delete any table?

    Assumes that the XML is stored in a column

    Is there something similar loan?


    With the help of:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
    PL/SQL Release 11.2.0.4.0 - Production
    CORE Production 11.2.0.4.0
    AMT for Linux: Version 11.2.0.4.0 - Production
    NLSRTL Version 11.2.0.4.0 - Production







    A few ideas, using DBMS_XMLSTORE:

    SQL> create table table2 (code varchar2(30) primary key, dt_ini date, aliq_pis number);
    
    Table created.
    
    SQL>
    SQL> create or replace procedure merge_record (p_rec in xmltype)
      2  is
      3
      4    cursor c_tab_cols (p_table_name in varchar2)
      5    is
      6      with pk_cols (column_name) as (
      7        select column_name
      8        from user_cons_columns
      9        where constraint_name = (
     10          select constraint_name
     11          from user_constraints
     12          where table_name = p_table_name
     13          and constraint_type = 'P'
     14        )
     15      )
     16      select tc.column_name
     17           , nvl2(cc.column_name, 'Y', 'N') as is_pk
     18      from user_tab_cols tc
     19           left outer join pk_cols cc on cc.column_name = tc.column_name
     20      where tc.table_name = p_table_name
     21      and tc.virtual_column = 'NO' ;
     22
     23    tab_name  user_tables.table_name%type;
     24    ctx       dbms_xmlstore.ctxHandle;
     25    numrows   number;
     26
     27  begin
     28
     29    -- get embedded table name
     30    select xmlcast(xmlquery('/TABLE/@tableName' passing p_rec returning content) as varchar2(30))
     31    into tab_name
     32    from dual;
     33
     34    -- set target table
     35    ctx := dbms_xmlstore.newContext(tab_name);
     36    -- and row tag name
     37    dbms_xmlstore.setRowTag(ctx, 'TABLE');
     38
     39    -- set columns to update
     40    for r in c_tab_cols (tab_name) loop
     41      dbms_xmlstore.setUpdateColumn(ctx, r.column_name);
     42      if r.is_pk = 'Y' then
     43        dbms_xmlstore.setKeyColumn(ctx, r.column_name);
     44      end if;
     45    end loop;
     46
     47    -- set date format
     48    execute immediate 'alter session set nls_date_format = "YYYY-MM-DD"';
     49
     50    -- update
     51    numrows := dbms_xmlstore.updateXML(ctx, p_rec);
     52
     53    -- if no row updated, try insert
     54    if numrows = 0 then
     55      dbms_xmlstore.clearKeyColumnList(ctx);
     56      numrows := dbms_xmlstore.insertXML(ctx, p_rec);
     57    end if;
     58
     59    dbms_xmlstore.closeContext(ctx);
     60
     61  end;
     62  /
    
    Procedure created.
    
    SQL>
    SQL>
    SQL> exec merge_record(xmltype('2009.70.012007-01-013
    ')) PL/SQL procedure successfully completed. SQL> select * from table2; CODE DT_INI ALIQ_PIS ------------------------------ ----------- ---------- 2009.70.01 01/01/2007 3 SQL> exec merge_record(xmltype('2009.70.012007-01-011
    ')) PL/SQL procedure successfully completed. SQL> exec merge_record(xmltype('2009.70.022007-01-011
    ')) PL/SQL procedure successfully completed. SQL> select * from table2; CODE DT_INI ALIQ_PIS ------------------------------ ----------- ---------- 2009.70.01 01/01/2007 1 2009.70.02 01/01/2007 1
  • Delete records based on the foreign keys of oracle 11 g

    I have a requirement to remove the records from the tables in the order according to

    the existing foreign keys.

    I for example, the following tables and the pk, fk constraints:

    create table one

    (aa number (1),)

    descr varchar2 (20));

    ALTER table one

    Add constraint a_pk key (aa) primary;

    create table b

    (aa number (1),)

    descr varchar2 (20));

    ALTER table b

    Add constraint b_pk key (aa) primary;

    create table c

    (aa number (1),)

    descr varchar2 (20));

    ALTER table c

    Add constraint c_pk key (aa) primary;

    create table a2

    (aa number (2),)

    id_aa number (1).

    descr varchar2 (20));

    ALTER table a2

    Add constraint a2_pk key (aa) primary;

    ALTER table a2

    Add constraint a2_fk foreign key (id_aa)

    references a (aa);

    create table b2

    (aa number (2),)

    id_aa number (1).

    descr varchar2 (20));

    ALTER table b2

    Add constraint b2_pk key (aa) primary;

    ALTER table b2

    Add constraint b2_fk foreign key (id_aa)

    references b (aa);

    create table z

    (aa number (3),)

    id_aa number (1).

    id_bb number (1).

    descr varchar (20));

    ALTER table z

    Add constraint z_pk key (aa) primary;

    ALTER table z

    Add constraint z_fk1 foreign key (id_aa)

    references a (aa);

    ALTER table z

    Add constraint z_fk2 foreign key (id_bb)

    references b (aa);

    So, I want to choose the names of the tables in such an order so as

    deleting records will succeed...

    I built the following sql query (using the recursive subquery factoring):

    [p]

    with q (r_constraint_name, table_name, constraint_name, lvl) as

    (select table_name, constraint_name, r_constraint_name 1 lvl

    from user_constraints one

    where a.constraint_type = 'P '.

    Union of all the

    Select b.table_name b.constraint_name, b.r_constraint_name, q.lvl + 1 lvl

    from user_constraints b

    Join q

    on (q.constraint_name = b.r_constraint_name)

    where b.constraint_type = 'R '.

    )

    Select f.table_name, f.constraint_name, f.r_constraint_name, f.lvl

    q f

    [/ p]

    I want the results as the following list:

    Table-name

    ----------------

    B2

    A2

    Z

    A

    B

    C

    The table - B2, A2, Z - (in any order) must first referred in the list

    because they are based on the other three tables - A, B, C. Thus, in order to remove the

    A, B, C table records the B2, A2, table Z records must be beleted first.

    The query I posted above has the problem that it displays tables A2, B2 twice

    (1 because they have a pk and 2 because they have fk referring A, B relatively tables).

    Is there a solution for this problem?

    Note: I use db11g v2

    I wrote not all relationships of tables user_constraints (only argument constraint_name = r_constraint_name)

    Thank you

    SIM

    I have a requirement to remove the records from the tables in the order according to

    the existing foreign keys.

    . . .

    The table - B2, A2, Z - (in any order) must first referred in the list

    because they are based on the other three tables - A, B, C. Thus, in order to remove the

    A, B, C table records the B2, A2, table Z records must be beleted first.

    Is there a solution for this problem?

    Yes - the 'solution' is to use ON DELETE CASCADE, as appropriate or write a procedure that removes tables in the proper order.

    The solution is NOT to try to use dynamic sql statements to do so.

    You already know the good parent/child relationships. Simply create a procedure that uses the correct order.

    Analyses are necessary in any case to determine the proper order AND press the appropriate values to use to remove the appropriate lines

    Your DDL for tables and constraints must be in a version control system

    Update the procedure when / if new constraints or tables are added to the application

    IMHO, you must use dynamic SQL NOT to try to adjust automatically if a new constraint appears. New constraints should not appear by accident - they appear ONLY as part of a well planned release.

  • Need help with Ora-00001: constraint Unique voilated in catalog synchronization

    Hi Experts...

    Has got some problem in the catalog... desperately need help...

    Oracle: 11 GR 2

    Here is a detail of the error.

    from full resynchronization of the recovery catalog

    RMAN-00571: ===========================================================

    RMAN-00569: = ERROR MESSAGE STACK FOLLOWS =.

    RMAN-00571: ===========================================================

    RMAN-03009: failure of command resync to the default channel on 26/11/2013 18:01:34

    ORA-01403: no data found

    ORA-00001: unique constraint (DNKF_GRIP. BRL_U1) violated

    ========================++++++++++++++++=========================

    Kind regards

    Hei,

    Cool... I have also encountered this kind of error long back... Follow and fortunately we it will be solved.

    A problem with the constraint or the Index after the upgrade of the catalogue in 11 GR 2

    Remove the constraint, if available, otherwise check index, if found the drop... Rest is history...

    First, check the BRL_U1... It can be constrained or an index on the catalog database.

    May be it's problem... the compulsion was abandoned during the catalog migration process, but the corresponding index has not been abandoned.

    The catalog DB:

    -Removal of the index

    SQL > connect rman.

    SQL > select * from user_constraints where constraint_name = "BRL_U1";

    SQL > select * from user_indexes where index_name = "BRL_U1";

    SQL > drop index BRL_U1;

    Once it will be deposited now connect to the production database to connect to the catalog and re-synchronize... It should work like that...

    RMAN target / catalog rman/password@catalog_db_name

    RMAN > catalog resync;

    from full resynchronization of the recovery catalog

    full complete Resync

    RMAN > exit

    ======================================

    Kind regards

    Firdous Shah

  • Need to request so that the data dictionary

    Hi all

    I need an application that can show all the details of the tables in my database

    request to see the... : table name, type of name of column data, constraints, default value, etc...

    I found two tables in the database that showa all this information... Here are the 2 quiries:

    Select table_name, column_name | » ('|| DATA_TYPE | (' ('| data_length |')) "column_name from all_tab_columns

    where OWNER = "UBSPROD."

    Select constraint_name, constraint_type, table_name, search_condition_vc, index_name

    From user_constraints where owner = "UBSPROD";

    but when I join them I get a lot of records... I mean I think he's going to cartiantion products

    I used query below:

    Select at.table_name, at.column_name |' ('| at.data_type |') ('|| at.data_length||')) "column_name,
    UC.constraint_name, uc.constraint_type, uc.table_name, uc.search_condition_vc, uc.index_name from all_tab_columns to, uc user_constraints
    where at.owner = 'UBSPROD. '
    and at.table_name = uc.table_name

    Please, help me to display information with all tables of database related...

    Thank you

    The reason you see too many lines is because one table lists columns and a list of constraints and want to join the table name. So if you have a table with 3 constraints and 5 columns, you get 15 lines, which probably makes no sense.

    Have a reflection on what data you actually want to display for each table. There is a many-to-many relationship between columns and constraints (each column can contain zero or more constraints, each constraint can use more than one column), is without doubt better to keep the two separate, for example

    COL1

    COL2

    COL3

    COL4

    COL5

    CONSTRAINT1

    CONSTRAINT2

    CONSTRAINT3

    This would be achieved either with two separate queries, or you can use a UNION ALL operation, as appropriate. If you want to display the columns used in a constraint, you must query the synonym ALL_CONS_COLUMNS.

    Also, make sure you are compatible by using the ALL_ or synonyms USER_ - do not mix the two.

  • question about how to combine the two scripts.


    Hello

    I have a sql script that can display a table (or view) all the information, it works fine. I call it validate_table.sql, as below:

    command prompt
    accept invites owner "Enter table owner:
    accept invites from TABLE_NAME "Enter object (table/View...) "name:"


    column owner format a10 column 'owner '.
    column format a30 topic 'Object name' object_name
    column object_type format a15 direction "Type of object".
    Status format a10 column titled "Status".
    in the heading of column created format a20 "created."
    the LAST_DDL_TIME format a20, heading 'LAST_DDL_TIME.
    Select
    owner
    object_name
    object_type
    status
    , to_char (created, "DD_MON_YY hh24:mi:ss") created
    LAST_DDL_TIME,
    Of
    DBA_OBJECTS
    where
    object_name = upper ('& table_name') and owner = upper ('& owner');


    command prompt

    prompt -- ----------------------------------------------------------------------- ---

    Guest - table/view structure-

    prompt -- ----------------------------------------------------------------------- ---

    command prompt


    describe and owner... & table table_name

    command prompt

    prompt -- ----------------------------------------------------------------------- ---

    guest - list assigned user/subsidies-

    prompt -- ----------------------------------------------------------------------- ---

    command prompt

    set pagesize 50000
    set linesize 10000
    set verify off
    Set feedback off
    column lvl format A4 direction "Lvl".
    proprietary format of columns A14
    format column in table_name A29
    A38 dealer column format
    column privilege A10 format


    SELECT 'Role' lvl, t.table_name, t.grantee, t.owner, t.privilege
    OF dba_tab_privs t
    WHERE t.grantee IN (SELECT FROM dba_roles role WHERE = role t.grantee) and t.table_name = upper ('& table_name') and t.owner = upper ('& owner')
    UNION
    SELECT 'User' lvl t.table_name, t.grantee, t.owner, t.privilege
    OF dba_tab_privs t
    WHERE t.grantee IN (SELECT username FROM dba_users WHERE username = t.grantee) and t.table_name = upper ('& table_name') and t.owner = upper ('& owner')
    UNION
    SELECT 'Pub' lvl, t.table_name, t.grantee, t.owner, t.privilege
    OF dba_tab_privs t
    WHERE t.grantee = 'PUBLIC' and t.table_name = upper ('& table_name') and t.owner = upper ('& owner')
    ORDER BY 1, 2, 3;

    command prompt

    prompt -- ----------------------------------------------------------------------- ---

    guest - list of synonyms created.

    prompt -- ----------------------------------------------------------------------- ---

    command prompt


    proprietary format of columns A15
    synonym_name A20 column format
    A15 table_owner column format
    format column in table_name A40
    DB_link A40 column format

    Select the owner, synonym_name, table_owner, table_name, DB_link from DBA_synonyms where Table_name = upper ('& table_name') stopped by the owner;


    command prompt

    prompt -- ----------------------------------------------------------------------- ---

    guest - list index created-

    prompt -- ----------------------------------------------------------------------- ---

    command prompt

    Select
    table-name
    index_name
    index_type
    nom_tablespace
    status
    of DBA_indexes
    WHERE table_name = upper ('& table_name') and owner = upper ('& owner')
    order of table_name, index_name;


    command prompt

    prompt -- ----------------------------------------------------------------------- ---

    guest - list of constraints-

    prompt -- ----------------------------------------------------------------------- ---

    command prompt

    format column in table_name A15
    format of column cons_type A15
    cons_name A20 column format
    check_cons A25 column format
    VALIDATED A20 column format
    column status A10 format
    last_change A20 column format

    Select
    table-name
    (case constraint_type
    When 'P', then 'Primary Key '.
    When 'R' then 'Foreign Key'
    When 'C' then 'check '.
    When 'U' then 'single '.
    When 'o' then 'read only display '.
    When 'V' then 'check the view. "
    When 'H' then 'Hash expression. "
    When 'F' then 'REF column.
    When the of ' then 'additional logging.
    cons_type end)
    constraint_name cons_name
    condition_de_recherche check_cons
    status
    VALID
    last_change
    of dba_constraints
    where owner = upper ('& owner')
    and table_name = upper ('& table_name')
    order of cons_type;

    I have another script that allows to display the newly created tables (table, table names) in the last 24 hours.

    SET SERVEROUTPUT ON;

    DECLARE

    CURSOR tmp_cur IS

    SELECT master, object_name

    FROM dba_objects

    WHERE object_type in ('TABLE', 'SEE') and the owner not in ('SYS', 'SYSTEM', 'GENERAL', "XDB", "OUTLN", "SYSMAN") and last_ddl_time > sysdate - 1;

    tmp_rec tmp_cur % ROWTYPE;

    BEGIN

    FOR tmp_rec IN tmp_cur LOOP

    DBMS_OUTPUT. PUT_LINE)

    tmp_rec. Owner | ' ' || tmp_rec.object_name);

    END LOOP;

    END;

    /

    The gap of the first script (validate_table.sql) is that it can only check table one by one by manual entry, then how can I combine these two scripts, to make a scipt that can check all newly created tables (not a table) in the last 24 hours?

    I thank very you much in advance!

    Hello

    If you already know how to find the owner and all the tables created table_name recently.  One thing you can do is to change all the WHERE clauses in validate_table.sql, so instead of things like

    where object_name = upper ('& table_name') and owner = upper('&owner');

    you say

    WHERE (owner, object_name) IN

    (

    SELECT master, object_name

    FROM dba_objects

    WHERE object_type in ('TABLE', 'SEE')

    AND owner NOT IN ('SYS', 'SYSTEM', 'GENERAL', "XDB", "OUTLN", "SYSMAN")

    AND last_ddl_time > SYSDATE - 1

    )

    ;

    Here is another approach:

    Validate_table. SQL is quite handy as it is.  You may want to run this script for tables, even when you know that they are not new.  Divide into 2 scripts: one called ask_and_describe_table.sql, which looks like this:

    -Ask_and_Describe_Table.sql

    accept invites owner "Enter table owner:

    accept invites from TABLE_NAME "Enter object (table/View...) "name:"

    -You can use any name path instead of d:\some_dir below:

    @d:\some_dir\describe_table & owner, table_name

    and the other one called Describe_Table.sql, which starts like this:

    -Describe_Table.sql

    DEFINE owner = & 1

    DEFINE table_name = & 2

    column owner format a10 column 'owner '.

    ...

    and continues with the same exact content as validate_table.sql.

    Now, to write another script (I'll call it Describe_Recent_Tables.sql):

    -Describe_Recent_Tables.sql - create and run Describe_Many_Tables.sql

    -Turn OFF the devices designed to help people to read the output:

    SET ECHO OFF

    SET FEEDBACK OFF

    SET PAGESIZE 0

    VERRIFY OFF SET

    -Create a Describe_Many_Tables.sql:

    COIL d:\some_dir\describe_many_tables.sql

    SELECT ' @d:\some_dir\describe_table '

    ||      owner

    ||      '  '

    ||      object_name

    FROM dba_objects

    WHERE object_type in ('TABLE', 'SEE')

    AND owner NOT IN ('SYS', 'SYSTEM', 'GENERAL', "XDB", "OUTLN", "SYSMAN")

    AND last_ddl_time > SYSDATE - 1;

    SPOOL OFF

    -Features lighting designed to help people to read the output:

    SET ECHO ON

    SET FEEDBACK ON

    SET PAGESIZE 50

    SET VERRIFY ON

    -Describe_Many_Tables.sql performance

    @d:\some_dir\describe_many_tables

    I guess that all of your tables have standard names (for example, start with a letter, no spaces in the name,...), which don't require quotation marks.  If they could, then the same basic approach will work, but the details are a little messier.

    When you want to see the information on a single table or view, no matter how old it is, driven

    Ask_and_Describe_Table

    or, if you do not need to question the owner of the table and the name, something like

    Describe_Table SCOTT EMP

    (You can find that you really need not Ask_and_Describe_Table.sql).

    When you want to do this for all the tables created in the last 24 hours:

    Describe_Recent_Tables

  • Generate the Sql Data model ER diagram

    Hello

    I want to use the Oracle Sql Developer Data Modeler to generate ER diagram for my schema. There are a lot of tables in this schema, so I would like to exclusively identify the tables that should be selected to generate my ER diagram.

    Basically, I want these table that are related to other tables here. The reason being, if I select all the tables in the schema, and then I went to these tables in the ER diagram which have nothing to do with other tables.

    Please can anyone suggest write queries that produce this data dictionary?

    Thank you.

    select uc1.constraint_name,
           uc1.table_name,
           uc1.constraint_type,
           uc2.constraint_name,
           uc2.table_name,
           uc2.constraint_type
    from   user_constraints uc1,
           user_constraints uc2
    where  uc1.constraint_type='R'
           and uc1.r_constraint_name=uc2.constraint_name
    

    This gives you the relationship between the primary and foreign key

Maybe you are looking for

  • HP pavilion 22xi backlit monitor goes black screen when using

    I have led screen have a HP Pavilion 22xi.  It is a year and no warranty left.  He started to go to a black screen when you use it.  I have to unplug the monitor for the display.  the power light lights up but won't stop him.  I saw a few ppl having

  • Laser color HP jet pro M277dw: Fax not recognized

    This printer has been connected to our network (wired to our router) and everything worked perfectly. Then the router connection has been moved to another port of the router and then focused on the fax machine failed.  In the device window and printe

  • Satellite A200 (PSAF4A-009009) stops when the key.

    Laptop has first of all the problems that have been resolved with a good rash of a compressor from overheating.Worked fine for about a month, has had at least 4 different OS on it without any problem [experiment] is now OS he came out with Vista 32 b

  • SP1_ Windows Server 2008 R2 operating system error

    Server rebooted automatically and we get the error Failure of the operating system (control bug of Windows, STOP: 0x000000C2 (0x000000000000109B, 0x000000000000000C, 0 x 0000000000000007, 0xFFFFFA8040DCCCA0))

  • Unable to browse the internet despite being connected.

    Hello I seem to be impossible to to connect to the internet using msn, steam, xfire, not even Internet Explorer can connect and yet firefox can for a short period, but even that ends by stops. I don't know if it has something to do with the firewall