将表从SQL Server复制到SAS中的Oracle-SQL Server中的列名太长
我们正在尝试将SQL Server数据库中的完整表复制到SAS EGuide中的Oracle,同时保留列名。不幸的是,SQL Server中的某些表的列名超过了32个字符的SAS限制 例如,SQL Server中的USR表有一个字段Identity_Source_System_Modified_On,SAS将该列截断为Identity_Source_System_Modified_。SAS中的列标签维护全名 有没有办法在Oracle中使用列标签而不是列名创建此表?或者用另一种方法复制此表而不让SAS截断列名将表从SQL Server复制到SAS中的Oracle-SQL Server中的列名太长,sql,sas,Sql,Sas,我们正在尝试将SQL Server数据库中的完整表复制到SAS EGuide中的Oracle,同时保留列名。不幸的是,SQL Server中的某些表的列名超过了32个字符的SAS限制 例如,SQL Server中的USR表有一个字段Identity_Source_System_Modified_On,SAS将该列截断为Identity_Source_System_Modified_。SAS中的列标签维护全名 有没有办法在Oracle中使用列标签而不是列名创建此表?或者用另一种方法复制此表而不让S
libname DEST oracle user=&user. pass = &pass. path = 'ORACLE100'
schema=TESTSCHEMA buffsize = 25000;
proc sql;
connect to odbc (uid="&user." pwd="&passsql." dsn='goven');
create table User_Table as select * from connection to odbc
(
select * from dbo.USR
);
disconnect from odbc;
quit ;
proc sql;
create table Dest.USR as
select
*
from work.User_Table;
quit;
SAS/Access始终在引擎盖下使用SAS,因此截断将始终发生,因为表名的最大长度为32。列标签不会被截断,因为标签的最大长度是256,通常标签是DBMS表名 尝试使用define sqlserver libname并使用proc fedsql移动数据
Libname sqlsrv sqlserver details
proc fedsql;
create table Dest.USR as
select
*
from sqlsrv.User_Table;
quit;
当处理较长的列长度问题时,PROC-FedSQL可以起到解救作用。PROC-FedSQL的优点是,当它连接到数据源时,它分别匹配数据源和目标的元数据,并在不涉及SAS/Access的情况下转换为源/目标元数据,因此不会发生截断。因为oraclesource和sqlservertarget都可以轻松地适应长度,因为当前版本的SQLServer和oracle可以适应128的列长度
当我将数据从Hive移动到Teradata时,我遇到了类似的问题,并且能够使用proc-fedsql和我写的一篇论文中的完整细节来修复
SAS/Access始终在引擎盖下使用SAS,因此截断将始终发生,因为表名的最大长度为32。列标签不会被截断,因为标签的最大长度是256,通常标签是DBMS表名 尝试使用define sqlserver libname并使用proc fedsql移动数据
Libname sqlsrv sqlserver details
proc fedsql;
create table Dest.USR as
select
*
from sqlsrv.User_Table;
quit;
当处理较长的列长度问题时,PROC-FedSQL可以起到解救作用。PROC-FedSQL的优点是,当它连接到数据源时,它分别匹配数据源和目标的元数据,并在不涉及SAS/Access的情况下转换为源/目标元数据,因此不会发生截断。因为oraclesource和sqlservertarget都可以轻松地适应长度,因为当前版本的SQLServer和oracle可以适应128的列长度
当我将数据从Hive移动到Teradata时,我遇到了类似的问题,并且能够使用proc-fedsql和我写的一篇论文中的完整细节来修复
如果使用基础SAS作为系统间复制的中介,则可以复制复制提交传递,重命名Oracle列。 在复制到Oracle之前,我认为不需要将SQL Server表复制到SAS工作
Proc SQL;
* Use SAS as the conduit between the two database systems;
create table dest.usr as select * from connection to odbc
(
select * from dbo.usr
);
* Copy one row from SQL Server to see what the mediated column names were;
create table one as select * from connection to odbc
(
select top 1 * from dbo.usr
);
* For the column names that dont match column labels code gen an alter statement;
reset noprint;
%let renames=;
select 'alter table usr rename ' || trim(name) || ' to ' || trim(label) || ';'
into :renames
separated by ' '
from dictionary.columns
where libname = 'WORK'
and memname = 'ONE'
and name ne label
;
connect using dest;
execute ( &renames ) by dest;
quit;
复制提交给Oracle的codegen alter table语句后
Proc SQL;
* Use SAS as the conduit between the two database systems;
create table dest.usr as select * from connection to odbc
(
select * from dbo.usr
);
* Copy one row from SQL Server to see what the mediated column names were;
create table one as select * from connection to odbc
(
select top 1 * from dbo.usr
);
* For the column names that dont match column labels code gen an alter statement;
reset noprint;
%let renames=;
select 'alter table usr rename ' || trim(name) || ' to ' || trim(label) || ';'
into :renames
separated by ' '
from dictionary.columns
where libname = 'WORK'
and memname = 'ONE'
and name ne label
;
connect using dest;
execute ( &renames ) by dest;
quit;
如果使用基础SAS作为系统间复制的中介,则可以复制复制提交传递,重命名Oracle列。 在复制到Oracle之前,我认为不需要将SQL Server表复制到SAS工作
Proc SQL;
* Use SAS as the conduit between the two database systems;
create table dest.usr as select * from connection to odbc
(
select * from dbo.usr
);
* Copy one row from SQL Server to see what the mediated column names were;
create table one as select * from connection to odbc
(
select top 1 * from dbo.usr
);
* For the column names that dont match column labels code gen an alter statement;
reset noprint;
%let renames=;
select 'alter table usr rename ' || trim(name) || ' to ' || trim(label) || ';'
into :renames
separated by ' '
from dictionary.columns
where libname = 'WORK'
and memname = 'ONE'
and name ne label
;
connect using dest;
execute ( &renames ) by dest;
quit;
复制提交给Oracle的codegen alter table语句后
Proc SQL;
* Use SAS as the conduit between the two database systems;
create table dest.usr as select * from connection to odbc
(
select * from dbo.usr
);
* Copy one row from SQL Server to see what the mediated column names were;
create table one as select * from connection to odbc
(
select top 1 * from dbo.usr
);
* For the column names that dont match column labels code gen an alter statement;
reset noprint;
%let renames=;
select 'alter table usr rename ' || trim(name) || ' to ' || trim(label) || ';'
into :renames
separated by ' '
from dictionary.columns
where libname = 'WORK'
and memname = 'ONE'
and name ne label
;
connect using dest;
execute ( &renames ) by dest;
quit;
谢谢你,基兰。这看起来是一种方法。我定义了sqlserver libname,它在proc sql语句中工作,但在fedsql错误中不工作:错误:[错误:PROC FEDSQL初始化失败。这超出了此问题的范围,因此我将标记您的回答作为答案。但是,如果您确实知道该错误可能指的是什么,我将不胜感激!这是我所担心的问题之一。您的SASok中没有PROC FEDSQL,这很公平。我可能可以破解一个解决方案。谢谢s anyways。另一个通常的做法是在源表中创建一个列长度较小的视图,然后执行您在Tanks Kiran中所做的操作。这看起来像是这样做的。我定义了sqlserver libname,它在proc sql语句中工作,但在fedsql中不工作错误:错误:[错误:PROC FEDSQL初始化失败。这超出了此问题的范围,因此我将标记您的回答作为答案。但是,如果您确实知道该错误可能指的是什么,我将不胜感激!这是我所担心的问题之一。您的SASok中没有PROC FEDSQL,这很公平。我可能可以破解一个解决方案。谢谢s无论如何。另一个通常的做法是在源表中创建一个列长度较小的视图,然后执行您所做的操作。谢谢Richard。我认为您的方法可以工作,但有一些不同的版本控制问题我一开始不知道。首先,我的SAS版本不允许在execute语句中使用;,因此我必须重新设置在创建alter table语句时将其移动。其次,我的Oracle版本只支持长度为30的列名。我最终不得不将表中的内容读入SAS,将列名缩短到长度为30,然后再写入。这不理想,但有效。这是p
谢谢你,理查德。我认为您的方法会起作用,但有一些不同的版本控制问题我一开始并不知道。首先,我的SAS版本不允许;在execute语句中,所以在创建ALTERTABLE语句时,我必须删除它。其次,我的Oracle版本只支持长度为30的列名。最后,我不得不将表中的内容读入SAS,将列名的长度减少到30,然后再写。不太理想,但它起作用了。