Bonjour à tous,
J'ai besoin d'aide , je dois créer une SP en mysql 5.1
voici le message du demandeur:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is myisam table customer on offer warehouse offer_{country}_production
We need a procedure that will accept the fields from customer and do something like:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;
columns list is:
+-------------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+------------------+------+-----+---------+-------+
| customer_id | int(10) unsigned | NO | PRI | NULL | |
| name | varchar(255) | NO | | NULL | |
| url | varchar(255) | NO | | NULL | |
| type | int(10) | NO | | NULL | |
| costperclick | decimal(10,3) | NO | | NULL | |
| priority | int(10) | NO | | NULL | |
| status | int(10) | NO | | NULL | |
| imported | datetime | YES | | NULL | |
| product_id | int(10) unsigned | YES | | NULL | |
| category_count | int(10) unsigned | NO | | 0 | |
| mapping_count | int(10) unsigned | NO | | 0 | |
| mapped_categories_count | int(10) unsigned | NO | | 0 | |
+-------------------------+------------------+------+-----+---------+-------+
Od duplicate key update values:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 INSERT INTO `customer` (`customer_id`,`name`,`url`,`type`,`costperclick`,`priority`,`status`,`product_id`) VALUES (5036517,'camera-accushop.nl','http://www.camera-accushop.nl/',2,0.16,300,0,2344415) ON DUPLICATE KEY UPDATE `name`='camera-accushop.nl',`url`='http://www.camera-accushop.nl/',`type`=2,`costperclick`=0.16,`priority`=300,`status`=0,`product_id`=2344415,`customer_id`=5036517
--------------------
J'ai commencé comme ça: mais je suis débutant , merci de votre indulgence
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 USE offer_es_production; DROP PROCEDURE IF EXISTS `sp_insert_customer` GO CREATE PROCEDURE sp_insert_customer ( IN customer_id INT(10) UNSIGNED , IN type INT(10) , IN costperclick DECIMAL(10,3) , IN priority INT(10) , IN status INT(10) , IN product_id INT(10) UNSIGNED ) BEGIN INSERT INTO customer (customer_id, type, costperclick, priority, status, product_id) VALUES (p_customer_id, p_type, p_costperclick, p_priority, p_status, p_product_id) ON DUPLICATE KEY UPDATE c=c+1; END
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Voilà, merci à vous pour votre aide !
Partager