使用 SQL 在 Oracle 中创建视图

Create a View in Oracle with SQL

我正在尝试创建一个视图,其中包含我的 tblSuppliers table 中的 strSupplierName 列以及我的 tblProducts table 中的 strProductName 列,但遇到了一些问题。任何帮助将不胜感激。

CREATE TABLE  "tblSuppliers" 
   (    "lngSupplierID" VARCHAR2(100) NOT NULL ENABLE, 
    "strSupplierName" VARCHAR2(100) NOT NULL ENABLE, 
    "strSupplierAddressStreet" VARCHAR2(200) NOT NULL ENABLE, 
    "strSupplierAddressCity" VARCHAR2(150) NOT NULL ENABLE, 
    "strSupplierAddressCountry" VARCHAR2(100) NOT NULL ENABLE, 
    "strSupplierAddressPostCode" VARCHAR2(25), 
    "strSupplierPhoneNo" VARCHAR2(15) NOT NULL ENABLE, 
    "strSupplierFaxNo" VARCHAR2(20), 
    "strPaymentTerms" VARCHAR2(500), 
     CONSTRAINT "tblSuppliers_PK" PRIMARY KEY ("lngSupplierID") ENABLE
   ) ;

CREATE OR REPLACE TRIGGER  "BI_tblSuppliers" 
  before insert on "tblSuppliers"               
  for each row  
begin   
  if :NEW."lngSupplierID" is null then 
    select "TBLSUPPLIERS_SEQ".nextval into :NEW."lngSupplierID" from dual; 
  end if; 
end; 


CREATE TABLE  "strProducts" 
   (    "lngProductID" VARCHAR2(100) NOT NULL ENABLE, 
    "strProductName" VARCHAR2(100) NOT NULL ENABLE, 
    "chkInStock" VARCHAR2(5) NOT NULL ENABLE, 
    "lngUnitsInStock" NUMBER(38,0) NOT NULL ENABLE, 
    "curProductUnitPurchasePrice" VARCHAR2(10), 
    "curProductUnitSalePrice" VARCHAR2(10), 
    "lngSupplierID" VARCHAR2(100), 
     CONSTRAINT "tblProducts_PK" PRIMARY KEY ("lngProductID") ENABLE
   ) ;

ALTER TABLE  "tblProducts" ADD FOREIGN KEY ("lngSupplierID")
      REFERENCES  "tblSuppliers" ("lngSupplierID") ENABLE;

CREATE OR REPLACE TRIGGER  "BI_tblProducts" 
  before insert on "tblProducts"               
  for each row  
begin   
  if :NEW."lngProductID" is null then 
    select "TBLPRODUCTS_SEQ".nextval into :NEW."lngProductID" from dual; 
  end if; 
end; 

/
ALTER TRIGGER  "BI_tblProducts" ENABLE;

这是您要找的吗?

CREATE VIEW "yourViewName" AS
SELECT
 p."lngProductID",
 p."strProductName",
 s."lngSupplierID",
 s."strSupplierName"
FROM "strProducts" p
INNER JOIN "tblSuppliers" s ON s."lngSupplierID" = p."lngSupplierID"