Home » SQL & PL/SQL » SQL & PL/SQL » How to create view
How to create view [message #11248] Mon, 15 March 2004 19:39 Go to next message
sri
Messages: 154
Registered: February 2000
Senior Member
How to create view from two tables , with selected columns, no primaty key relation between these two tables.
Re: How to create view [message #11249 is a reply to message #11248] Mon, 15 March 2004 20:12 Go to previous message
Jitendra Agrawal
Messages: 71
Registered: December 2003
Member
Hi,

SQL> create view VIEW_NAME as select FIELD from TABLE1 a, TABLE2 b where CONDITION

CONDITION can be any condition like : a.field1=b.field1

Here is an example that I posted in another forum.

SQL> create table table_test1 (field1 number(4), field2 number(4));

Table created.

SQL> ed
Wrote file afiedt.buf

1* create table table_test2 (field1 number(4), field2 number(4))
SQL> /

Table created.

SQL> insert into table_test1 (field1) values (1);

1 row created.

SQL> insert into table_test1 (field1, field2) values (2, 1);

1 row created.

SQL> insert into table_test2 (field1, field2) values (1, 2);

1 row created.

SQL> insert into table_test2 (field1) values (2);

1 row created.

SQL> select * from table_test1;

FIELD1 FIELD2
---------- ----------
1
2 1

SQL> select * from table_test2;

FIELD1 FIELD2
---------- ----------
1 2
2

SQL> create view view_test2 as select nvl(a.field2, b.field2) field1 from table_test1 a, table_test2 b where a.field1=b.field1;

View created.

SQL> select * from view_test2;

FIELD1
----------
2
1

Hope this helps,
Jitendra Agrawal,

http://www.telemune.com/
Previous Topic: NOT IN QUERY
Next Topic: CODE WORKING ON 9i Release 1.0 But not on 9i Relase 2.0
Goto Forum:
  


Current Time: Wed Apr 24 18:57:31 CDT 2024