Sql 我不能在insert语句中使用函数吗?
似乎无法在insert语句中使用SAS函数:Sql 我不能在insert语句中使用函数吗?,sql,sas,sql-insert,Sql,Sas,Sql Insert,似乎无法在insert语句中使用SAS函数: proc sql; create table tq84_tab (col char(100)); insert into tq84_tab values (repeat('foo ', 10)); quit; 当我运行代码时,我得到: insert into tq84_tab values (repeat('foo ', 10)); ---- ----- 22 26 202 2
proc sql;
create table tq84_tab (col char(100));
insert into tq84_tab values (repeat('foo ', 10));
quit;
当我运行代码时,我得到:
insert into tq84_tab values (repeat('foo ', 10));
---- -----
22 26
202 200
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
a missing value, +, -, MISSING, NULL, USER.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
是我做错了什么,还是我的怀疑真的是这样?没有/可能
使用insert。。值
您必须使用固定值,无函数
在这个简单的例子中,您可以自己使用SAS宏—使用%sysfunc宏函数调用SAS函数,该函数“预处理”您的代码
proc sql;
create table tq84_tab (col char(100));
insert into tq84_tab values ("%sysfunc(repeat(foo, 10))");
select * from tq84_tab;
quit;
要使项目出现N次,请重复N-1次。如果要重复尾随空格,还需要对项目进行宏引用:
insert into tq84_tab values ("%sysfunc(repeat(%str(foo ), 9))");
您还可以创建只有一行的虚拟表。然后使用运行时函数构造要插入的值
create table onerow (ignore_me char(0));
insert into onerow values ('');
insert into tq84_tab select (repeat("foo ",9)) as col from onerow;
onerow充当Oracle的DUAL或SQL Server的bare select(无来自).运行该代码时会发生什么?不应该使用
select
而不是values
?select
而不是values
会导致类似的错误。我认为您不能使用values
子句中的任何函数。@RenéNyffenegger:目标是创建一个包含“foo”的变量吗重复10次(fooofooo)或创建10个变量,每个变量包含世界“foo”?一个值为foo foo foo foo foo foo
的变量。