Union select as cursor in procedure
Hi!
With ref. to an earlier post from Sept. 11, 2009, I am facing the following problem:
In my procedure I have this statement as a cursor:
SELECT a.carrier_code, a.flight_no, a.from_city, a.origin, a.dept_time, a.to_city, a.destination, a.arr_time, a.flight_date,
a.aircraft_type, a.booking_class, a.service_class, a.num_of_seats, a.checked_bag, a.fare_basis, a.fare_type, a.currency, a.rt_net_fare, a.tax, a.surcharges, a.fare_total
FROM favailability a, main_related_flight b
WHERE a.flight_leg_id = b.flight_leg_id_1
AND a.from_city = 'London'
AND a.service_class = 'Business'
AND a.fare_type = 'Business Saver'
AND a.flight_date = '27.09.09'
UNION
SELECT d.carrier_code, d.flight_no, d.from_city, d.origin, d.dept_time, d.to_city, d.destination, d.arr_time, d.flight_date,
d.aircraft_type, d.booking_class, d.service_class, d.num_of_seats, d.checked_bag, d.fare_basis, d.fare_type, d.currency, d.rt_net_fare, d.tax, d.surcharges, d.fare_total
FROM favailability d, main_related_flight e
WHERE d.flight_leg_id = e.flight_leg_id_2
AND d.from_city = 'Zurich'
AND d.service_class = 'Business'
AND d.fare_type = 'Business Flex'
AND d.flight_date = '03.10.09'
ORDER BY flight_date;
ARRIER_CODE FLIGHT_NO FROM_CITY ORIGIN DEPT_TIME TO_CITY DESTINATION ARR_TIME FLIGHT_DATE AIRCRAFT_TYPE BOOKING_CLASS SERVICE_CLASS NUM_OF_SEATS CHECKED_BAG FARE_BASIS FARE_TYPE CURRENCY RT_NET_FARE TAX SURCHARGES FARE_TOTAL
LX 345 London LHR 06:00 Zurich ZRH 08:40 27.09.09 Airbus A320 J Business 64 30 kg LXJ Business Saver EUR 337 30,01 35,24 402,25
LX 450 Zurich ZRH 07:00 London LCY 07:35 03.10.09 AVRO RJ100 Z Business 37 30 kg LXZ Business Flex EUR 740 30,01 21,24 791,25
2 rows selectedworks fine when running the statement alone. However, when running the procedure, my exception appears:
ORA-20022: Fare not found for flight from London to Zurich on 27-Sep-2009
Please note that the fare type can be different for inbound and outbound flights.
PROCEDURE FLIGHT (p_ptc_adult IN NUMBER,
p_ptc_adult_rt IN NUMBER,
p_ptc_adult_add IN NUMBER,
p_ptc_adult_add_rt IN NUMBER,
p_city_o IN favailability.from_city%TYPE,
p_city_d IN favailability.to_city%TYPE,
p_service_class IN favailability.service_class%TYPE,
p_fare_type IN favailability.fare_type%TYPE,
p_fare_type_rt IN favailability.fare_type%TYPE,
p_flightdate IN favailability.flight_date%TYPE,
p_flightdate_rt IN favailability.flight_date%TYPE,
p_username IN users.username%TYPE,
p_password IN users.password%TYPE,
p_card_type IN users_cc.card_type%TYPE,
p_creditcardnumber IN VARCHAR2,
p_expiry_date IN DATE,
p_first_name_add IN VARCHAR2,
p_last_name_add IN VARCHAR2) IS
CURSOR c1 IS
SELECT a.carrier_code, a.flight_no, a.from_city, a.origin, a.dept_time, a.to_city, a.destination, a.arr_time, a.flight_date,
a.aircraft_type, a.booking_class, a.service_class, a.num_of_seats, a.checked_bag, a.fare_basis, a.fare_type, a.currency, a.rt_net_fare, a.tax, a.surcharges, a.fare_total
FROM favailability a, main_related_flight b
WHERE a.flight_leg_id = b.flight_leg_id_1
AND a.from_city = p_city_o
AND a.service_class = p_service_class
AND a.fare_type = p_fare_type
AND a.flight_date = p_flightdate
UNION
SELECT d.carrier_code, d.flight_no, d.from_city, d.origin, d.dept_time, d.to_city, d.destination, d.arr_time, d.flight_date,
d.aircraft_type, d.booking_class, d.service_class, d.num_of_seats, d.checked_bag, d.fare_basis, d.fare_type, d.currency, d.rt_net_fare, d.tax, d.surcharges, d.fare_total
FROM favailability d, main_related_flight e
WHERE d.flight_leg_id = e.flight_leg_id_2
AND d.from_city = p_city_d
AND d.service_class = p_service_class
AND d.fare_type = p_fare_type_rt
AND d.flight_date = p_flightdate_rt
ORDER BY flight_date;
f_rec c1%ROWTYPE;
v_num_of_seats favailability.num_of_seats%TYPE;
v_fare_type favailability.fare_type%TYPE;
v_fare_type_rt favailability.fare_type%TYPE;
v_net_fare favailability.rt_net_fare%TYPE;
v_currency fl_itinerary_t.currency_t%TYPE;
v_rid fl_itinerary_t.rid%TYPE;
v_status fl_itinerary_t.status%TYPE;
v_ptc_adult NUMBER;
v_ptc_adult_rt NUMBER;
v_ptc_adult_add NUMBER;
v_ptc_adult_add_rt NUMBER;
e_no_passenger EXCEPTION;
e_no_available_fares EXCEPTION;
e_no_user EXCEPTION;
e_credit_card_expired EXCEPTION;
v_error_code error_log.err_code%TYPE;
v_error_message error_log.err_message%TYPE;
v_error_date error_log.err_date%TYPE;
v_user_name users.username%TYPE;
v_password users.password%TYPE;
v_user_id users.user_id%TYPE;
v_first_name users.first_name%TYPE;
v_last_name users.last_name%TYPE;
v_dob users.dob%TYPE;
v_country_code users.country_code%TYPE;
v_prefix users.prefix%TYPE;
v_mobile_phone users.mobile_phone%TYPE;
v_card_type users_cc.card_type%TYPE;
v_creditcardnumber users_cc.card_number%TYPE;
v_expiry_date DATE;
v_grand_total NUMBER(10,2);
v_first_name_add VARCHAR2(40);
v_last_name_add VARCHAR2(40);
v_booking_code VARCHAR2(6);
v_result VARCHAR2(32);
BEGIN
v_ptc_adult := p_ptc_adult;
v_ptc_adult_rt := p_ptc_adult_rt;
v_ptc_adult_add := p_ptc_adult_add;
v_ptc_adult_add_rt := p_ptc_adult_add_rt;
-- Check user input
IF p_city_o = p_city_d THEN
dbms_output.put_line ('Departure city cannot be arrival city!');
ELSIF p_flightdate = p_flightdate_rt THEN
dbms_output.put_line ('Departure date cannot be arrival date!');
ELSIF p_flightdate > p_flightdate_rt THEN
dbms_output.put_line ('Departure date cannot be after arrival date!');
ELSIF p_flightdate < sysdate OR p_flightdate_rt < sysdate THEN
dbms_output.put_line ('Departure and arrival date cannot be in the past!');
ELSE
IF nvl(trunc(p_ptc_adult), 0) = 0
OR nvl(trunc(p_ptc_adult_rt), 0) = 0
THEN
RAISE e_no_passenger;
END IF;
-- Check outbound availability
SELECT num_of_seats INTO v_num_of_seats
FROM favailability
WHERE v_ptc_adult = p_ptc_adult
AND v_ptc_adult_add = p_ptc_adult_add
AND from_city = p_city_o
AND to_city = p_city_d
AND service_class = p_service_class
AND fare_type = p_fare_type
AND fare_type = p_fare_type_rt
AND flight_date = p_flightdate;
IF p_ptc_adult > v_num_of_seats
OR v_num_of_seats < 2 THEN
dbms_output.put_line ('No seats available!');
ELSE
UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult
WHERE v_ptc_adult = p_ptc_adult
AND from_city = p_city_o
AND to_city = p_city_d
AND service_class = p_service_class
AND fare_type = p_fare_type
AND fare_type = p_fare_type_rt
AND flight_date = p_flightdate;
END IF;
IF p_ptc_adult_add > v_num_of_seats
OR v_num_of_seats < 2 THEN
dbms_output.put_line ('No seats available!');
ELSE
UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult_add
WHERE v_ptc_adult_add = p_ptc_adult_add
AND from_city = p_city_o
AND to_city = p_city_d
AND service_class = p_service_class
AND fare_type = p_fare_type
AND fare_type = p_fare_type_rt
AND flight_date = p_flightdate;
END IF;
-- Check inbound availability
SELECT num_of_seats INTO v_num_of_seats
FROM favailability
WHERE v_ptc_adult_rt = p_ptc_adult_rt
AND v_ptc_adult_add_rt = p_ptc_adult_add_rt
AND from_city = p_city_d
AND to_city = p_city_o
AND service_class = p_service_class
AND fare_type = p_fare_type_rt
AND fare_type = p_fare_type
AND flight_date = p_flightdate_rt;
IF p_ptc_adult_rt > v_num_of_seats
OR v_num_of_seats < 2 THEN
dbms_output.put_line ('No seats available!');
ELSE
UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult_rt
WHERE v_ptc_adult_rt = p_ptc_adult_rt
AND from_city = p_city_d
AND to_city = p_city_o
AND service_class = p_service_class
AND fare_type = p_fare_type_rt
AND fare_type = p_fare_type
AND flight_date = p_flightdate_rt;
END IF;
IF p_ptc_adult_add_rt > v_num_of_seats
OR v_num_of_seats < 2 THEN
dbms_output.put_line ('No seats available!');
ELSE
UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult_add_rt
WHERE v_ptc_adult_add_rt = p_ptc_adult_add_rt
AND from_city = p_city_d
AND to_city = p_city_o
AND service_class = p_service_class
AND fare_type = p_fare_type_rt
AND fare_type = p_fare_type
AND flight_date = p_flightdate_rt;
END IF;
-- get credit info
SELECT u.user_id, u.first_name, u.last_name, u.dob, u.country_code, u.prefix, u.mobile_phone, p_card_type, p_creditcardnumber, p_expiry_date
INTO v_user_id, v_first_name, v_last_name, v_dob, v_country_code, v_prefix, v_mobile_phone, v_card_type, v_creditcardnumber, v_expiry_date
FROM dual, users u, users_cc c
WHERE u.user_id = c.user_id
AND u.username = p_username
AND u.password = p_password
AND c.card_type = p_card_type
AND c.card_number = p_creditcardnumber
AND c.expiry_date = p_expiry_date;
IF SQL%ROWCOUNT = 0 THEN
RAISE e_no_user;
END IF;
IF p_expiry_date < sysdate THEN
RAISE e_credit_card_expired;
END IF;
v_result := booking_pkg.validatecreditcard(p_creditcardnumber);
-- open cursor
OPEN c1;
LOOP
FETCH c1 INTO f_rec;
EXIT WHEN c1%notfound;
-- insert records
INSERT INTO fl_itinerary_t (rid, carrier_t, fno_t, from_city_t, origin_t, dept_t, to_city_t, destination_t, arr_t, fdate_t, aircraft_type_t, booking_class_t, service_class_t,
num_of_seats_t, checked_bag_t, fare_basis_t, fare_type_t, currency_t, fare_t, tax_t, surcharges_t, fare_total_t, grand_total_t, trans_date,
status, user_id, first_name, last_name, dob, country_code, prefix, mobile_phone)
VALUES (new_res_seq.nextval, f_rec.carrier_code, f_rec.flight_no, f_rec.from_city, f_rec.origin, f_rec.dept_time, f_rec.to_city, f_rec.destination, f_rec.arr_time, f_rec.flight_date, f_rec.aircraft_type, f_rec.booking_class,
f_rec.service_class, p_ptc_adult + p_ptc_adult_add, f_rec.checked_bag, f_rec.fare_basis, f_rec.fare_type, f_rec.currency, f_rec.rt_net_fare, f_rec.tax, f_rec.surcharges, f_rec.fare_total, f_rec.fare_total * (p_ptc_adult + p_ptc_adult_add), sysdate,
'Confirmed', v_user_id, v_first_name, v_last_name, v_dob, v_country_code, v_prefix, v_mobile_phone);
-- additional traveller
SELECT p_first_name_add, p_last_name_add
INTO v_first_name_add, v_last_name_add
FROM dual;
IF v_ptc_adult_add = p_ptc_adult_add
AND v_ptc_adult_add_rt = p_ptc_adult_add_rt
AND v_first_name_add = p_first_name_add
AND v_last_name_add = p_last_name_add
THEN
INSERT INTO fl_itinerary_add (trans_id, carrier, fno, from_city, to_city, fdate, first_name_2, last_name_2, dob_2, main_user_id, trans_date, status)
VALUES (new_trans_seq.nextval, f_rec.carrier_code, f_rec.flight_no, f_rec.from_city, f_rec.to_city, f_rec.flight_date, v_first_name_add, v_last_name_add, null, v_user_id, sysdate, 'Confirmed');
END IF;
COMMIT;
END LOOP;
CLOSE c1;
-- show itinerary for main traveller
dbms_output.put_line ('Itinerary completed!');
dbms_output.put_line (v_ptc_adult || ' seat(s) reserved for ' || v_first_name ||', ' || v_last_name);
dbms_output.put_line (v_ptc_adult_rt || ' seat(s) reserved for ' || v_first_name ||', ' || v_last_name);
-- show itinerary for 2.traveller
dbms_output.put_line (v_ptc_adult_add || ' seat(s) reserved for ' || v_first_name_add ||', ' || v_last_name_add);
dbms_output.put_line (v_ptc_adult_add_rt || ' seat(s) reserved for ' || v_first_name_add ||', ' || v_last_name_add);
END IF;
-- Create new booking
INSERT INTO booking (booking_id,
rid,
e_ticket_no,
booking_code,
user_id,
first_name,
last_name,
dob,
credit_card_type,
credit_card_number,
currency,
booking_date,
status)
VALUES (new_booking_seq.nextval,
new_res_seq.currval,
dbms_random.value(1000000000000, 9999999999999),
dbms_random.string('X', 6),
v_user_id,
v_first_name,
v_last_name,
v_dob,
v_card_type,
'xxxx-xxxx-xxxx-'||substr(v_creditcardnumber,-4),
f_rec.currency,
SYSDATE, 'Confirmed');
SELECT booking_code
INTO v_booking_code
FROM booking;
dbms_output.put_line ('Booking code: ' || v_booking_code);
EXCEPTION
WHEN e_no_available_fares THEN
RAISE_APPLICATION_ERROR (-20021, 'There are no fares available for flight'||
' from '|| p_city_o||' to '|| p_city_d||' on '||TO_CHAR(p_flightdate, 'dd-Mon-yyyy'));
WHEN no_data_found THEN
RAISE_APPLICATION_ERROR (-20022, 'Fare not found for flight from '|| p_city_o||
' to '|| p_city_d||' on '||TO_CHAR(p_flightdate, 'dd-Mon-yyyy'));
WHEN too_many_rows THEN
RAISE_APPLICATION_ERROR (-20023, 'More than one fare found for flight from '||
p_city_o||' to '|| p_city_d||' on '||
TO_CHAR(p_flightdate, 'dd-Mon-yyyy'));
WHEN e_no_passenger THEN
RAISE_APPLICATION_ERROR(-20001, 'Please enter a valid number of travelers!');
WHEN e_no_user THEN
RAISE_APPLICATION_ERROR(-20002, 'User not found!');
WHEN e_credit_card_expired THEN
RAISE_APPLICATION_ERROR(-20003, 'Credit card has expired!');
--WHEN OTHERS THEN
-- v_error_code := SQLCODE;
-- v_error_message := SUBSTR(SQLERRM, 1, 200);
-- INSERT INTO error_log (err_code, err_message, err_date) VALUES
-- (v_error_code, v_error_message, sysdate);
END FLIGHT;Furthermore, only 1 booking can be inserted into the booking table.
Hi!
Thanks for the tip! Now inserting into the booking table works! Sorry for bothering again. In my package I have this function that should check the
credit card number. Works alone, but not within the package (procedure). Please see above procedure too.
FUNCTION VALIDATECREDITCARD (p_creditcardnumber IN VARCHAR2)
RETURN VARCHAR2
IS
creditcardnumber VARCHAR2 (32);
--:= nosymbols (p_CreditCardNumber, LENGTH (p_CreditCardNumber));
creditcardlength NUMBER := LENGTH (p_creditcardnumber);
subtotal NUMBER := 0;
t_value NUMBER := 0;
c1 NUMBER;
c2 NUMBER;
c3 NUMBER;
c4 NUMBER;
cardtype VARCHAR2 (160) := 'CARD';
calculationmethod VARCHAR2 (160) := 'UNKNOWN';
RESULT VARCHAR2 (160);
v_expiry_date DATE;
BEGIN
creditcardnumber := LTRIM(RTRIM(p_creditcardnumber));
creditcardnumber := REPLACE(creditcardnumber, '-');
creditcardnumber := REPLACE(creditcardnumber, '.');
-- IF isnumber (CreditCardNumber) = 0 THEN
c1 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 1));
c2 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 2));
c3 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 3));
c4 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 4));
IF creditcardlength = 13
THEN
IF c1 IN (4)
THEN
cardtype := 'VISA';
calculationmethod := 'MOD10';
END IF;
ELSIF creditcardlength = 14
THEN
IF c2 IN (36, 38)
THEN
cardtype := 'DINERS CLUB';
calculationmethod := 'MOD10';
ELSIF c3 IN (300, 301, 302, 303, 304, 305)
THEN
cardtype := 'DINERS CLUB';
calculationmethod := 'MOD10';
END IF;
ELSIF creditcardlength = 15
THEN
IF c2 IN (34, 37)
THEN
cardtype := 'AMEX';
calculationmethod := 'MOD10';
ELSIF c4 IN (2014, 2149)
THEN
cardtype := 'enROUTE';
calculationmethod := 'ANY';
ELSIF c4 IN (2131, 1800)
THEN
cardtype := 'JBC';
calculationmethod := 'MOD10';
END IF;
ELSIF creditcardlength = 16
THEN
IF c1 IN (4)
THEN
cardtype := 'VISA';
calculationmethod := 'MOD10';
ELSIF c1 IN (3)
THEN
cardtype := 'JBC';
calculationmethod := 'MOD10';
ELSIF c2 IN (51, 52, 53, 54, 55)
THEN
cardtype := 'MASTERCARD';
calculationmethod := 'MOD10';
ELSIF c4 IN (6011)
THEN
cardtype := 'DISCOVER';
calculationmethod := 'MOD10';
END IF;
END IF;
IF calculationmethod = 'MOD10'
THEN
FOR i IN REVERSE 1 .. LENGTH (creditcardnumber)
LOOP
IF cardtype = 'AMEX'
THEN
IF (TO_NUMBER (SUBSTR (TO_CHAR (i), LENGTH (i), 1)) NOT IN (1, 3, 5, 7, 9))
THEN
t_value := SUBSTR (creditcardnumber, i, 1) * 2;
subtotal := subtotal + SUBSTR (t_value, 1, 1);
subtotal := subtotal + NVL (SUBSTR (t_value, 2, 1), 0);
ELSE
subtotal := subtotal + SUBSTR (creditcardnumber, i, 1);
END IF;
ELSE
IF (TO_NUMBER (SUBSTR (TO_CHAR (i), LENGTH (i), 1)) IN (1, 3, 5, 7, 9))
THEN
t_value := SUBSTR (creditcardnumber, i, 1) * 2;
subtotal := subtotal + SUBSTR (t_value, 1, 1);
subtotal := subtotal + NVL (SUBSTR (t_value, 2, 1), 0);
ELSE
subtotal := subtotal + SUBSTR (creditcardnumber, i, 1);
END IF;
END IF;
END LOOP;
IF MOD (subtotal, 10) = 0
THEN
RESULT := 'VALID';
ELSE
RESULT := 'INVALID';
END IF;
ELSIF calculationmethod = 'ANY'
THEN
RESULT := 'VALID';
ELSE
RESULT := 'UNKNOWN';
END IF;
RESULT := RESULT || ', ' || cardtype;
RETURN (RESULT);
END VALIDATECREDITCARD;
create or replace PACKAGE "BOOKING_PKG"
AS
PROCEDURE FLIGHT (p_ptc_adult IN NUMBER,
p_ptc_adult_rt IN NUMBER,
p_ptc_adult_add IN NUMBER,
p_ptc_adult_add_rt IN NUMBER,
p_city_o IN favailability.from_city%TYPE,
p_city_d IN favailability.to_city%TYPE,
p_service_class IN favailability.service_class%TYPE,
p_fare_type IN favailability.fare_type%TYPE,
p_fare_type_rt IN favailability.fare_type%TYPE,
p_flightdate IN favailability.flight_date%TYPE,
p_flightdate_rt IN favailability.flight_date%TYPE,
p_username IN users.username%TYPE,
p_password IN users.password%TYPE,
p_card_type IN users_cc.card_type%TYPE,
p_creditcardnumber IN VARCHAR2,
p_expiry_date IN DATE,
p_first_name_add IN VARCHAR2,
p_last_name_add IN VARCHAR2);
PROCEDURE NEW_USER (p_username IN users.username%TYPE,
p_password IN users.password%TYPE,
p_salutation users.salutation%TYPE,
p_academic_title users.academic_title%TYPE,
p_first_name users.first_name%TYPE,
p_last_name users.last_name%TYPE,
p_dob users.dob%TYPE,
p_street_address users.street_address%TYPE,
p_company_name users.company_name%TYPE,
p_street_address_2 users.street_address_2%TYPE,
p_country users.country%TYPE,
p_postal_code users.postal_code%TYPE,
p_city users.city%TYPE,
p_e_mail_address users.e_mail_address%TYPE,
p_country_code users.country_code%TYPE,
p_prefix users.prefix%TYPE,
p_mobile_phone users.mobile_phone%TYPE,
p_home_phone users.home_phone%TYPE,
p_language users.language%TYPE,
p_newsletter users.newsletter%TYPE,
p_specials users.specials%TYPE,
p_membership users.membership%TYPE,
p_remarks users.remarks%TYPE);
FUNCTION VALIDATECREDITCARD (p_creditcardnumber IN VARCHAR2) RETURN VARCHAR2;
END BOOKING_PKG;Thanks for your help!
Similar Messages
-
How to create a cursor on a union select statement?
Hi,
Using Oracle 10g RAC +ASM ( RELEASE 1002000300)
What are is the proper way to create a cursor on a union select statement?
Is it possible?
code lines, Results in PLS-00201 error: sT := crsR.STATUS; sS := crsR.TIME;
Procedure listed below:
CREATE OR REPLACE PROCEDURE BUILD_SUMMARY IS
CURSOR csrO IS
SELECT
STATUS,
TIME
FROM (
SELECT
SUBSTR(DESCRIPTION,1,50) STATUS,
TO_CHAR(TIMESTAMP,'MM/DD/YY hh12:mi:ss') TIME
FROM GLOBALSALES.CUBE_STATUS
UNION ALL
SELECT
' TOTAL BUILD TIME',
TO_CHAR(TO_DATE('00:00:00','HH24:MI:SS') +(MAX(TIMESTAMP) - MIN(TIMESTAMP)), 'HH24:MI:SS')
FROM GLOBALSALES.CUBE_STATUS);
csrR csrO%ROWTYPE;
sT LONG :='';
sS LONG :='';
BEGIN
FOR csrR IN csrO
LOOP
sT := crsR.STATUS;
sS := crsR.TIME;
DBMS_OUTPUT.PUT_LINE(sT || ' ' || sS);
END LOOP;
END;
/csrR csrO%ROWTYPE;
Declares the csrR correct? Cursor Record of Cursor Object Type?That line declares one variable CSRR with your column structure described by the cursor (CSRO) type you declared above it. It means the CSRR variable has the columns you had in the SELECT statement in that cursor.
When you run a cursor as you did you don't need to declare the record variable. Try this:
CREATE OR REPLACE PROCEDURE build_summary IS
CURSOR csro IS
SELECT status, TIME
FROM (SELECT substr(description, 1, 50) status, to_char(TIMESTAMP, 'MM/DD/YY hh12:mi:ss') TIME
FROM globalsales.cube_status
UNION ALL
SELECT ' TOTAL BUILD TIME',
to_char(to_date('00:00:00', 'HH24:MI:SS') + (MAX(TIMESTAMP) - MIN(TIMESTAMP)),
'HH24:MI:SS')
FROM globalsales.cube_status);
--csrr csro%ROWTYPE;
st LONG := '';
ss LONG := '';
BEGIN
FOR csrr IN csro
LOOP
st := csrr.status;
ss := csrr.time;
dbms_output.put_line(st || ' ' || ss);
END LOOP;
END;Also why are you using LONG? It's a deprecated data type and Oracle recommends against using it. Either pick varchar2(4000) or CLOB.
DBMS_OUTPUT.PUT_LINE will implicitly convert that LONG data type anyway. -
Using ORDER BY in UNION clause in cursor
Hi Everybody,
I have one situation and i need your help guys. I have to use ORDER BY in UNION of two queries and return value in cursor.
OPEN cursor FOR
SELECT ID, DESC,SID, ITID, SID_DESC
FROM (SELECT A.ID,
A.DESC,
B.SID,
NULL AS ITID,
B.SID_DESC
FROM TABLEA A, TABLEB B
WHERE A.ID = B.ID
order by A.SORTORDER asc,B.SORTORDER)
UNION
SELECT ID, DESC, ,SID,ITID, ITID_DESCRIPTION,
FROM (SELECT A.ID,
A.DESC,
NULL AS SID,
C.ITID,
C.ITID_DESC,
FROM TABLEA A,
TABLEC C
WHERE A.ID = C.ID
order by A.SORTORDER asc,C.SORTORDER)
I SORT ORDER is column in all three tables. TABLEA has unique number for each record as sort order. TABLEB has sortorder as 1 for each id. If id is two times then its 1 and 2 for each id. TABLEC has sort order as TABLEB, 1 for each id and if id is two times then it is 1 and 2 and id id is three times, it is 1, 2, 3.
I am not getting correct sorting as i cant use order by like this in UNION. Please let me know how i can handle this.
Thank you in advance to everybody.
I will really appreciate your comments and responses.Hi,
You can use ORDER BY in a sub-query, but there's usually no point in doing so, because the super-query won't necessarily preserve that order. You need to make the columns that you want to ORDER BY available to the main query, so that they can be used there.
Try this:
SELECT ID, DESC,SID, ITID, SID_DESC
FROM (
SELECT A1.ID,
A1.DESC,
B.SID,
NULL AS ITID,
B.SID_DESC,
A1.SORTORDER AS sortorder_1
B.SORTORDER AS sortorder_2
FROM TABLEA A1,
TABLEB B
WHERE A1.ID = B.ID
UNION
SELECT A2.ID,
A2.DESC,
NULL AS SID,
C.ITID,
C.ITID_DESC,
A2.SORTORDER AS sortorder_1
B.SORTORDER AS sortorder_2
FROM TABLEA A2,
TABLEC C
WHERE A2.ID = C.ID
order by SORTORDER_1 ASC -- ASC is the default, but it doesn't hurt to say it
SORTORDER_2This assumes that tableb.sortorder and tablec.sortorder have the same, or at least similar, data types. If not, explicitly convert sortorder_1 in one branch of the UNION to the type of sortorder_2 in the other branch.
Using the same alias to mean different things in the same query is just asking for trouble. I changed the table alias a (which was used in different places to mean two different things) to A1 and A2, each of which means only one thing.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. -
How return parameter ref Cursor from procedure using dynamic SQL?
I sorry, but i very need help.
I using Oracle 8.0.6
I need to return parameter of type ref Cursor from procedure.
create or replace package PlanExp is
type cursortype is ref cursor;
procedure ShowPlan (cursorparam out
cursortype.............);
end PlanExp;
create or replace package body PlanExp is
procedure ShowPlan (cursorparam out cursortype,
.............) Is
sql_str varchar2(1000);
sql_str_select varchar2(100);
sql_str_from varchar2(100);
sql_str_where varchar2(500);
Return_Code integer;
Num_Rows integer;
cur_id_sel integer;
tSum_Plan DBMS_SQL.NUMBER_TABLE;
tSum_Plan_Ch DBMS_SQL.NUMBER_TABLE;
tSum_Plan_Day DBMS_SQL.NUMBER_TABLE;
begin
/* calculating string variables ........... /*
sql_str := 'select ' || sql_str_select ||
'from ' || sql_str_from ||
'where ' || sql_str_where ||
'group by ' || sql_str_select;
cur_id_sel := dbms_sql.open_cursor;
dbms_sql.parse(cur_id_sel, sql_str, dbms_sql.native);
dbms_sql.define_array(cur_id_sel, 1, tSum_Plan, 20, 1);
dbms_sql.define_array(cur_id_sel, 2, tSum_Plan_Ch, 20, 1);
dbms_sql.define_array(cur_id_sel, 3, tSum_Plan_Day, 20, 1);
Return_Code := dbms_sql.execute(cur_id_sel);
delete from TEMP_SHOWPLAN;
Loop
Num_Rows := dbms_sql.Fetch_Rows(cur_id_sel);
dbms_sql.column_value(cur_id_sel, 1, tSum_Plan);
dbms_sql.column_value(cur_id_sel, 2, tSum_Plan_Ch);
dbms_sql.column_value(cur_id_sel, 3, tSum_Plan_Day);
if Num_Rows = 0 then
exit;
end if;
Exit When Num_Rows < 20;
End Loop;
dbms_sql.close_cursor(cur_id_sel);
end;
end PlanExp;
How return cursor (cursorparam) from 3 dbms_sql.column_value-s ?I am using Oracle 8.1.7, so I don't know if this will work in
8.0.6 or not:
SQL> CREATE TABLE test
2 (col1 NUMBER,
3 col2 NUMBER,
4 col3 NUMBER)
5 /
Table created.
SQL> INSERT INTO test
2 VALUES (1,1,1)
3 /
1 row created.
SQL> INSERT INTO test
2 VALUES (2,2,2)
3 /
1 row created.
SQL> INSERT INTO test
2 VALUES (3,3,3)
3 /
1 row created.
SQL> CREATE TABLE temp_showplan
2 (tSum_Plan NUMBER,
3 tSum_Plan_Ch NUMBER,
4 tSum_Plan_Day NUMBER)
5 /
Table created.
SQL> EDIT planexp
CREATE OR REPLACE PACKAGE PlanExp
IS
TYPE CursorType IS REF CURSOR;
PROCEDURE ShowPlan
(cursorparam IN OUT CursorType,
sql_str_select IN VARCHAR2,
sql_str_from IN VARCHAR2,
sql_str_where IN VARCHAR2);
END PlanExp;
CREATE OR REPLACE PACKAGE BODY PlanExp
IS
PROCEDURE ShowPlan
(cursorparam IN OUT CursorType,
sql_str_select IN VARCHAR2,
sql_str_from IN VARCHAR2,
sql_str_where IN VARCHAR2)
IS
sql_str VARCHAR2 (1000);
cur_id_sel INTEGER;
return_code INTEGER;
BEGIN
DELETE FROM temp_showplan;
sql_str := 'INSERT INTO temp_showplan '
|| ' SELECT ' || sql_str_select
|| ' FROM ' || sql_str_from
|| ' WHERE ' || sql_str_where;
cur_id_sel := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (cur_id_sel, sql_str, DBMS_SQL.NATIVE);
return_code := DBMS_SQL.EXECUTE (cur_id_sel);
DBMS_SQL.CLOSE_CURSOR (cur_id_sel);
OPEN cursorparam FOR SELECT * FROM temp_showplan;
END ShowPlan;
END PlanExp;
SQL> START planexp
Package created.
Package body created.
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC PlanExp.ShowPlan (:g_ref, 'col1, col2,
col3', 'test', ' 1 = 1 ')
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
TSUM_PLAN TSUM_PLAN_CH TSUM_PLAN_DAY
1 1 1
2 2 2
3 3 3 -
How to out Dynamic ref cursor from Procedure to Forms
Hi
I am trying to out Dynamic ref cursor from Procedure to Forms, But I am unable to do so. however cursor return the value within procedure but I am failed to capture the same in Forms
Pl advice suggestion if any, Here I am attaching full procedure for reference
CREATE PACKAGE winepkg
IS
TYPE wine IS RECORD ( mynumber number);
/* Define the REF CURSOR type. */
TYPE wine_type IS REF CURSOR RETURN wine;
END winepkg;
CREATE procedure find_wine
(col1_in in number,
c1 out winepkg.wine_type) as
vsql varchar2(1000);
cur sys_refcursor;
x number;
BEGIN
vsql:='select bo_id from bo_details where bo_details.bo_id = '||col1_in ;
open cur for vsql;
c1:=cur;
--fetch c1 into x;
--dbms_output.put_line(x);
END find_wine;
In front end forms
Declare
TYPE F is REF CURSOR;
CUR_F F;
rec number;
Begin
break;
find_wine( 1601480000011078,cur_f ) ;
Loop
fetch cur_f into rec ;
Message(rec ) ;pause;
exit when cur_f%notfound ;
End loop ;
exception
when others then
Message(sqlerrm) ;pause;
End ;yo can use
declare
c_cursor EXEC_SQL.CursType;
v_stmt varchar2(2000) = 'select a, b, c from mytab where cond1'; -- you can create this value dynamically
begin
c_cursor := Exec_SQL.Open_cursor;
EXEC_SQL.PARSE(c_articulos, v_stmt);
EXEC_SQL.DEFINE_COLUMN(c_articulos,1, v_colchar1, 30);
EXEC_SQL.DEFINE_COLUMN(c_articulos,2, v_colchar2, 15);
EXEC_SQL.DEFINE_COLUMN(c_articulos,3, v_colchar3, 30);
v_exec := EXEC_SQL.EXECUTE(c_cursor);
WHILE EXEC_SQL.FETCH_ROWS(c_cursor) > 0 LOOP
EXEC_SQL.COLUMN_VALUE(c_cursor,1,v_colchar1);
EXEC_SQL.COLUMN_VALUE(c_c_cursor,2,v_colchar2);
EXEC_SQL.COLUMN_VALUE(c_c_cursor,3,v_colchar3);
assign_values_to_block;
END LOOP;
EXEC_SQL.CLOSE_CURSOR(c_cursor);
end;
and WORKS IN FORMS 6 -
hi ,
I want to privelege only Grant SELECT ALL tables,views....
I have written A procedure.....given below....
CREATE OR REPLACE PROCEDURE GRANT_SELECT_ALL_PROC
IS
l_obj VARCHAR2(60);
l_obj_type VARCHAR2(60);
CURSOR Cur_Obj IS
SELECT OBJECT_NAME,OBJECT_TYPE
FROM USER_OBJECTS
WHERE USER ='OWNER';
BEGIN
For i in Cur_Obj Loop
l_obj := i.OBJECT_NAME;
l_obj_type := i.OBJECT_TYPE;
IF l_obj_type IN ('TABLE','VIEW')
THEN
EXECUTE IMMEDIATE 'GRANT SELECT ON' || l_obj ||'TO TEMP’;
ELSIF l_obj_type IN('FUNCTION','PROCEDURE','PACKAGE') THEN
EXECUTE IMMEDIATE 'GRANT EXECUTE ON'|| l_obj ||'TO TEMP’;
END IF;
END LOOP;
END GRANT_SELECT_ALL_PROC;
procedure is working fine.....
OWNER there are some table and views......
But After creation of User name TEMp....
When I m giving GRANT SELECT to TEMP(by procedure)..... ALL tables and views of OWNER....
when I coonecte to TEMP...
Not getting table,view List...
not even data of table or Views.....
can anybdy help me.......advance thanx ...
sanjayhi ,
I want to privelege only Grant SELECT ALL
tables,views....
have written A procedure.....given below....
CREATE OR REPLACE PROCEDURE GRANT_SELECT_ALL_PROC
IS
l_obj VARCHAR2(60);
l_obj_type VARCHAR2(60);
CURSOR Cur_Obj IS
SELECT OBJECT_NAME,OBJECT_TYPE
FROM USER_OBJECTS
WHERE USER ='OWNER';
BEGIN
For i in Cur_Obj Loop
l_obj := i.OBJECT_NAME;
l_obj_type := i.OBJECT_TYPE;
IF l_obj_type IN ('TABLE','VIEW')
THEN
EXECUTE IMMEDIATE 'GRANT SELECT ON' || l_obj ||'TO
TEMP’;
ELSIF l_obj_type IN('FUNCTION','PROCEDURE','PACKAGE')
THEN
EXECUTE IMMEDIATE 'GRANT EXECUTE ON'|| l_obj ||'TO
TEMP’;
END IF;
END LOOP;
END GRANT_SELECT_ALL_PROC;
procedure is working fine.....
OWNER there are some table and views......
But After creation of User name TEMp....
When I m giving GRANT SELECT to TEMP(by
procedure)..... ALL tables and views of OWNER....
when I coonecte to TEMP...
Not getting table,view List...
not even data of table or Views.....
can anybdy help me.......advance thanx ...
sanjayQuery SELECT * FROM USER_TAB_PRIVS_MADE from the user from which you are executing the procedure
and Query SELECT * FROM USER_TAB_PRIVS_RECD from the TEMP user. -
Re-use SELECT statement in several procedures (other than copy-and-paste)
Our site uses a procedure of the following procedure construct to generate Excel spreadsheets:
TYPE retCur is REF CURSOR;
PROCEDURE get_data_for_excel (
p_filter1 VARCHAR2
,p_filter2 VARCHAR2
,c_OutCursor out retCur
IS
retCursor retcur
BEGIN
BEGIN
OPEN c_OutCursor FOR
SELECT XMLELEMENT("TR", XMLFOREST(
"col1" AS "TD"
,"col2" AS "TD"
,"col3" AS "TD"
)).getstringval()DATA FROM (SELECT * FROM
SELECT col1, col2, col3
FROM sometable
WHERE somecolumn = p_filter1
AND someothercolumn = p_filter2
) x);
END;
END get_data_for_excel
My question is, the subselect:
SELECT col1, col2, col3
FROM sometable
is used in another procedure. Is there a way to reuse the select from the other procedure into this procedure so we don't copy-and-paste each time the other procedure is changed?
Thanks a lot.This is a design decision you need to make BEFORE it goes into production.
Right now you have
procedure get_data_for_excel (
p_filter1 VARCHAR2
,p_filter2 VARCHAR2
,c_OutCursor out retCur );
What, I think jihuyao is trying to say is: convert it to a pipelined function.
I agree with jihuyao as I have ran into to this problem before.
create type d4e_t as object ( DATA xmltype);
create type d4e_table is table of d4e_t;
create or replace function get_data_for_excel (
p_filter1 VARCHAR2
,p_filter2 VARCHAR2 )
return d4e_table pipelined;
as
begin
for curr in ( --start of SELECT statement
SELECT XMLELEMENT("TR", XMLFOREST(
"col1" AS "TD"
,"col2" AS "TD"
,"col3" AS "TD"
)).getstringval()DATA FROM (SELECT * FROM
SELECT col1, col2, col3
FROM sometable
WHERE somecolumn = p_filter1
AND someothercolumn = p_filter2
) x) )
LOOP
pipe row( d4e_t( curr.data ) );
end loop;
return;
end;
From there, you use it elsewhere as if it were a table.
insert into t
select X.data from table( get_data_for_excel( l_var1, l_var2 ) ) X;
MK -
Hi,
I need to do a select within cursor, in other words, my cursor have a select from table and I want to do other select within this data. By example, my cursor have all calls but I want the calls successfully and/or the calls failure , how can to do it?
thanks by any idea.i think i have to go for two cursors Intially i have written like the below codeThis requirement merely made me think of a pure SQL solution - something interesting...
As I mentioned, you likely should be using ref cursors as typically this requirement extends to a client that wants to make a call to Oracle without needing to know SQL or table names, pass parameters, and get a dynamic "+result set+" in response.
In Oracle. this is done using ref cursors. The code will look something like this"
{code}
create or replace procedure FooProc( someVar1 varchar2, someVar2 number, curResult OUT sys_refcursor ) is
begin
case
when someVar1 = someValueA then
open curResult for select * from emp;
when someVar1 = someValueB then
open curResult for select * from emp where empid = someVar2;
.. etc ..
end case;
end;
{code}
This is pretty straight forward stuff - and well explained with examples in the Oracle® Database PL/SQL User's Guide and Reference (http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref139)
You procedure it a tad different in output parameters (and not what one typically would get in a production system), but the concept is the same. If the SQL projection is the same for each cursor, you can use a ref cursor as above - and then simply code a single fetch to get the row's columns, close the cursor, and then return that column values as output parameters.
Edited by: Billy Verreynne to fix the broken Jive s/w that does not understand how to parse a link and show it correctly.. (am getting more and more peeved at the crappiness factor of the new forum s/w) -
What is a good way to check if sql select basd cursor return anything
Hello everyone,
I am trying to find a good way to identify that a SQL select based cursor return nothing.
I know that or we use exception when no data found, or count(*) to check how many rows are returned.
I have a cursor based on quite a long select statement.
Like
CREATE OR REPLACE PROCEDURE aaa (v_input IN NUMBER, v_output OUT VARCHAR2)
CURSOR long_cursor IS
--long select statement(with input variable) ;
BEGIN
Select count(*)
Into v_count
From
-- a long select statment with input again ;
IF v_count > 0 then
For record in long_cursor loop
--Get information from cursor
--other processing for output
End loop;
END IF;
END;Is there any other way than the above ?
I would love to reduce the amount of typing. I know that repetition in code is not good.
Thanks in advance,
Ann
Edited by: Ann586341 on Feb 28, 2013 2:29 PM>
Not sure I understand your point. I am still a new bie here.
>
A flag is just a piece of data. By itself it doesn't prevent anyone from changing the data. And in a multiuser system anything you try to check is based on the COMMITTED data in the system. Two users can be changing two different rows at the same time but neither user will see the other change.
So if you try to count how many rows meet a particular condition you may get a count of 8 but after the other user commits the count might be 7 or 9. So if you use 8 it may not be valid for very long.
>
But the app we use is Oracle Application Express 4.0.
I assume when the data is read, there will be some kind of lock on these rows so other users cannot change it, right ?
Or should I use SELECT for update even I do not update anything here.
>
I can't help you with that one. That would be a question for the application express forum.
Oracle Application Express (APEX)
You don't need to use FOR UPDATE if you don't plan to change the data. But, as explained above, you can't rely on any data you query being the same because another user could be changing it while you are looking at it. -
How to return cursor from procedure to jdbc
plz help me through example of code as wl as procedure where.... return cursor from procedure to jdbc
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE procedure anil3 @count INT OUT,@opcode INT OUT,@total_tiff INT OUT
as
declare @query2 varchar(300),@tiff_count int,@query1 varchar(300)
set @query1='declare move_cursor cursor forward_only static for
select count(opcode),opcode from TABLE1 group by opcode
open move_cursor'
exec(@query1)
fetch next from move_cursor into @count,@opcode
set @opcode="'"+@opcode+"'"
set @total_tiff=0
while (@@fetch_status=0)
begin
set @query2='declare move_cursor2 cursor static for '+
' select count(tiff) from TABLE2 where opcode='+@opcode+
' open move_cursor2 '
exec(@query2)
fetch next from move_cursor2 into @tiff_count
while (@@fetch_status=0)
begin
set @total_tiff=@total_tiff+@tiff_count
fetch next from move_cursor2 into @tiff_count
end
close move_cursor2
deallocate move_cursor2
print @total_tiff
print @count
print @opcode
fetch next from move_cursor into @count,@opcode
end
close move_cursor
deallocate move_cursor
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO******************************************************************************
above this is sql server 2000 PL/SQL and i hv to get the value
print @total_tiff
print @count
print @opcode
through JDBC
plz help me out how to return Cursor to JDBC and HOW toPRINT THESE THREE VALUE @total_tiff, @count, @opcode through JDBC
get this values through JDBC -
SELECT QUERY USING STORED PROCEDURE
Hi,
I am using stored procedure in package, i need to execute select statement using
stored procedure.
regards,
p.kumaran? not framed properly i think so if u dnt mind plz check it out once
if u wnt to invoke a proc from package 2 ways r there
1) execute pac_name.proc_name[(arg_list)];
2) pl/sql
[declare]
begin
pac_name.proc_name[(arg_list)];
end;
/ -
Call the Function against a select query in 500 procedures...
Hello Gurus,
I have a scenario, where i had made one function(UDF Function) to calculate something and in every procedure i call that function and calculate my requirement.
Yesterday, i made a select query using reg exp for the same calculation..
So my question is, what should be the proper approach..
I need to implement this on 500 procedures...
And the UDF function is
CREATE OR REPLACE FUNCTION "UDF_TEXTSPLIT" (
p_list VARCHAR2,
p_del VARCHAR2 := ','
) RETURN split_tbl pipelined
IS
l_idx PLS_INTEGER;
l_list VARCHAR2(7999) ;
l_value VARCHAR2(7999);
BEGIN
l_list := p_list;
LOOP
l_idx := INSTR(l_list,p_del);
IF l_idx > 0 THEN
pipe ROW(SUBSTR(l_list,1,l_idx-1));
l_list := SUBSTR(l_list,l_idx+LENGTH(p_del));
ELSE
pipe ROW(l_list);
EXIT;
END IF;
END LOOP;
RETURN;
END Udf_Textsplit;
I have made this query:
SELECT a.b,z. b1 FROM
(SELECT ROWNUM d,REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) b
FROM (SELECT 'xxx>zzz>gg' str1 FROM dual)
CONNECT BY REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) IS NOT NULL)a,
(SELECT ROWNUM d,REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) b1
FROM (SELECT '100>500>20' str1 FROM dual)
CONNECT BY REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) IS NOT NULL)z
WHERE a.d=z.d
Do i use the same select query in all 500 procedures or call the (UDF Function) in every procedure..
So which will be faster...
Your approach would be very much appreciated...
Thanks,
Haraprasad...Hmm, do I edit 500 procedures to replace a function call with a SQL statement, or edit 1 function to use a sql statement instead of the current algorithm?
This is why we use code modules that do one thing and do it well. As long as the new version of the function takes the same arguments and returns the same results as the old, then the callers will never know that the way the function works has changed.
Whenther you put the select statement in 500 procedures, or 1 function, there will still be a context switch every time you use it. The tiny additional overhead of calling a function before the context switch would be unnoticeable.
John -
Dear All,
I got a doubt b/n select and cursor.
I read in one oracle book that select into clause will actually tries to get the data twice, Whereas the cursor will query only ones.
Is this the case in Oracle 10g or both the select and cursor will fetch the data only ones.
Ex
select sal into v_sal from emp where empno = 7788 --> Ones it hit the data, oracle will again scan the entire set of records in the emp table for another match.
Whereas
Cursor c_sal is select sal from emp where empno = 7788; --> This will do the fetch operation only ones.
Is this the case still True in Oracle 10g or 11i.
Appreciate your help.
Thankyou very much
Madhu Kthe query is processed as follows (this is from ora doc)
Parse:
– Search for identical statement
– Check syntax, object names, and privileges
– Lock objects used during parse
– Create and store execution plan
Execute: Identify rows selected
Fetch: Return rows to user process
for cursor also same things are performed, but cursor is private sql area in which you can processes one row at a time, you can use cursor in your pl/sql program and access one row a time,
so if you say,
cursor c1 is select * from emp;
c1 is private sql area where you can processes single row of emp , make comparisons, calculations etc,
once you close the cursor this area is released and can be used by another cursor,
the basic query processing rules remains the same, -
Hi all,
Given the following code :
TYPE option_rec IS RECORD
value varchar2(3),
label varchar2(255)
TYPE option_list_t IS TABLE OF option_rec;
FUNCTION get_object_list
RETURN option_list_t
PIPELINED
DETERMINISTIC
IS
tmp option_rec;
BEGIN
tmp.value:='1';
tmp.label:='foo';
PIPE ROW(tmp);
tmp.value:='2';
tmp.label:='bar';
PIPE ROW(tmp);
RETURN;
END get_object_list;
FUNCTION generate_select(selected_value in varchar2)
RETURN sys_refcursor
IS
ret sys_refcursor;
BEGIN
open ret for
select value as value,
'(' || value || ') ' || label as label,
case value
when selected_value then
'selected'
else
end as selected
from table(get_object_list);
return ret;
END generate_select;
I can't succeed in runnig this query :
select *
from cursor(generate_select('2'))I have the following error :
ORA-00933: "SQL command not properly ended"What is wrong ?
I run on Oracle 10gR2Having a pipelined function defined search documentation for TABLE operator
You must select from (TABLE(get_object_list()) where ...
Regards
Etbin
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2351
Edited by: Etbin on Apr 27, 2009 7:09 PM -
Hi,
I have a question about the best solution in selecting data from two tables and one of it is a temp table.
If ID is found on both tables, only the temp_table row should be selected. My solution looks like:
ORIG_TABLE
PK_ID
Data1
Data2
status_cd
TEMP_TABLE
PK_ID
Data1
Data2
status_cd
select data1, data2, status_cd from ORIG_TABLE
where pk_id not in (select pk_id from temp_table)
union
select data1, data2, status_cd from TEMP_TABLEI wonder if there is an easier way in selecting data like that.
Thanks ahead,
TobiasTobias Arnhold wrote:
I wonder if there is an easier way in selecting data like that.I think your current apporach is probably the best solution (You may want to replace UNION with UNION ALL though depending upon whether you expect (and need or not) duplicate records). You may want to keep an eye on the execution plan of the query using NOT IN if the temp table is a GTT (global temporary table) since maintaining statistics on a GTT can be tricky.
Edited by: user503699 on Nov 4, 2010 3:20 PM - Added comment about UNION
Maybe you are looking for
-
Two Apple ID's: Dealing With It
Here's a means to deal with the 2 Apple ID problem. It's not necessarily a solution; it's a message to Apple. Background: The old MobileMe, iTunes, and iCloud accounts do not get along. This is because iTunes used one Apple ID for purchases, and Mobi
-
My Epson wp4535 all in one will no longer scan. Where can I find an updated driver?
I have an Epson WP-4535 Workforce Pro all in one printer, scanner, fax machine. Since upgrading to mavericks the scanner will no longer work- an error message comes up to say that "you can't use this version of Epson Scan." I must need an uodated
-
Add a first page (turn page 1 into page 2 so page 1 is then blank)
Basically I have a resume created but must add a cover letter to the file. So I need to create a blank page that will be page 1.
-
"save as" won´t work
please help just downloaded the free trial of photoshop cs6 but the save as button doesn´t work everything else does.
-
Error refreshing Planning Database
Hi Friends, I am not able to refresh the database in Planning. I am getting following error at step2(Setting Locaiton Aliases) "java.lang.UnsatisfiedLinkError: no HspEssbaseOutlineAPI in java.library.path" Anyone please guide me.