tags:

views:

82

answers:

4

i get error

insert into dmi_user.fct_sales_summary_cmp values SELECT  A.bio_id
                                                  *
ERROR at line 1:
ORA-00936: missing expression

on running following query

insert into dmi_user.fct_sales_summary_cmp values SELECT  A.bio_id
,decode(A.wk_units2 - B.wk_units1,0,NULL,A.wk_units2), decode(A.wk_units2 -
B.wk_units1,0,NULL,B.wk_units1), decode(A.wk_units3 -
B.wk_units2,0,NULL,A.wk_units3), decode(A.wk_units3 -
B.wk_units2,0,NULL,B.wk_units2), decode(A.wk_units4 -
B.wk_units3,0,NULL,A.wk_units4), decode(A.wk_units4 -
B.wk_units3,0,NULL,B.wk_units3), decode(A.wk_units5 -
B.wk_units4,0,NULL,A.wk_units5), decode(A.wk_units5 -
B.wk_units4,0,NULL,B.wk_units4), decode(A.wk_units6 -
B.wk_units5,0,NULL,A.wk_units6), decode(A.wk_units6 -
B.wk_units5,0,NULL,B.wk_units5) from cnt_sls_dm.fct_sales_summary A,
cnt_sls_dm.fct_sales_summary B where A.bio_id=B.bio_id AND A.bio_id<>0 and
rownum<25 AND ( A.wk_units2<> B.wk_units1 or  A.wk_units3<> B.wk_units2 or
A.wk_units4<> B.wk_units3 or  A.wk_units5<> B.wk_units4 or  A.wk_units6<>
B.wk_units5)
+5  A: 

I'm not sure about the oracle (now that the answer got upvoted and commented I'm relatively sure ;-) ), but I'd expect it to be either

INSERT INTO table VALUES …

or

INSERT INTO table SELECT …

(with no VALUES keyword).

I failed, of course, to read the whole query ;-)

Michael Krelin - hacker
+1! Be sure about this! The insert statement is either INSERT/VALUES or INSERT/SELECT but not INSERT/VALUES/SELECT. You're either inserting values or a subset from another table, not some weird mixture. :-)
Workshop Alex
Thank, now looking at upvotes I am ;-) It's just that I've almost never dealt with Oracle and the last time was almost 10 years ago and you always expect weird syntaxes from biggies :)
Michael Krelin - hacker
A: 

You probably don't need the word 'values' in your query.

Zed
A: 
INSERT INTO TABLE1(COL1,COL2) SELECT FIELD1,FIELD2 FROM TABLE2
adatapost
A: 

Following should work fine.

IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
      WHERE TABLE_NAME = 'T1')
   DROP TABLE T1
GO

CREATE TABLE T1 ( column_1 int, column_2 varchar(30))
GO

Insert into T1 Values (1,2)
Go
insert into T1 select 1,2

GO
select * from T1

I guess, if you remove your Values Keyword it should be fine