我已经看到类似的问题,但我似乎无法正常工作。我正在开发一个程序,它几乎可以作为一个简单的select语句。闭包是主表的名称。我正在使用TOAD&如果需要该信息,则为APEX。
Tbl_Web_Closures
(
RECORDID NUMBER,
BEGDATE DATE,
ENDDATE DATE,
STLOCATION VARCHAR2(50 BYTE),
DESCRIPTION VARCHAR2(400 BYTE),
STATUS NUMBER,
TYPEOF NUMBER,
INACTIVEDATE DATE,
AGENCY NUMBER,
CITY NUMBER,
ROUTEDESCRIPTION VARCHAR2(4000 BYTE),
NAMEEVENT VARCHAR2(40 BYTE),
TIMESTART DATE,
TIMEEND DATE
我已经清楚地了解了你可以在程序中使用简单的select语句,并且需要某种形式的into语句。
我尝试了很多变化,仍然无法获得我想要的结果。我不仅需要一个结果,而且还需要与查询匹配的所有结果。
哪个是
SELECT "STLOCATION" AS "Location",
"BEGDATE" AS "Begin Date",
"ENDDATE" AS "End Date",
"TBL_WEBCLOSURES"."DESCRIPTION" AS "Description",
"TBL_TYPE"."TYPESIT" AS "Type",
"TBL_CITY"."CITY" AS "City"
FROM "TBL_CITY" "TBL_CITY",
"TBL_TYPE" "TBL_TYPE",
"TBL_STATUS" "TBL_STATUS",
"TBL_AGENCY" "TBL_AGENCY",
"TBL_WEBCLOSURES" "TBL_WEBCLOSURES"
WHERE "TBL_AGENCY"."AGENCYID" = "TBL_WEBCLOSURES"."AGENCY"
AND "TBL_STATUS"."STATUSID" = "TBL_WEBCLOSURES"."STATUS"
AND "TBL_TYPE"."TYPEID" = "TBL_WEBCLOSURES"."TYPEOF"
AND "TBL_CITY"."CITYID" = "TBL_WEBCLOSURES"."CITY"
AND "TBL_WEBCLOSURES".AGENCY = '2'
AND ENDDATE = TRUNC (SYSDATE + 5);
我尝试过多种变体,包括
create or replace procedure my_Procedure (v_my_var in char default null
,cv_1 OUT TBL_WEBCLOSURES%rowtype) as rt TBL_WEBCLOSURES%rowtype;
begin
SELECT *
into rt
FROM TBL_WEBCLOSURES
WHERE ENDDATE = TRUNC (SYSDATE + 5);
END my_Procedure;
另一个
CREATE OR REPLACE PROCEDURE "ABC6" (
stlocation IN VARCHAR2,
o_stlocation OUT TBL_WEBCLOSURES%ROWTYPE,
BEGDATE IN DATE,
o_begdate OUT TBL_WEBCLOSURES%ROWTYPE,
ENDDATE IN DATE,
o_enddate OUT TBL_WEBCLOSURES%ROWTYPE,
DESCRIPTION IN VARCHAR2,
o_description OUT TBL_WEBCLOSURES%ROWTYPE,
TYPESIT IN NUMBER,
o_typesit OUT TBL_WEBCLOSURES%ROWTYPE,
CITY IN NUMBER,
o_city OUT TBL_WEBCLOSURES%ROWTYPE)
IS
BEGIN
SELECT "STLOCATION" AS "Location",
"BEGDATE" AS "Begin Date",
"ENDDATE" AS "End Date",
"TBL_WEBCLOSURES"."DESCRIPTION" AS "Description",
"TBL_TYPE"."TYPESIT" AS "Type"
"TBL_CITY"."CITY" AS "City"
INSERT INTO o_stlocation,
o_begdate,
o_enddate,
o_description,
o_typesit,
o_city
FROM "TBL_CITY" "TBL_CITY",
"TBL_TYPE" "TBL_TYPE",
"TBL_STATUS" "TBL_STATUS",
"TBL_AGENCY" "TBL_AGENCY",
"TBL_WEBCLOSURES" "TBL_WEBCLOSURES"
WHERE "TBL_AGENCY"."AGENCYID" = "TBL_WEBCLOSURES"."AGENCY"
AND "TBL_STATUS"."STATUSID" = "TBL_WEBCLOSURES"."STATUS"
AND "TBL_TYPE"."TYPEID" = "TBL_WEBCLOSURES"."TYPEOF"
AND "TBL_CITY"."CITYID" = "TBL_WEBCLOSURES"."CITY"
AND "TBL_WEBCLOSURES".AGENCY = '2'
AND ENDDATE = TRUNC (SYSDATE + 5);
END;
我已经修改过,尝试过不同的方式,等等。我似乎无法正确地将其推出。
答案 0 :(得分:0)
不推荐。您可以创建yourtable%ROWTYPE的记录。创建一个记录集合(它是pl / sql类型)。然后用值填充该表并返回。链接:http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/05_colls.htm
好。在过程中定义一个out光标。使用select填充该过程。完成。链接:http://www.oracle-base.com/articles/misc/using-ref-cursors-to-return-recordsets.php
答案 1 :(得分:0)
我想我几乎已经明白了。
CREATE OR REPLACE PROCEDURE roadclosure_notif4
IS
road_refcur2 SYS_REFCURSOR;
v_stlocation TBL_WEBCLOSURES.stlocation%TYPE;
v_enddate TBL_WEBCLOSURES.DESCRIPTION%TYPE;
BEGIN
OPEN road_refcur2 FOR
'SELECT "STLOCATION",
"ENDDATE"
FROM "TBL_CITY" "TBL_CITY",
"TBL_TYPE" "TBL_TYPE",
"TBL_STATUS" "TBL_STATUS",
"TBL_AGENCY" "TBL_AGENCY",
"TBL_WEBCLOSURES" "TBL_WEBCLOSURES"
WHERE "TBL_AGENCY"."AGENCYID" = "TBL_WEBCLOSURES"."AGENCY"
AND "TBL_STATUS"."STATUSID" = "TBL_WEBCLOSURES"."STATUS"
AND "TBL_TYPE"."TYPEID" = "TBL_WEBCLOSURES"."TYPEOF"
AND "TBL_CITY"."CITYID" = "TBL_WEBCLOSURES"."CITY"
AND "TBL_WEBCLOSURES".AGENCY = 2
AND ENDDATE = TRUNC (SYSDATE + 5)';
DBMS_OUTPUT.PUT_LINE ('Location End Date');
LOOP
FETCH road_refcur2 INTO v_stlocation, v_enddate;
EXIT WHEN road_refcur2%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (v_stlocation || ' ' || v_enddate);
END LOOP;
CLOSE road_refcur2;
END;
/