ASP Stored Procedure VS Oracle [新增資料]

摘要:ASP Stored Procedure VS Oracle [新增資料]

建立Table

 

  CREATE TABLE A1
  (	
  "Fname" VARCHAR2(200 BYTE), 
  "Fnum" NUMBER
   )

 

建立Procedure

 

CREATE OR REPLACE PROCEDURE Insert_a1(
var_col1 IN RCHAR2,
var_col2 IN NUMBER
)
IS
BEGIN
    INSERT INTO A1 (Fname,Fnum) VALUES (var_col1,var_col2);
    COMMIT;
END;

Procedure建立完成後,先測試能不能使用。

例如:CALL Insert_a1('aaa',1234)

 

接著在APS中要使用Stored Procedure新增資料

 

'使用Command Object
Set cmd = Server.CreateObject("ADODB.Command")
'objConnect是已經設定好的連線物件
Set cmd.ActiveConnection = objConnect
'給予準備插入資料欄位的值
V1 = "aaa"
V2 = 5
'
With cmd
  'Sets or returns a provider command
  .CommandText = "Insert_a1"

  'Sets or returns the type of a Command object
  .CommandType = 4

  'Creates a new Parameter object
  .Parameters.Append .CreateParameter("var_col1", 200,1, 200, V1)
  .Parameters.Append .CreateParameter("var_col2", 3,1, 4, V2)
  'Executes the query
  .Execute
End With