我是pl / sql的新手! 我正在尝试使用简单的冒泡排序算法对记录表进行排序。有什么问题?
我在哪里可以找到有关使用记录表的更多信息?
DECLARE
text VARCHAR2(50);
TYPE TIP_VECTOR
IS
TABLE OF INT INDEX BY BINARY_INTEGER;
TYPE contorRecord
IS
record
(
codASCII VARCHAR2(3),
contor SMALLINT);
TYpe tip_vector2
IS
TABLE OF contorRecord;
VECTOR TIP_VECTOR;
VECTOR2 TIP_VECTOR2 := TIP_VECTOR2();
aux tip_vector2 := tip_vector2();
v_char VARCHAR2(3);
FLAG BOOLEAN := TRUE;
t smallint;
n SMALLINT := 1;
ind SMALLINT := 0;
begin
AUX.EXTEND(1);
WHILE(FLAG)
LOOP
FLAG := FALSE;
-- here is the problem; what i'm doing wrong?
FOR I IN 1..(vector2.count-1) LOOP
-- here is the problem; what i'm doing wrong?
IF VECTOR2(I).CONTOR < VECTOR2(I+1).contor THEN
AUX := VECTOR(I+1);
VECTOR(i+1) := VECTOR(I);
VECTOR(I) := AUX;
FLAG := TRUE;
END IF;
END LOOP;
END LOOP;
end;
错误:
Error report:
PLS-00382: expression is of wrong type
PL/SQL: Statement ignored
PLS-00382: expression is of wrong type
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
答案 0 :(得分:4)
如果你不想自己动手,这是一个很好的技巧:http://technology.amis.nl/blog/1217/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting
答案 1 :(得分:3)
也许这不是你真正需要的方式。通常,您可以从PL / SQL代码中使用SQL中受益 - 在SQL中,您只需按结果排序即可。你试图解决的问题是什么?
有关PL / SQL集合的信息,请访问:PL/SQL Language Reference
答案 2 :(得分:2)
你的类型和变量混在一起。尝试:
DECLARE
TYPE contorRecord IS record ( codASCII VARCHAR2(3), contor SMALLINT);
TYpe tip_vector2 IS TABLE OF contorRecord;
VECTOR2 TIP_VECTOR2 := TIP_VECTOR2();
aux contorRecord;
FLAG BOOLEAN := TRUE;
begin
WHILE(FLAG)
LOOP
FLAG := FALSE;
FOR I IN 1..(vector2.count-1) LOOP
IF VECTOR2(I).CONTOR < VECTOR2(I+1).contor THEN
AUX := VECTOR2(I+1);
VECTOR2(i+1) := VECTOR2(I);
VECTOR2(I) := AUX;
FLAG := TRUE;
END IF;
END LOOP;
END LOOP;
end;
/
(通过删除所有未使用的类型和变量进行整理)