Refernece a table : References « Table « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Table » References 
6. 17. 1. Refernece a table
SQL> set echo on
SQL>

SQL> create table p int primary key );

Table created.

SQL>
SQL> create table c y references p );

Table created.

SQL>
SQL>
SQL> insert into p values );

row created.

SQL>
SQL>
SQL> insert into p values );

row created.

SQL>
SQL>
SQL> column columns format a30 word_wrapped
SQL> column tablename format a15 word_wrapped
SQL> column constraint_name format a15 word_wrapped
SQL>
SQL> select table_name, constraint_name,
  2         cname1 || nvl2(cname2,','||cname2,null||
  3         nvl2(cname3,','||cname3,null|| nvl2(cname4,','||cname4,null||
  4         nvl2(cname5,','||cname5,null|| nvl2(cname6,','||cname6,null||
  5         nvl2(cname7,','||cname7,null|| nvl2(cname8,','||cname8,null)
  6              columns
  7    from select b.table_name,
  8                  b.constraint_name,
  9                  max(decodeposition, 1, column_name, null )) cname1,
 10                  max(decodeposition, 2, column_name, null )) cname2,
 11                  max(decodeposition, 3, column_name, null )) cname3,
 12                  max(decodeposition, 4, column_name, null )) cname4,
 13                  max(decodeposition, 5, column_name, null )) cname5,
 14                  max(decodeposition, 6, column_name, null )) cname6,
 15                  max(decodeposition, 7, column_name, null )) cname7,
 16                  max(decodeposition, 8, column_name, null )) cname8,
 17                  count(*col_cnt
 18             from (select substr(table_name,1,30table_name,
 19                          substr(constraint_name,1,30constraint_name,
 20                          substr(column_name,1,30column_name,
 21                          position
 22                     from user_cons_columns a,
 23                  user_constraints b
 24            where a.constraint_name = b.constraint_name
 25              and b.constraint_type = 'R'
 26            group by b.table_name, b.constraint_name
 27         cons
 28   where col_cnt > ALL
 29           select count(*)
 30               from user_ind_columns i
 31              where i.table_name = cons.table_name
 32                and i.column_name in (cname1, cname2, cname3, cname4,
 33                                      cname5, cname6, cname7, cname8 )
 34                and i.column_position <= cons.col_cnt
 35              group by i.index_name
 36           )
 37  /

TABLE_NAME                     CONSTRAINT_NAME COLUMNS
------------------------------ --------------- ------------------------------
C                              SYS_C009529     Y

SQL>
SQL>
SQL> drop table c;

Table dropped.

SQL>
SQL> drop table p;

Table dropped.

SQL>
SQL>
SQL>
SQL>
SQL>
6. 17. References
6. 17. 1. Refernece a table
6. 17. 2. Reference column from another column
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.