Reputation: 518
I've been looking into storing a query into a variable but I am having trouble doing so. I keep getting the error
wrong number or types of arguments in call to '||'
This is what I tried
DECLARE
addresses VARCHAR(200);
CURSOR allAddresses IS
SELECT *
FROM ALL_ADDRESS;
BEGIN
FOR rec IN allAddresses LOOP
addresses := addresses || rec;
END LOOP;
DBMS_OUTPUT.PUT_LINE(addresses);
END;
Upvotes: 1
Views: 77
Reputation: 145
For this scenario you should understand cursor variable calling things:
DECLARE
addresses VARCHAR(200);
CURSOR allAddresses IS
SELECT *
FROM ALL_ADDRESS;
BEGIN
FOR rec IN allAddresses LOOP
addresses := addresses || rec.a; -- A as attribute of your cursor
--- so your need to access your cursor attribute using loop name i.e rec
END LOOP;
DBMS_OUTPUT.PUT_LINE(addresses);
END;
/
whenever you are trying to access your cursor record, you should call cursor variable before the attribute. Hope it will help you.. thank you
Upvotes: 2
Reputation: 31648
You cannot use a CURSOR for loop
iterator directly in your expressions.You can only refer to the column names as rec.col1
, rec.col2
..etc
DECLARE
addresses VARCHAR(200);
CURSOR allAddresses IS
SELECT *
FROM ALL_ADDRESS;
BEGIN
FOR rec IN allAddresses LOOP
addresses := addresses || rec.<address_column>;
END LOOP;
DBMS_OUTPUT.PUT_LINE(addresses);
END;
Upvotes: 2
Reputation: 167867
You refer to the columns in the record rec
that you are using by name:
DECLARE
addresses VARCHAR(200);
CURSOR allAddresses IS
SELECT *
FROM ALL_ADDRESS;
BEGIN
FOR rec IN allAddresses LOOP
addresses := addresses || rec.house_number
|| ' ' || rec.house_name
|| ' ' || rec.address1
|| ' ' || rec.address2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(addresses);
END;
/
Upvotes: 3