1

I've tried to convert SQL Server code to Oracle but failed.

Here is my code in SQL Server. Can anyone help?

CREATE TABLE [dbo].[DimCustomer]
(
     CustomerID INT IDENTITY(12,1) NOT NULL,
     CustomerAccountID VARCHAR(20),
     FirstName VARCHAR(50),
     LastName VARCHAR(50),
     FullName AS CONCAT(FirstName,' ',LastName),
     ContactNumber VARCHAR(20),
     EmailAddress VARCHAR(50),
     MemberShipType VARCHAR(50),
     MemberShipStartDatekey INT,
     MemberShipExpiryDateKey INT,

     CONSTRAINT pk_customer_id PRIMARY KEY (CustomerID)
)
5
  • Add the version-specific SQL Server tag to your question.Your DDL is valid in SQL Server 2012 and later but not against older versions because of the CONCAT function. Commented Nov 2, 2017 at 16:41
  • This is not a code writing service. There are many differences between Oracle and sql server. identity being one that jumps off the page here. The syntax for computed columns is very different also. Commented Nov 2, 2017 at 16:42
  • Which version of Oracle? Commented Nov 2, 2017 at 16:45
  • for starters, oracle has no [dbo] Commented Nov 2, 2017 at 16:48
  • Thanks everyone.It is solved. Commented Nov 2, 2017 at 16:56

1 Answer 1

1

As simple as (Oracle 12c):

CREATE TABLE DimCustomer
(
CustomerID INT   GENERATED BY DEFAULT AS IDENTITY NOT NULL  --IDENTITY
,CustomerAccountID VARCHAR2(20)                             --VARCHAR2
,FirstName VARCHAR2(50)
,LastName VARCHAR2(50)
,FullName AS (FirstName || ' ' ||LastName)                  --calculated column
,ContactNumber VARCHAR2(20)
,EmailAddress VARCHAR2(50)
,MemberShipType VARCHAR2(50)
,MemeberShipStartDatekey INT
,MemberShipExpiryDateKey INT
,CONSTRAINT pk_customer_id PRIMARY KEY (CustomerID)         --comma
);

Alternative using sequence and trigger:

CREATE SEQUENCE DimCustomer_seq START WITH 12 INCREMENT BY 1;

CREATE OR REPLACE TRIGGER DimCustomer_seq_tr
 BEFORE INSERT ON DimCustomer FOR EACH ROW
BEGIN
 SELECT DimCustomer_seq.NEXTVAL INTO :NEW.CustomerID FROM DUAL;
END;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.