我正在尝试执行插入操作,但是我收到的数字错误无效。 我知道在哪里,但我不知道为什么或如何解决这个问题。一切都很好(我猜)。
以下是PL / SQL块:
DECLARE
L_J_ID NUMBER := J_SEQ.NEXTVAL;
BEGIN
INSERT INTO some_table
(J_ID, E_TABLE_COLUMN, F_TABLE_COLUMN)
VALUES
(L_J_ID, 'a', 'b');
INSERT INTO CFG_FILTER_JOIN
(J_ID, E_TABLE_COLUMN, F_TABLE_COLUMN)
VALUES
(L_J_ID, 'c', 'd');
END;
/
DECLARE
var NUMBER;
BEGIN
SELECT ID --number
INTO var
FROM some_table
WHERE F_TABLE_COLUMN = 'a'
AND E_TABLE_COLUMN = 'b';
INSERT INTO my_table
(ID, --in table definition: number(8)
NAME, --varchar2(30)
TYPE, --varchar2(30)
TABLE_name, --varchar2(30)
J_ID, --number(8) --here is where I get the invalid number
COLUMN, --varchar2(30)
COLUMN_TYPE, --varchar2(1)
FILTER_LIST_ID) --number(8)
VALUES
(SEQ.NEXTVAL,
'COL_LIST',
'JL',
var, --here is where I get the invalid number
'NB_CTL',
'DEST',
'V',
4);
END;
/
怎么了?
答案 0 :(得分:1)
将insert语句重写为伪代码:
INSERT INTO my_table
(ID = SEQ.NEXTVAL,
NAME = 'COL_LIST',
TYPE = 'JL',
TABLE = var,
J_ID = 'NB_CTL',
COLUMN = 'DEST',
COLUMN_TYPE = 'V',
FILTER_LIST_ID = 4)
为数字J_ID列分配字符串值' NB_CTL'。
答案 1 :(得分:0)
Table是双引号(“table”)中的保留关键字括起来的表。并且发生了列不匹配。通过重写你的plsql块是
DECLARE
L_J_ID NUMBER := J_SEQ.NEXTVAL;
BEGIN
INSERT INTO some_table
(J_ID, E_TABLE_COLUMN, F_TABLE_COLUMN)
VALUES
(L_J_ID, 'a', 'b');
INSERT INTO CFG_FILTER_JOIN
(J_ID, E_TABLE_COLUMN, F_TABLE_COLUMN)
VALUES
(L_J_ID, 'c', 'd');
END;
/
DECLARE
var NUMBER;
BEGIN
SELECT ID --number
INTO var
FROM some_table
WHERE F_TABLE_COLUMN = 'a'
AND E_TABLE_COLUMN = 'b';
INSERT INTO my_table
(ID, --in table definition: number(8)
NAME, --varchar2(30)
TYPE, --varchar2(30)
j_id --number(8)
"TABLE", --varchar2(30)--here is where I get the invalid number
COLUMN, --varchar2(30)
COLUMN_TYPE, --varchar2(1)
FILTER_LIST_ID) --number(8)
VALUES
(SEQ.NEXTVAL,
'COL_LIST',
'JL',
var,
'NB_CTL',
'DEST',
'V',
4);
END;
保留关键字为:http://docs.oracle.com/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm