简体   繁体   中英

Migrate User Define Types from Oracle to MSSQL

Can you help me to migrate the following lines from Oracle to MSSQL. Thank you.

create or replace TYPE "GPS_SEGMENT" is object (
  lat1 numeric (14,5),
  lon1 numeric (14,5),
  lat2 numeric (14,5),
  lon2 numeric (14,5)
  );

create or replace TYPE "GPS_SEGMENT_TABLE" is table of  gps_segment;   

Thank you.

I believe what you'd want in SQL Server would be a User Defined Table Type:

CREATE TYPE udtGpsSegment AS TABLE
(
  lat1 numeric (14,5),
  lon1 numeric (14,5),
  lat2 numeric (14,5),
  lon2 numeric (14,5)
);

You could then use this as a table variable in MSSQL:

DECLARE @gpsSegment udtGpsSegment;
INSERT @gpsSegment(....)

Or take it as a parameter to a stored procedure:

CREATE PROCEDURE example (@gpsSegment udtGpsSegment READONLY)
AS
BEGIN
  -- note that you can't update/insert/delete udtGpsSegment, but you can select from it - if needed, select it into a temp table or table variable that can be updated/deleted/inserted.
END

Also note that this only works for SQL Server 2008R2+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM