How to display cursor in procedure?Insert results of a stored procedure into a temporary tablehow to write a pl/sql code block that prints out contents of cursor that is out parameter from stored procFunction vs. Stored Procedure in SQL ServerOracle - select a specific column from a ref cursorhow to fetch cursor value into varchar2 in pl/sqlCursor in procedure returning more values than queryNot understanding cursorHow to get data in grid view from procedure returning multiple rows in ref cursorSpringboot java oracle procedure calling with cursorloop is not running for Cursor in the stored procedure
If I have the War Caster feat, can I use the Thorn Whip cantrip to stop an enemy caster from escaping using the Dimension Door spell?
Why can't you move another user's directory when you can move their file?
A quine of sorts
How can I know if a PDF file was created via LaTeX or XeLaTeX?
Quantum jump/leap, exist or not, and instantaneous or not (for electrons)?
I just started should I accept a farewell lunch for a coworker I don't know?
Checkmate in 1 on a Tangled Board
Why wasn't EBCDIC designed with contiguous alphanumeric characters?
Sharing referee/AE report online to point out a grievous error in refereeing
Fully submerged water bath for stove top baking?
Converting Geographic Coordinates into Lambert2008 coordinates
Translation of the Sator Square
Put my student loan in parents’ second mortgage - help?
What happens if a caster is surprised while casting a spell with a long casting time?
Cooking a nice pan seared steak for picky eaters
Adjective for 'made of pus' or 'corrupted by pus' or something of something of pus
Losing the queen and then winning the game
Why were the first airplanes "backwards"?
What is the Japanese name for the conventional shoelace knot?
How can I deal with extreme temperatures in a hotel room?
If I were to build a J3 cub twice the size of the original using the same CG would it fly?
Bin Packing with Relational Penalization
Why does my air conditioning feel weak during the day, but strong in the evening?
Journal standards vs. personal standards
How to display cursor in procedure?
Insert results of a stored procedure into a temporary tablehow to write a pl/sql code block that prints out contents of cursor that is out parameter from stored procFunction vs. Stored Procedure in SQL ServerOracle - select a specific column from a ref cursorhow to fetch cursor value into varchar2 in pl/sqlCursor in procedure returning more values than queryNot understanding cursorHow to get data in grid view from procedure returning multiple rows in ref cursorSpringboot java oracle procedure calling with cursorloop is not running for Cursor in the stored procedure
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have to display name and surname of everyone from team that have the same manager(his name and surname taken from parameter).
I tried 'IN' before VARCHAR2. I did use set serveroutput on.
Furthermore select from cursor separately is working.
CREATE OR REPLACE PROCEDURE ex_2h(nazw VARCHAR2, imi VARCHAR2)
IS
CURSOR team IS SELECT * FROM people p WHERE p.id_manager=
(SELECT id_ppl FROM people WHERE name= imi AND surname=nazw);
tmp people%ROWTYPE;
BEGIN
OPEN team;
LOOP
FETCH team INTO tmp;
EXIT WHEN team%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(NVL(tmp.name, '?'));
END LOOP;
CLOSE team;
END;
I don't know why without parameters it is working but if I add these the cursor is empty and it does not show anything.
oracle stored-procedures plsql cursor
add a comment |
I have to display name and surname of everyone from team that have the same manager(his name and surname taken from parameter).
I tried 'IN' before VARCHAR2. I did use set serveroutput on.
Furthermore select from cursor separately is working.
CREATE OR REPLACE PROCEDURE ex_2h(nazw VARCHAR2, imi VARCHAR2)
IS
CURSOR team IS SELECT * FROM people p WHERE p.id_manager=
(SELECT id_ppl FROM people WHERE name= imi AND surname=nazw);
tmp people%ROWTYPE;
BEGIN
OPEN team;
LOOP
FETCH team INTO tmp;
EXIT WHEN team%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(NVL(tmp.name, '?'));
END LOOP;
CLOSE team;
END;
I don't know why without parameters it is working but if I add these the cursor is empty and it does not show anything.
oracle stored-procedures plsql cursor
Tested, except thiszespol
/team
issue it works. Maybe you called it asex_2h('Franciszek', 'Smuda')
instead ofex_2h('Smuda', 'Franciszek')
?;
– Ponder Stibbons
Mar 25 at 15:37
Problem solved, thank you for advice, but it was some problem with sql developer. Explenation below.
– Beata Kozieł
Mar 25 at 21:45
add a comment |
I have to display name and surname of everyone from team that have the same manager(his name and surname taken from parameter).
I tried 'IN' before VARCHAR2. I did use set serveroutput on.
Furthermore select from cursor separately is working.
CREATE OR REPLACE PROCEDURE ex_2h(nazw VARCHAR2, imi VARCHAR2)
IS
CURSOR team IS SELECT * FROM people p WHERE p.id_manager=
(SELECT id_ppl FROM people WHERE name= imi AND surname=nazw);
tmp people%ROWTYPE;
BEGIN
OPEN team;
LOOP
FETCH team INTO tmp;
EXIT WHEN team%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(NVL(tmp.name, '?'));
END LOOP;
CLOSE team;
END;
I don't know why without parameters it is working but if I add these the cursor is empty and it does not show anything.
oracle stored-procedures plsql cursor
I have to display name and surname of everyone from team that have the same manager(his name and surname taken from parameter).
I tried 'IN' before VARCHAR2. I did use set serveroutput on.
Furthermore select from cursor separately is working.
CREATE OR REPLACE PROCEDURE ex_2h(nazw VARCHAR2, imi VARCHAR2)
IS
CURSOR team IS SELECT * FROM people p WHERE p.id_manager=
(SELECT id_ppl FROM people WHERE name= imi AND surname=nazw);
tmp people%ROWTYPE;
BEGIN
OPEN team;
LOOP
FETCH team INTO tmp;
EXIT WHEN team%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(NVL(tmp.name, '?'));
END LOOP;
CLOSE team;
END;
I don't know why without parameters it is working but if I add these the cursor is empty and it does not show anything.
oracle stored-procedures plsql cursor
oracle stored-procedures plsql cursor
edited Mar 25 at 21:44
Beata Kozieł
asked Mar 25 at 14:54
Beata KoziełBeata Kozieł
12 bronze badges
12 bronze badges
Tested, except thiszespol
/team
issue it works. Maybe you called it asex_2h('Franciszek', 'Smuda')
instead ofex_2h('Smuda', 'Franciszek')
?;
– Ponder Stibbons
Mar 25 at 15:37
Problem solved, thank you for advice, but it was some problem with sql developer. Explenation below.
– Beata Kozieł
Mar 25 at 21:45
add a comment |
Tested, except thiszespol
/team
issue it works. Maybe you called it asex_2h('Franciszek', 'Smuda')
instead ofex_2h('Smuda', 'Franciszek')
?;
– Ponder Stibbons
Mar 25 at 15:37
Problem solved, thank you for advice, but it was some problem with sql developer. Explenation below.
– Beata Kozieł
Mar 25 at 21:45
Tested, except this
zespol
/team
issue it works. Maybe you called it as ex_2h('Franciszek', 'Smuda')
instead of ex_2h('Smuda', 'Franciszek')
?;– Ponder Stibbons
Mar 25 at 15:37
Tested, except this
zespol
/team
issue it works. Maybe you called it as ex_2h('Franciszek', 'Smuda')
instead of ex_2h('Smuda', 'Franciszek')
?;– Ponder Stibbons
Mar 25 at 15:37
Problem solved, thank you for advice, but it was some problem with sql developer. Explenation below.
– Beata Kozieł
Mar 25 at 21:45
Problem solved, thank you for advice, but it was some problem with sql developer. Explenation below.
– Beata Kozieł
Mar 25 at 21:45
add a comment |
1 Answer
1
active
oldest
votes
Who knows? The procedure itself looks OK (apart from the fact that you opened the TEAM cursor and fetched from ZESPOL (which was never declared).
- may be the letter case (are those names written in lower/upper/mixed case)?
- are you confused by parameters' order? Surname first, the first name next? Should it be vice versa (i.e.
imi VARCHAR2, nazw VARCHAR2
)
always use aliases, especially when you use the same table twice (or more times)
Here's a test case which shows that it works if you use it correctly. Note that I've switched to cursor FOR loop which is easier to maintain.
SQL> create table people
2 (id_ppl number,
3 name varchar2(10),
4 surname varchar2(10),
5 id_manager number);
Table created.
SQL> insert all
2 into people values (1, 'Little', 'Foot', 1) --> the same ...
3 into people values (2, 'Big' , 'Foot', 1) --> ... manager
4 into people values (3, 'Stack' , 'Over', 2)
5 select * from dual;
3 rows created.
SQL> set serveroutput on;
The procedure:
SQL> create or replace procedure ex_2h (p_nazw in varchar2, p_imi in varchar2)
2 is
3 begin
4 for tmp in (select p.name from people p
5 where p.id_manager = (select p1.id_ppl
6 from people p1
7 where p1.name = p_imi
8 and p1.surname = p_nazw
9 )
10 )
11 loop
12 dbms_output.put_line(nvl(tmp.name, '?'));
13 end loop;
14 end;
15 /
Procedure created.
Testing:
SQL> exec ex_2h('Foot', 'Little');
Little
Big
PL/SQL procedure successfully completed.
SQL>
I suggest you to try it that way. If it doesn't work, please, post some more info - CREATE TABLE and sample data so that we could see what you really have and how Oracle responded (and why).
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340612%2fhow-to-display-cursor-in-procedure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Who knows? The procedure itself looks OK (apart from the fact that you opened the TEAM cursor and fetched from ZESPOL (which was never declared).
- may be the letter case (are those names written in lower/upper/mixed case)?
- are you confused by parameters' order? Surname first, the first name next? Should it be vice versa (i.e.
imi VARCHAR2, nazw VARCHAR2
)
always use aliases, especially when you use the same table twice (or more times)
Here's a test case which shows that it works if you use it correctly. Note that I've switched to cursor FOR loop which is easier to maintain.
SQL> create table people
2 (id_ppl number,
3 name varchar2(10),
4 surname varchar2(10),
5 id_manager number);
Table created.
SQL> insert all
2 into people values (1, 'Little', 'Foot', 1) --> the same ...
3 into people values (2, 'Big' , 'Foot', 1) --> ... manager
4 into people values (3, 'Stack' , 'Over', 2)
5 select * from dual;
3 rows created.
SQL> set serveroutput on;
The procedure:
SQL> create or replace procedure ex_2h (p_nazw in varchar2, p_imi in varchar2)
2 is
3 begin
4 for tmp in (select p.name from people p
5 where p.id_manager = (select p1.id_ppl
6 from people p1
7 where p1.name = p_imi
8 and p1.surname = p_nazw
9 )
10 )
11 loop
12 dbms_output.put_line(nvl(tmp.name, '?'));
13 end loop;
14 end;
15 /
Procedure created.
Testing:
SQL> exec ex_2h('Foot', 'Little');
Little
Big
PL/SQL procedure successfully completed.
SQL>
I suggest you to try it that way. If it doesn't work, please, post some more info - CREATE TABLE and sample data so that we could see what you really have and how Oracle responded (and why).
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
add a comment |
Who knows? The procedure itself looks OK (apart from the fact that you opened the TEAM cursor and fetched from ZESPOL (which was never declared).
- may be the letter case (are those names written in lower/upper/mixed case)?
- are you confused by parameters' order? Surname first, the first name next? Should it be vice versa (i.e.
imi VARCHAR2, nazw VARCHAR2
)
always use aliases, especially when you use the same table twice (or more times)
Here's a test case which shows that it works if you use it correctly. Note that I've switched to cursor FOR loop which is easier to maintain.
SQL> create table people
2 (id_ppl number,
3 name varchar2(10),
4 surname varchar2(10),
5 id_manager number);
Table created.
SQL> insert all
2 into people values (1, 'Little', 'Foot', 1) --> the same ...
3 into people values (2, 'Big' , 'Foot', 1) --> ... manager
4 into people values (3, 'Stack' , 'Over', 2)
5 select * from dual;
3 rows created.
SQL> set serveroutput on;
The procedure:
SQL> create or replace procedure ex_2h (p_nazw in varchar2, p_imi in varchar2)
2 is
3 begin
4 for tmp in (select p.name from people p
5 where p.id_manager = (select p1.id_ppl
6 from people p1
7 where p1.name = p_imi
8 and p1.surname = p_nazw
9 )
10 )
11 loop
12 dbms_output.put_line(nvl(tmp.name, '?'));
13 end loop;
14 end;
15 /
Procedure created.
Testing:
SQL> exec ex_2h('Foot', 'Little');
Little
Big
PL/SQL procedure successfully completed.
SQL>
I suggest you to try it that way. If it doesn't work, please, post some more info - CREATE TABLE and sample data so that we could see what you really have and how Oracle responded (and why).
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
add a comment |
Who knows? The procedure itself looks OK (apart from the fact that you opened the TEAM cursor and fetched from ZESPOL (which was never declared).
- may be the letter case (are those names written in lower/upper/mixed case)?
- are you confused by parameters' order? Surname first, the first name next? Should it be vice versa (i.e.
imi VARCHAR2, nazw VARCHAR2
)
always use aliases, especially when you use the same table twice (or more times)
Here's a test case which shows that it works if you use it correctly. Note that I've switched to cursor FOR loop which is easier to maintain.
SQL> create table people
2 (id_ppl number,
3 name varchar2(10),
4 surname varchar2(10),
5 id_manager number);
Table created.
SQL> insert all
2 into people values (1, 'Little', 'Foot', 1) --> the same ...
3 into people values (2, 'Big' , 'Foot', 1) --> ... manager
4 into people values (3, 'Stack' , 'Over', 2)
5 select * from dual;
3 rows created.
SQL> set serveroutput on;
The procedure:
SQL> create or replace procedure ex_2h (p_nazw in varchar2, p_imi in varchar2)
2 is
3 begin
4 for tmp in (select p.name from people p
5 where p.id_manager = (select p1.id_ppl
6 from people p1
7 where p1.name = p_imi
8 and p1.surname = p_nazw
9 )
10 )
11 loop
12 dbms_output.put_line(nvl(tmp.name, '?'));
13 end loop;
14 end;
15 /
Procedure created.
Testing:
SQL> exec ex_2h('Foot', 'Little');
Little
Big
PL/SQL procedure successfully completed.
SQL>
I suggest you to try it that way. If it doesn't work, please, post some more info - CREATE TABLE and sample data so that we could see what you really have and how Oracle responded (and why).
Who knows? The procedure itself looks OK (apart from the fact that you opened the TEAM cursor and fetched from ZESPOL (which was never declared).
- may be the letter case (are those names written in lower/upper/mixed case)?
- are you confused by parameters' order? Surname first, the first name next? Should it be vice versa (i.e.
imi VARCHAR2, nazw VARCHAR2
)
always use aliases, especially when you use the same table twice (or more times)
Here's a test case which shows that it works if you use it correctly. Note that I've switched to cursor FOR loop which is easier to maintain.
SQL> create table people
2 (id_ppl number,
3 name varchar2(10),
4 surname varchar2(10),
5 id_manager number);
Table created.
SQL> insert all
2 into people values (1, 'Little', 'Foot', 1) --> the same ...
3 into people values (2, 'Big' , 'Foot', 1) --> ... manager
4 into people values (3, 'Stack' , 'Over', 2)
5 select * from dual;
3 rows created.
SQL> set serveroutput on;
The procedure:
SQL> create or replace procedure ex_2h (p_nazw in varchar2, p_imi in varchar2)
2 is
3 begin
4 for tmp in (select p.name from people p
5 where p.id_manager = (select p1.id_ppl
6 from people p1
7 where p1.name = p_imi
8 and p1.surname = p_nazw
9 )
10 )
11 loop
12 dbms_output.put_line(nvl(tmp.name, '?'));
13 end loop;
14 end;
15 /
Procedure created.
Testing:
SQL> exec ex_2h('Foot', 'Little');
Little
Big
PL/SQL procedure successfully completed.
SQL>
I suggest you to try it that way. If it doesn't work, please, post some more info - CREATE TABLE and sample data so that we could see what you really have and how Oracle responded (and why).
answered Mar 25 at 15:21
LittlefootLittlefoot
29.9k7 gold badges17 silver badges34 bronze badges
29.9k7 gold badges17 silver badges34 bronze badges
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
add a comment |
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
My colleague send me this procedure using for loop and it worked and then I compiled again and it also was ok... I just spent one day on this meh
– Beata Kozieł
Mar 25 at 16:21
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Does it mean that the problem is now solved?
– Littlefoot
Mar 25 at 16:23
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
Yes it is working now
– Beata Kozieł
Mar 25 at 17:59
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
OK, I'm glad you made it work.
– Littlefoot
Mar 25 at 18:22
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
Thanks a lot anyway.
– Beata Kozieł
Mar 25 at 21:43
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340612%2fhow-to-display-cursor-in-procedure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Tested, except this
zespol
/team
issue it works. Maybe you called it asex_2h('Franciszek', 'Smuda')
instead ofex_2h('Smuda', 'Franciszek')
?;– Ponder Stibbons
Mar 25 at 15:37
Problem solved, thank you for advice, but it was some problem with sql developer. Explenation below.
– Beata Kozieł
Mar 25 at 21:45