Pl / SQL匿名块函数调用

时间:2015-12-01 20:10:51

标签: sql database plsql

ALTER SESSION SET CURRENT_SCHEMA = ftest;
SET SERVEROUTPUT ON;

DECLARE
  R_id rooms.room_id%TYPE:='Enter Room id';

BEGIN

  RoomCapacity(R_id);

EXCEPTION
when others then
  dbms_output.put_line(SQLCODE||SQLERRM);
 rollback work;

END;

尝试在匿名的sql代码块中调用函数。似乎没有什么能让它进入这个功能。我这里有一个参考表,但它只有使用多个函数的例子

if client_exists(buyer)then
  if car_exists(regin)then
    sell_car(regin, buyer, price, sdate);

2 个答案:

答案 0 :(得分:0)

直接使用该函数或将其存储在如下变量中:

ALTER SESSION SET CURRENT_SCHEMA = ftest;
SET SERVEROUTPUT ON;

DECLARE
  R_id rooms.room_id%TYPE:='Enter Room id';
  v_temp <DATATYPE OF THE FUNCTION RETURN>;

BEGIN

  v_temp := RoomCapacity(R_id);
  dbms_output.put_line(v_temp); --displays the result/return of your function

EXCEPTION
when others then
  dbms_output.put_line(SQLCODE||SQLERRM);
 rollback work;

END;

答案 1 :(得分:0)

Hello i have illustrated 2 menthods of calling function. Let me know if this helps.

-- First way to call a function
ALTER SESSION SET CURRENT_SCHEMA = ftest;
SET SERVEROUTPUT ON;
DECLARE
  R_id rooms.room_id%TYPE:=&Enter_Room_id;
  lv_var                  <Datatype_of_function>;
BEGIN
  lv_var:=RoomCapacity(R_id);
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line(SQLCODE||SQLERRM);
  ROLLBACK;
END;
-- Second way to call a function by direct sql invokation

SELECT RoomCapacity(R_id)
FROM DUAL;