create table st01 ( "id" INT, "name" VARCHAR(20), "age" VARCHAR(20) )哪里有问题
时间: 2023-07-17 11:59:46 浏览: 160
在您的CREATE TABLE语句中,有几个问题需要注意:
1. 在列名和数据类型之间,应该使用空格而不是逗号。例如,将`"name" VARCHAR(20)`更改为`"name" VARCHAR(20)`。
2. VARCHAR的括号内应该是一个整数,表示该列的最大字符长度。您可以将`"age" VARCHAR(20)`更改为适当的长度,根据您的需求进行调整。
修正后的CREATE TABLE语句如下:
```
CREATE TABLE st01 (
"id" INT,
"name" VARCHAR(20),
"age" VARCHAR(20)
);
```
请注意,在MySQL中,引号通常不是必需的,也可以使用反引号来包围列名和表名,例如`id`、`name`、`age`。
相关问题
ALTER TABLE HA_ST01.TABLE_PO_SALES_MOM_TZC DROP COLUMN C_MONTH; CREATE procedure HA_ST01.PRO_PO_SALES_MOM_TZC(IN S_YM NVARCHAR(6),IN E_YM NVARCHAR(6)) LANGUAGE SQLSCRIPT AS BEGIN DELETE FROM HA_ST01.TABLE_PO_SALES_MOM_TZC WHERE C_MONTH BETWEEN :S_YM AND :E_YM; INSERT INTO TABLE_PO_SALES_MOM_TZC(C_MONTH,GROSSAMOUNT,GROSSAMOUNT_1,RATE_MOM)(SELECT C_MONTH FROM "_SYS_BIC"."HA20_TZC.DAY1/CAL_PO_TZC_01" WHERE C_MONTH BETWEEN :S_YM AND :E_YM); END;怎么修改
根据提供的代码,您需要将INSERT INTO语句中的表名从TABLE_PO_SALES_MOM_TZC修改为HA_ST01.TABLE_PO_SALES_MOM_TZC,以便与DELETE语句中的表名匹配。修改后的代码如下:
```
ALTER TABLE HA_ST01.TABLE_PO_SALES_MOM_TZC DROP COLUMN C_MONTH;
CREATE procedure HA_ST01.PRO_PO_SALES_MOM_TZC(IN S_YM NVARCHAR(6),IN E_YM NVARCHAR(6))
LANGUAGE SQLSCRIPT AS
BEGIN
DELETE FROM HA_ST01.TABLE_PO_SALES_MOM_TZC WHERE C_MONTH BETWEEN :S_YM AND :E_YM;
INSERT INTO HA_ST01.TABLE_PO_SALES_MOM_TZC(C_MONTH,GROSSAMOUNT,GROSSAMOUNT_1,RATE_MOM)
(SELECT C_MONTH FROM "_SYS_BIC"."HA20_TZC.DAY1/CAL_PO_TZC_01" WHERE C_MONTH BETWEEN :S_YM AND :E_YM);
END;
```
请注意,如果表名或字段名有误,仍会提示错误。建议在修改代码之前,仔细检查表名、字段名和语法,以确保代码正确无误。
CREATE PROCEDURE HA_ST01,PRO_TEST01_LNJ(IN ID INTEGER,IN DAY_STR NVARCHAR(8),OUT MESSAGE NVARCHAR(50)) LANGUAGE sqlscript as begin DECLARE DAY_DATE DATE; DECLARE COUNT_ID INTEGER; RS_1=SELECT * FROM "HA_ST01"."DATE_INFO_LNJ" WHERE ID =:ID; SELECT COUNT(1) INTO COUNT_ID FROM :RS_1; SELECT TO_DATE(:DAY_STR)INTO DAY_DATE FROM DUMMY; IF :COUNT_ID >=1 THEN :MESSAGE SELECT'错误:主键重复' INTO MESSAGE FROM DUMMY; ELSEIF :COUNT_ID<1 insert into "HA_ST01"."DATE_INFO_LNJ"(ID,DAY,WEEK_NUM)VALUES(:ID,:DAY_DATE,WEEKDAY(:DAY_DATE)); SELECT'插入成功' INTO MESSAGE FROM DUMMY; END IF; end;有啥错误
在第3行,RS_1应该使用DECLARE关键字声明为变量,应该改为:DECLARE RS_1 CURSOR FOR SELECT * FROM "HA_ST01"."DATE_INFO_LNJ" WHERE ID =:ID;
在第4行,COUNT_ID应该先声明为变量,应该改为:DECLARE COUNT_ID INTEGER;
在第7行,应该使用SELECT COUNT(*) INTO COUNT_ID FROM (SELECT * FROM "HA_ST01"."DATE_INFO_LNJ" WHERE ID =:ID);
在第8行,应该使用SELECT TO_DATE(:DAY_STR,'YYYY-MM-DD') INTO DAY_DATE FROM DUMMY;
在第10行,应该将:MESSAGE SELECT'错误:主键重复' INTO MESSAGE FROM DUMMY; 改为 SET MESSAGE = '错误:主键重复';
在第13行,应该将:MESSAGE SELECT'插入成功' INTO MESSAGE FROM DUMMY; 改为 SET MESSAGE = '插入成功';
正确的存储过程如下:
CREATE PROCEDURE HA_ST01.PRO_TEST01_LNJ (IN ID INTEGER, IN DAY_STR NVARCHAR(8), OUT MESSAGE NVARCHAR(50))
LANGUAGE sqlscript AS
BEGIN
DECLARE RS_1 CURSOR FOR SELECT * FROM "HA_ST01"."DATE_INFO_LNJ" WHERE ID =: ID;
DECLARE COUNT_ID INTEGER;
SELECT COUNT(*) INTO COUNT_ID FROM (SELECT * FROM "HA_ST01"."DATE_INFO_LNJ" WHERE ID =: ID);
DECLARE DAY_DATE DATE;
SELECT TO_DATE(:DAY_STR, 'YYYY-MM-DD') INTO DAY_DATE FROM DUMMY;
IF COUNT_ID >= 1 THEN
SET MESSAGE = '错误:主键重复';
ELSEIF COUNT_ID < 1 THEN
INSERT INTO "HA_ST01"."DATE_INFO_LNJ" (ID, DAY, WEEK_NUM) VALUES (: ID, : DAY_DATE, WEEKDAY(: DAY_DATE));
SET MESSAGE = '插入成功';
END IF;
END;
阅读全文