For reference, I'm using sqldeveloper-22.2.1.234.1810-x64 and I'm facing the following error:
Error report -
ORA-06550: line 12, column 1:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
This is simply a program that calculates the average of the top 3 pilot salaries. I don't want to create the tables manually, I would rather have everything coded down.
Here is the code:
DECLARE
v_max1 REAL := 0.0;
v_max2 REAL := 0.0;
v_max3 REAL := 0.0;
moy REAL := 0.0;
temp REAL := 0.0;
v_num INTEGER := 0;
BEGIN
CREATE TABLE IF NOT EXISTS pilot(
id INTEGER PRIMARY KEY, name VARCHAR(64), city VARCHAR(64), age INTEGER, salary REAL);
INSERT INTO OR IGNORE pilot(1, "john", "portland", 34, 35000.0)
INSERT INTO OR IGNORE pilot(2, "sam", "nyc", 29, 30000.0)
INSERT INTO OR IGNORE pilot(3, "kim", "nashville", 39, 40000.0)
INSERT INTO OR IGNORE pilot(4, "dan", "san antonio", 41, 45000.0)
SELECT COUNT(id) INTO v_num
SELECT MIN(salary) INTO v_max1
v_max2 := v_max1
v_max3 := v_max2
FOR I IN 1..v_num LOOP
SELECT salary INTO temp FROM pilot WHERE id = I
IF temp > v_max1 THEN
v_max2 := v_max1
v_max1 := temp
ELSE IF temp > v_max2 THEN
v_max3 := v_max2
v_max2 := temp
ELSE IF temp > v_max3 THEN
v_max3 := temp
END IF;
END LOOP;
moy := (v_max1 + v_max2 + v_max3 / 3)
END;