简体   繁体   English

在 SAS 隐式 Sql Pass Thru 中使用 Teradata UDF

[英]Using a Teradata UDF in SAS Implicit Sql Pass Thru

I am trying to use a Teradata UDF (User Defined Function) in a SAS Implicit SQL which establishes the connection to Teradata using LIBNAME Statement.Assume that the function is called PTY_DECRYPT and is defined in a Database called TEST in Teradata.我正在尝试在 SAS 隐式 SQL 中使用 Teradata UDF(用户定义函数),该 SQL 使用 LIBNAME 语句建立与 Teradata 的连接。假设该函数称为 PTY_DECRYPT,并在 Teradata 中名为 TEST 的数据库中定义。 The Purpose of this function is to decrypt values in a Column of a View in Teradata.此函数的目的是解密 Teradata 中视图列中的值。

What works is using the UDF in an Explicit Sql .Below I am using the function on a column called SSN_NBR in a view called V_TEST_PERS present in the Database called SAMPLE.有效的是在显式 Sql 中使用 UDF。下面我在名为 SSN_NBR 的列上使用该函数,该函数位于名为 SAMPLE 的数据库中的名为 V_TEST_PERS 的视图中。

Explcit Sql:显式 Sql:

Options  debug=DBMS_TIMERS sastrace=',,,d'
sastraceloc=saslog no$stsuffix fullstimer;


Proc Sql;
Connect to TERADATA(User=XXXXX pwd=XXXXX server=XXXXX);
Create Table Final as
select  *  from connection to teradata
(
Select
sub_id, 
SSN_NBR,
TEST.PTY_DECRYPT(SSN_NBR,'T_ssn_test',400,0,0 ) as SSN_NBR_Decrypt
from SAMPLE.V_TEST_PERS
);
disconnect from teradata;
Quit;

But I would like to use the same function in an Implicit SQL but it does not work.但我想在隐式 SQL 中使用相同的函数,但它不起作用。 Any ideas as to how to make it work in an Implicit Sql with minimum changes to the Implicit SQL?关于如何在对隐式 SQL 进行最少更改的情况下使其在隐式 Sql 中工作的任何想法?

Implicit Sql隐式 SQL

Options  debug=DBMS_TIMERS sastrace=',,,d'
sastraceloc=saslog no$stsuffix fullstimer;

Libname Td Teradata  User=XXXXX pwd=XXXXX server=XXXXX database=SAMPLE ;

Proc sql;
Create  table Final as
select
sub_id, 
SSN_NBR,
TEST.PTY_DECRYPT(SSN_NBR,'T_ssn_test',400,0,0 ) as SSN_NBR_Decrypt

from Td.V_TEST_PERS;
Quit;

In your implicit SQL you reference the view with the LIBNAME alias TD , however when you reference the UDF you are not aliasing the TEST database containing the UDF with the LIBNAME alias.在您的隐式 SQL 中,您使用 LIBNAME 别名TD引用视图,但是当您引用 UDF 时,您不会使用 LIBNAME 别名为包含 UDF 的TEST数据库设置别名。 Syntactically, you may not be able to do that in SAS.从语法上讲,您可能无法在 SAS 中做到这一点。 (eg TD.TEST.PTY_DECRYPT() - in fact I wouldn't expect this to work) (例如TD.TEST.PTY_DECRYPT() - 事实上我不希望这能工作)

The UDF may need to be placed in SYSLIB or TD_SYSFNLIB so that it is in a default search path for the database optimizer to find the UDF without being fully qualified.该UDF可能需要放置在SYSLIBTD_SYSFNLIB ,使其在数据库优化器默认搜索路径找到UDF还没有完全合格。 (eg TD_WEEK_BEGIN() ) Alternatively, the UDF could be placed in database SAMPLE but that likely violates how UDFs are maintained in your environment, as it would in my environment. (例如TD_WEEK_BEGIN() )或者,UDF 可以放置在数据库SAMPLE但这可能违反了 UDF 在您的环境中的维护方式,就像在我的环境中一样。

Otherwise, the UDF call could be embedded in a view on the database, but then you have other issues to consider with the security of that column if your environment is not granting security on a column level basis to views containing encrypted data elements.否则,UDF 调用可能会嵌入到数据库的视图中,但是如果您的环境没有在列级别基础上向包含加密数据元素的视图授予安全性,那么您还有其他问题需要考虑该列的安全性。 (eg PHI, PII, etc.) Without a row-column level security mechanism in place to dynamically filter a users ability to see the column you are decrypting in the view putting the UDF into the view isn't going to work. (例如 PHI、PII 等)如果没有行列级安全机制来动态过滤用户在视图中查看您正在解密的列的能力,则将 UDF 放入视图中是行不通的。

I asked the same question the SAS Communities Forum and I am glad to say that i did find a Solution to this Problem.我在 SAS 社区论坛上问了同样的问题,我很高兴地说我确实找到了这个问题的解决方案。

Please see the link below :请参阅以下链接:

https://communities.sas.com/t5/Base-SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/mp/266850/highlight/false#M52685 https://communities.sas.com/t5/Base-SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/mp/266850/highlight/false#M52685

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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