简体   繁体   English

如何使用表数据调用存储过程?

[英]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 | 10 | 200 | 200 | kell | 凯尔 +------+--------+---------------+ 27 rows in set (0.00 sec) + ------ + -------- + --------------- +设置27行(0.00秒)

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. 如果您表示需要在某些数据表的select语句内调用此存储过程,则此功能不可用。 You have two options: 1- transfer your procedure to function and then you can call it easily from inside the select statement. 您有两个选择:1-将过程转移到函数中,然后可以从select语句内部轻松调用它。 2- write plsql code to call this procedure and you can check the below link about this point oracle call stored procedure inside select 2-编写plsql代码来调用此过程,您可以在select内检查以下有关此点的oracle调用存储过程的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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