在此處輸入影像描述使用帶有 SQL 命令的 PL/SQL 操作資料庫(PL/SQL 結構、資料型別、變數、DBMS 輸出和條件),這是我的代碼和我所了解的
uj5u.com熱心網友回復:
我的示例代碼沒有運行。它給
INSERT INTO Grades(STUDENT_ID, SName, Grades, Top_Average)VALUES(1001,'Carmina',75)
Error at Command Line : 8 Column : 59
Error report -
SQL Error: ORA-00947: not enough values
00947. 00000 - "not enough values"
原因是您的陳述句中有 4 列,但第一個插入陳述句的“值”部分中只有 3 個值。洗掉“top_average”列或添加值。
但是,該問題與您遇到的錯誤無關。截圖給出了它。您正在選擇以下 3 行
DECLARE
Grades NUMBER:= 75;
Top_Average NUMBER:= 100;
然后將其作為陳述句運行。如果您在 sqldeveloper 中選擇多行,它將嘗試僅將這些選定的行作為陳述句運行。這不是一個完整的宣告,所以它失敗了。
要解決它。將游標放在 pl/sql 塊之前或中并運行該陳述句。它運行時沒有錯誤,但它不顯示任何內容,因為set serveroutput on 塊之前缺少 。
這是格式正確的代碼
- 正確識別 pl/sql
- 將關鍵字更改為大寫,將識別符號更改為小寫(為了可讀性)
- pl/sql 中的重命名變數 - 請參閱注釋。
DROP TABLE grades;
CREATE TABLE grades(
student_id INT NOT NULL PRIMARY KEY,
sname VARCHAR2(50),
grades NUMBER,
top_average NUMBER(3)
);
INSERT INTO grades(student_id, sname, grades) VALUES (1001,'Carmina',75);
INSERT INTO grades(student_id, sname, grades,top_average) VALUES (1002,'Danielle',90,100);
INSERT INTO grades(student_id, sname, grades,top_average) VALUES (1003,'Sophia',80,100);
INSERT INTO grades(student_id, sname, grades,top_average) VALUES (1004,'Zoe',85,100);
INSERT INTO grades(student_id, sname, grades,top_average) VALUES (1005,'Carlo',78,100);
SELECT * FROM grades;
set serveroutput on size 999999
--clear screen
DECLARE
-- do NOT name your variables the same as your column names. It's confusing. Instead prefix with "l_" (local variable)
l_grades NUMBER:= 75;
l_top_average NUMBER:= 100;
BEGIN
dbms_output.put_line('The sum of ' || l_grades ||' and ' || l_top_average || ' is ' || (l_grades l_top_average));
dbms_output.put_line('The difference of ' || l_grades ||' and ' || l_top_average || ' is ' || (l_grades - l_top_average));
dbms_output.put_line('The product of ' || l_grades ||' and ' || l_top_average || ' is ' || (l_grades * l_top_average));
IF l_top_average = l_grades THEN
dbms_output.put_line('The quotient of ' || l_grades ||' and ' || l_top_average|| ' is ' || ' FAILED');
ELSE
dbms_output.put_line('The quotient of ' || l_grades ||' and ' || l_top_average || ' is ' || (l_grades / l_top_average));
END IF;
END;
/
Table GRADES created.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
STUDENT_ID SNAME GRADES TOP_AVERAGE
---------- -------------------------------------------------- ---------- -----------
1001 Carmina 75
1002 Danielle 90 100
1003 Sophia 80 100
1004 Zoe 85 100
1005 Carlo 78 100
The sum of 75 and 100 is 175
The difference of 75 and 100 is -25
The product of 75 and 100 is 7500
The quotient of 75 and 100 is .75
PL/SQL procedure successfully completed.
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/371577.html
標籤:sql 甲骨文 plsql oracle-sqldeveloper
下一篇:PL/SQL創建程序-階乘
