Oracle 是否可以在过程中将数组作为参数传递?
我试图在我的过程中传递一个数组作为参数,但我一直得到一个未知的命令错误 代码Oracle 是否可以在过程中将数组作为参数传递?,oracle,plsql,procedure,Oracle,Plsql,Procedure,我试图在我的过程中传递一个数组作为参数,但我一直得到一个未知的命令错误 代码 SET SERVEROUTPUT ON; TYPE pourcentage_remise IS TABLE OF NUMBER INDEX BY commandeproduit.ref_produit%type; CREATE OR REPLACE PROCEDURE remise_produit( pourcent IN pourcentage_remise,
SET SERVEROUTPUT ON;
TYPE pourcentage_remise IS TABLE OF NUMBER INDEX BY commandeproduit.ref_produit%type;
CREATE OR REPLACE PROCEDURE remise_produit( pourcent IN pourcentage_remise,
ref_comm IN commande.ref_commande%type,
c_ht OUT commandeproduit.prix_ht%type,
c_ttc OUT commandeproduit.prix_ttc%type)
IS
CURSOR p_curs IS
SELECT ref_produit, prix_ttc, prix_ht FROM commandeproduit WHERE concerne = ref_comm ;
ref commandeproduit.ref_produit%type;
ttc commandeproduit.prix_ttc%type;
ht commandeproduit.prix_ht%type;
BEGIN
open p_curs;
LOOP
FETCH p_curs into ref, ttc, ht;
EXIT WHEN p_curs%notfound;
dbms_output.put_line(ref, ' ',ht, ' ', ttc);
IF pourcent(ref) THEN
ttc := ttc - ttc * pourcent(ref);
ht := ht - ttc * pourcent(ref);
INSERT INTO commandeproduit(prix_ht, prix_ttc) VALUES(ht, ttc) WHERE concerne = ref_comm AND ref_produit = ref;
END IF;
dbms_output.put_line(ref, ' ',ht, ' ', ttc);
END LOOP;
close p_curs;
END remise_produit;
/
过程调用
DECLARE
pourcentage pourcentage_remise;
reference commande.ref_commande%type :=1;
BEGIN
pourcentage('A01') :=0.15;
pourcentage('B15') :=0.2;
remise_produit(pourcentage, reference);
END;
/
表格
法语中的错误,表示命令未知
请帮助您的语法错误出现在您的类型声明中,因此不需要您的其他代码
TYPE pourcentage_remise IS TABLE OF NUMBER INDEX BY commandeproduit.ref_produit%type;
几个问题
- 如果试图在SQL中声明类型,则需要使用
,因此缺少创建类型
创建
- 如果试图在SQL中声明表类型,则不能使用关联数组。实际上,您需要一个嵌套表
- 如果您试图声明PL/SQL类型,则语句需要位于PL/SQL块中。可以声明包含关联数组类型的包
CREATE TYPE pourcentage_remise IS TABLE OF NUMBER;
如果要在PL/SQL包中声明关联数组
CREATE OR REPLACE PACKAGE my_collection_pkg
AS
TYPE pourcentage_remise IS TABLE OF NUMBER INDEX BY commandeproduit.ref_produit%type;
END;
如果要使用嵌套表类型,则会更改需要初始化关联数组的方式。它应该改变您引用该数组元素的方式,但我对您的代码感到困惑。您的过程似乎在使用数字索引访问关联数组的元素,如果关联数组使用字符串作为索引,则该操作没有意义