我正在创建一个删除表行重复项的过程。
代码工作正常,我想将代码转换为过程。我找不到设置[ Schema] 和 [Table] 作为输入参数的方法。
Create procedure DUPL_DELETE (in inp1 nvarchar(100), in inp2 nvarchar(200))
as
begin
-- Select the distinct rows into a New temporary Table
create local temporary table #Mytemp
LIKE "SCHEMA"."TABLE";
-- LIKE :inp2.:inp1 Desired code to be(does not work)
SELECT DISTINCT *
FROM "SCHEMA"."TABLE"
INTO "SCHEMA".#Mytemp;
-- Delete the rows from table
DELETE FROM "SCHEMA"."TABLE";
-- Insert disctinct data back in to the Table and drop the temporary table
INSERT INTO "SCHEMA"."TABLE" SELECT * FROM "SCHEMA".#Mytemp;
DROP TABLE "SCHEMA".#Mytemp;
end;
请大家帮助
答案 0 :(得分:0)
您可以尝试使用以下示例命令更改架构:
set schema OTHERSCHEMA;
但是对于表名,您需要使用{p>
execute immediate :sql;
答案 1 :(得分:0)
您可以这样:
CREATE PROCEDURE OriginalSchema.procDynamicSchema(
IN schemaId NVARCHAR(250)
)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
READS SQL DATA AS
BEGIN
/*****************************
Write your procedure logic
*****************************/
EXECUTE IMMEDIATE
'SELECT
"Id",
"UUID",
"IdpId",
"Email",
"firstName",
"lastname"
FROM ' || :schemaId || '."Users"' ;
END;
然后称呼它:
CALL "OriginalSchema"."procDynamicSchema"(SCHEMAID => 'XYZ')
p.s:我认为您不能动态地传递OriginalSchema名称,因为要创建一个过程,您至少必须具有一个实际上要在第一手创建过程的方案。