我正在创建一个易失性表并尝试向表中插入行。我可以上传一行如下......
create volatile table Example
(
ProductID VARCHAR(15),
Price DECIMAL (15,2)
)
on commit preserve rows;
et;
INSERT INTO Example
Values
('Steve',4);
然而,当我尝试上传多个时,我收到错误:
“语法错误:预期在')'和','之间。”
INSERT INTO Example
Values
('Steve',4),
('James',8);
答案 0 :(得分:4)
正如Gordon所说,Teradata不支持多行的VALUES(由于缺少FROM,UNION ALL将失败。
您可以改为使用多语句请求(MSR):
INSERT INTO Example Values('Steve',4)
;INSERT INTO Example Values('James',8)
;
如果是BTEQ作业,则在最后一个分号后将插入作为一个块提交(当一个新命令从同一行开始时它是MSR的一部分)。在SQL Assistant或Studio中,您必须使用F9
而不是F5
提交。
答案 1 :(得分:2)
我不认为Teradata支持多行class GameScene : SKScene {
var timer: NSTimer!
override func didMoveToView(view: SKView) {
timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector(), userInfo: nil, repeats: false)
}
}
class Viewcontroller : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var skView = self.view as! SKView
let gameScene = GameScene()
skView.presentScene(gameScene)
gameScene.timer = //whatever
}
}
语法。只需使用values
:
select
答案 2 :(得分:1)
CTE语法(有效):
insert into target_table1 (col1, col2)
with cte as (select 1 col1)
select 'value1', 'value2' from cte
union all
select 'value1a', 'value2a' from cte
;
CTE语法在Teradata中不起作用 (错误:预期为“)”和“插入”关键字之间的某项)
with cte as (select 1 col1)
insert into target_table1 (col1, col2)
select 'value1', 'value2' from cte
union all
select 'value1a', 'value2a' from cte
;
答案 3 :(得分:0)
create table dummy (dumcol varchar(1));
INSERT INTO Student
(Name, Maths, Science, English)
SELECT 'Tilak', 90, 40, 60 from dummy union
SELECT 'Raj', 30, 20, 10 from dummy
;
答案 4 :(得分:0)
我通过RECURSIVE找到了解决方案。它是这样的: -
INSERT INTO table (col1, col2)
with recursive table (col1, col2) as
(select 'val1','val2' from table) -- 1
select 'val1','val2' from table -- 2
union all select 'val3','val4' from table
union all select 'val5','val6' from table;
第1行的数据未插入(但您需要此行)。从第2行开始,为val1,val2等输入的数据将插入到相应的列中。使用尽可能多的UNION ALLs'要插入的行数。希望这会有所帮助:)
答案 5 :(得分:0)
至少在我们的Teradata版本中,我们无法使用带有CTE的insert语句。相反,找一个真正的桌子(最好是小的)并做一个前1。
Insert Into OtherRealTable(x, y)
Select top 1
'x' as x,
'y' as y
FROM RealTable
答案 6 :(得分:0)
是的,您可以尝试一下。
INSERT INTO Student
SELECT (Name, Maths, Science, English) FROM JSON_Table
(ON (SELECT 1 id,cast('{"DataSet" : [
{"s":"m", "Name":"Tilak", "Maths":"90","Science":"40", "English":"60" },
{"s":"m", "Name":"Raj", "Maths":"30","Science":"20", "English":"10" }
]
}' AS json ) jsonCol)
USING rowexpr('$.DataSet[*]')
colexpr('[{"jsonpath":"$.s","type":"CHAR(1)"},{"jsonpath":"$.Name","type":"VARCHAR(30)"}, {"jsonpath":"$.Maths","type":"INTEGER"}, {"jsonpath":"$.Science","type":"INTEGER"}, {"jsonpath":"$.English","type":"INTEGER"}]')
) AS JT(id,State,Name, Maths, Science, English)