Тёмный

How to return multiple values from a function in oracle pl/sql ? (without using out parameter) 

Kishan Mashru
Подписаться 9 тыс.
Просмотров 51 тыс.
50% 1

This video demonstrates how a function can return multiple values to the calling environment, but without using multiple out parameters, the video shows an example on how we can create a object, a nested table based on the object and then returning the nested table type from the function.

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@ipseetasahu9328
@ipseetasahu9328 7 лет назад
Nice explanation with Nice example 👌
@KishanMashru
@KishanMashru 7 лет назад
Thanks, I hope you have given a "like" to the video!!! Please let me know if you are looking for any specific topic, would be happy to help :)
@ipseetasahu9328
@ipseetasahu9328 7 лет назад
It will help me, if you will make a video about Ref Cursor and Dynamic sql.
@KishanMashru
@KishanMashru 7 лет назад
Sure, We have a video on Dynamic Sql, here's the link ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ExJEISDShgw.html please do like the video if you enjoy watching it, and we will shortly come up with Ref Cursors in Oracle PL/SQL. Please subscribe so that you will get a notification when we upload the video :)
@ipseetasahu9328
@ipseetasahu9328 7 лет назад
Kishan Mashru, Thank you :)
@KishanMashru
@KishanMashru 7 лет назад
here is the video on ref cursor ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-j19nfKTxMT4.html hope you enjoy it!!!
@Bendiksen4
@Bendiksen4 3 года назад
Thank you! This saved me for a final submission. Could not find a source that better clarified the topic than this
@vayunandu
@vayunandu 7 лет назад
Thank you Kishan. I just followed what you mentioned in the videos step by step. It's very clear. Just pasting what I created with bulk collect. CREATE or REPLACE TYPE emp_obj_t AS OBJECT (empno NUMBER,ename VARCHAR2(200),deptno NUMBER); CREATE OR REPLACE TYPE emp_tab_t AS TABLE OF emp_obj_t; CREATE OR REPLACE FUNCTION emp_tab RETURN emp_tab_t IS TYPE emp_rec IS RECORD (empno NUMBER,ename VARCHAR2(200),deptno NUMBER); TYPE emp_tab IS TABLE OF emp_rec; emp_blk emp_tab; emp_recs emp_tab_t; BEGIN emp_recs:=emp_tab_t(); SELECT empno,ename,deptno BULK COLLECT INTO emp_blk FROM emp; FOR i IN 1..emp_blk.count LOOP emp_recs.extend(); emp_recs(i):=emp_obj_t(emp_blk(i).empno,emp_blk(i).ename,emp_blk(i).deptno); END LOOP; RETURN emp_recs; EXCEPTION WHEN no_data_found THEN raise_application_error(-20001,'Source table is empty'); END; / SELECT * FROM TABLE(emp_tab);
@KishanMashru
@KishanMashru 7 лет назад
Good work!!! :)
@TheDMTLover
@TheDMTLover 2 года назад
Well done. Very nice.
@nileshpatil4068
@nileshpatil4068 2 года назад
Thanks Kishan, video is very informative.
@patinoricardo
@patinoricardo 4 года назад
muy bueno, excelente Kishan, gracias por compartir
@ravishettiyar3262
@ravishettiyar3262 4 года назад
Thank you so much this video is help me lot and very god example
@rameshch6903
@rameshch6903 4 года назад
Supper brother , explanation supper love it please make more videos we can learn easily 😊
@chandraneeldwaraki672
@chandraneeldwaraki672 7 лет назад
Hi Kishan. Thanks for making video and sharing it for everyone to learn. I understood returning multiple values from a procedure but I did not understand this particular video because of concepts like OBJECT TYPE, NESTED TABLE TYPE, .EXTEND() and BULK COLLECT. It is my request to make a separate video first on concepts which you have mentioned in this video like OBJECT TYPE, NESTED TABLE etc. Also are you planning to make any ORACLE PERFORMANCE TUNING videos where you explain about different concepts like EXPLAIN PLAN, ORACLE HINTS etc. It would be very helpful if you make a series about ORACLE PERFORMANCE TUNING. Again many thanks for your efforts.
@KishanMashru
@KishanMashru 7 лет назад
Ya if you are new to Nested Tables and Bulk Collect this video will be a bit complicated to understand, I will make a Video series on Oracle Collections and before that will make few videos on performance tuning !!!
@chandraneeldwaraki672
@chandraneeldwaraki672 7 лет назад
Thanks Kishan.. Will be looking forward to your videos..
@akashjain135
@akashjain135 5 лет назад
Watch Steven Feurenstein's video series on PLSQL Collections.
@shyamkollimarla1384
@shyamkollimarla1384 6 лет назад
Really Good help and for fresher really good help & Inputs
@KishanMashru
@KishanMashru 6 лет назад
Thanks Shyam, I am glad you enjoyed it :) Hope you have liked the video and subscribed to our channel!!!
@sateeshbabu5792
@sateeshbabu5792 7 лет назад
Nice explanation, i am expecting more videos on plsql collections Thanks kishan
@nileshpatil4068
@nileshpatil4068 2 года назад
Thanks!
@SujitKumar-wg7sz
@SujitKumar-wg7sz 7 лет назад
Kindly share always queries whatever you use so that we could replicate same for better understanding...Great Explanations
@KishanMashru
@KishanMashru 7 лет назад
Ya, will be posting them on my blog soon :) thanks for the comment, hope you have subscribed to our channel and given the video a "thumbs up" !!!
@SujitKumar-wg7sz
@SujitKumar-wg7sz 7 лет назад
Thanks..
@bowser9775
@bowser9775 5 лет назад
Thank you very much. Really good explanations
@tejujagadale7458
@tejujagadale7458 6 лет назад
its too nice explanation.....
@KishanMashru
@KishanMashru 6 лет назад
Thanks Teju!!! Hope you have liked the video and subscribed to our channel!!!
@chandraneeldwaraki672
@chandraneeldwaraki672 7 лет назад
Hi Kishan, Great explanation. Thanks. I had 1 query regarding BULK COLLECT method you have used I tried the statement: SELECT FIRST_NAME,LAST_NAME,DEPARTMENT_NAME BULK COLLECT INTO....... instead of using EMP_OBJ_TYPE(FIRST_NAME,LAST_NAME,DEPARTMENT_NAME) BULK COLLECT INTO... The first statement throws compilation error while creating function. Can you please explain why passing it as OBJ_TYPE is mandatory and why oracle throws error for normal SELECT INTO. Thanks.
@akashjain135
@akashjain135 5 лет назад
The collection in which you are fetching the 3 attributes is EMP_DETAILS. Now, EMP_DETAILS is of table type EMP_TBL_TYPE. Each row of EMP_TBL_TYPE consists of the object type EMP_OBJ_TYPE. So while populating the table type , you need to write something like below:- EMP_DETAILS(1) := EMP_OBJ_TYPE(attribute1,attribute2,attribute3); Similarly while bulk collecting into the EMP_DETAILS you need to use EMP_OBJ_TYPE(attribute1,attribute2,attribute3).
@Vathananable
@Vathananable 5 лет назад
Is this the same when you do with create or replace type body with member function?
@milindbidve446
@milindbidve446 5 лет назад
Nice video. Can you please create a video on pipelined functions having pipe row? Thanks.
@rajvizag6757
@rajvizag6757 7 лет назад
Explantion is very good. Please take care of Video Quality:)
@KishanMashru
@KishanMashru 7 лет назад
Thanks Raj :) Hope you have subscribed to the channel and liked the video!!!
@rajvizag6757
@rajvizag6757 7 лет назад
Yess!!! Keep Going ! Good luck.
@ramramaraju2221
@ramramaraju2221 5 лет назад
Thanks Kishan :)
@KishanMashru
@KishanMashru 5 лет назад
Welcome!!!
@rishinigam8773
@rishinigam8773 5 лет назад
I need to do the same thing but in a procedure, is there anyway to pass my function into a procedure to display.
@KishanMashru
@KishanMashru 5 лет назад
A better option would be to use sys_refcursors. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-j19nfKTxMT4.html
@shrikantpatil2094
@shrikantpatil2094 7 лет назад
it's pretty good. pls also explain through blog.
@TheSoulamimukherjee
@TheSoulamimukherjee 7 лет назад
So in order to return multiple values from a function. Only to make an object is the only option? Or having multiple out parameters will also do. I mean both the options would work?
@KishanMashru
@KishanMashru 6 лет назад
good question, you are kind of right. See its all abt the requirement if you have a single records but multiple values to be returned from a function like id, name for a SINGLE employee you can simply do it with multiple out parameters, but when you need to return MULTIPLE rows containing id and name for a bunch of employee you would need the object based shown in d video. Hope this helps.
@TheSoulamimukherjee
@TheSoulamimukherjee 6 лет назад
Kishan Mashru yes that was helpful. So in order to return multiple values I can use multiple out parameters. So If i need to return empid ename n salary. Write it in the same way like a procedure
@KishanMashru
@KishanMashru 6 лет назад
yup, you will get the values in your out params, make sure you handle/sync them properly with the return statement of the function.
@TheSoulamimukherjee
@TheSoulamimukherjee 6 лет назад
Kishan Mashru okay krishna. So it will be e.g emp id , ename n address Then return varchar2 is V_empid varchar2(100), V_ename varchar2(20), V_addr varchar2 (30) Like this?
@KishanMashru
@KishanMashru 6 лет назад
CASE STUDY -- DROP THE TABLE, IF EXISTS DROP TABLE TEST_EMP; -- CREAT ETABLE CREATE TABLE TEST_EMP ( EMP_ID NUMBER, EMP_NAME VARCHAR2(30), DEPT NUMBER ); -- INSERT DATA INSERT INTO TEST_EMP VALUES (1, 'KISHAN',10); INSERT INTO TEST_EMP VALUES (2, 'MASHRU',20); -- COMMIT DATA COMMIT; -- FUNCTION CREATE OR REPLACE FUNCTION GET_NAME_DEPT (F_ID NUMBER, F_NAME OUT VARCHAR2, F_DEPT OUT VARCHAR2) RETURN NUMBER IS BEGIN SELECT EMP_NAME, DEPT INTO F_NAME, F_DEPT FROM TEST_EMP WHERE EMP_ID = F_ID; RETURN F_ID; END; / --EXEC TEST DECLARE FUNC_OUTPUT NUMBER; FUNC_NAME VARCHAR2(50); FUNC_DEPT VARCHAR2(50); BEGIN FUNC_OUTPUT := GET_NAME_DEPT(1,FUNC_NAME,FUNC_DEPT); DBMS_OUTPUT.PUT_LINE('FUNCTION OUTPUT : '||FUNC_OUTPUT||' NAME : '||FUNC_NAME||' DEPT : '||FUNC_DEPT); END; / -- OUTPUT -- FUNCTION OUTPUT : 1 NAME : KISHAN DEPT : 10
@NewZenContent
@NewZenContent 5 лет назад
Thank you Kishan :D
@visakviz4690
@visakviz4690 5 лет назад
well explained..
@parthparth8680
@parthparth8680 3 года назад
WHICH WAY TO DELETE RECORD STORED IN NESTED TABLE
@parthparth8680
@parthparth8680 3 года назад
very nice video but where can we use objects
@poornimas620
@poornimas620 4 года назад
Does it work for insert and update also
@abderrahimhaddadi4023
@abderrahimhaddadi4023 4 года назад
Good content.. Do you have an idea how can i work with the same function in java ??
@KishanMashru
@KishanMashru 4 года назад
Create a connection to the database and invoke the function!!!
@abderrahimhaddadi4023
@abderrahimhaddadi4023 4 года назад
@@KishanMashru Yes, about invoking the function, what should be the return type ? there's a trick (types.ARRAY, ''nestedtableType') , but I still dont know how to retrieve the data. I would be very grateful if you help me with this Kishan !!
@mahendrababu5516
@mahendrababu5516 6 лет назад
Why can’t we use a sys_ref cursor?
@akankshawakhure9402
@akankshawakhure9402 Год назад
It's giving me empty table
@aruljebin
@aruljebin 6 лет назад
No need for nested table. As you are returning only one record you can declare as record is enough.
@paladugulasudha2016
@paladugulasudha2016 7 лет назад
Nice explanation but maintain screen quality while explain the program
@KishanMashru
@KishanMashru 7 лет назад
sure!!! Thank you :)
@ramyalakshmi5594
@ramyalakshmi5594 3 года назад
Write a function to return the name of the student whose mark is maximum
@aravindmadurai9743
@aravindmadurai9743 7 лет назад
confusing brother :(
@KishanMashru
@KishanMashru 7 лет назад
which part? try this one out ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-zVs9fKSc-7M.html
Далее
HOW TO REPLACE NULL VALUE IN ORACLE SQL?
6:25
Просмотров 5 тыс.
Difference between Case and Decode
10:14
Просмотров 22 тыс.
Аруси Точики ❤️❤️❤️
00:13
Просмотров 414 тыс.
Fake watermelon by Secret Vlog
00:16
Просмотров 8 млн
FUNCTIONS IN ORACLE PL/SQL (basic to advance examples)
19:50
Collections in Oracle PLSQL
13:29
Просмотров 62 тыс.
Аруси Точики ❤️❤️❤️
00:13
Просмотров 414 тыс.