简体   繁体   中英

how to call a stored procedure using table data?

i want to create a stored procedure by using below requirement.

i tried and written a stored procedure it is working fine with the static values.

how a stored procedure will work with the dynamic values.

Please find my requirement here.

 Create a stored proc “skillsparse” that accepts a string of text and and breaks it up into 1,2,3 word phrases. 

    a.       For example: I love java because it’s fun should have these 15 phrases

    i.      I
   ii.      I love
   iii.      I love java
   iv.      Love
   v.      Love java
   vi.      Love java because
   vii.      Java
   viii.      Java because
   ix.      Java because it’s
   x.      Because
   xi.      Because it’s
   xii.      Because it’s fun
   xiii.      It’s
   xiv.      It’s fun
   xv.      fun

    3.       Store these phrases in a new table called: github_skills_phrases with fields:  ID, userid, skills_id (from github_skills_source) and skills_phrase

    4.       Create a storedproc that compares the skills_phrases against the skills table (ref Table) and store the values into the github_skills table for each user. If possible, please maintain the source of where the skills came from (repodesc, repolang, starred, bio)

    5.       NOTE: Aside from the info in the new table Kishore is creating, you will also need to run the github_users.bio field against the Skillsparse procedure.  You can start this first (for testing logic, etc) since the github_users.bio already exists and has data.



    We don’t need to go this for users who have not yet been processed for skills

How i written is:

++++++++++++++++++++++++++++++++++++++++++++++++++++++
DELIMITER $$
CREATE procedure testing(IN id varchar(20),IN usr_id varchar(20),IN str varchar(200))
begin
DECLARE wordCnt varchar(20);
DECLARE wordCnt1 varchar(20);
DECLARE idx INT DEFAULT 1;
DECLARE splt varchar(200);
declare strng varchar(200);


create temporary table tmp.hello1(id varchar(200),usr_id varchar(200),st varchar(200));
set strng = str;
set wordCnt = LENGTH(trim(strng)) - LENGTH(REPLACE(trim(strng), ' ', ''))+1;
set wordCnt1 = LENGTH(trim(strng)) - LENGTH(REPLACE(trim(strng), ' ', ''))+1;

 myloop: WHILE idx <= wordCnt DO
 set splt = substring_index(trim(strng),' ',idx);
 insert into tmp.hello1 values (id,usr_id,splt);

 set idx=idx+1;
 IF idx = 4 THEN
 set strng = substring(trim(strng),length(substring_index(trim(strng),' ',1))+1);
 set idx = 1;
 set wordCnt = wordCnt -1;
 END IF;
 end while ;

 insert into tmp.hello1 values (id,usr_id,trim(substring(trim(str),length(substring_index(trim(str),' ',wordCnt1-1))+1)));
 end $$

Out put ::

 mysql> call testing('10','200','I am the my fine the kks hhh nanj kell');
Query OK, 1 row affected (0.77 sec)

mysql> select * from hello1;
+------+--------+---------------+
| id   | usr_id | st            |
+------+--------+---------------+
| 10   | 200    | I             |
| 10   | 200    | I am          |
| 10   | 200    | I am the      |
| 10   | 200    | am            |
| 10   | 200    | am the        |
| 10   | 200    | am the my     |
| 10   | 200    | the           |
| 10   | 200    | the my        |
| 10   | 200    | the my fine   |

........ .......... | 10 | 200 | kell | +------+--------+---------------+ 27 rows in set (0.00 sec)

my stored procedure is working fine with static values .how to call dynamically a stored procdure by using table data. Please help me to write a stored procedure to calling with the table data.

If you means you need to call this stored procedure inside select statement on certain data table, this is not available. You have two options: 1- transfer your procedure to function and then you can call it easily from inside the select statement. 2- write plsql code to call this procedure and you can check the below link about this point oracle call stored procedure inside select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM