IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Requêtes MySQL Discussion :

Remplacer chaine entre parenthèses dans un champ


Sujet :

Requêtes MySQL

  1. #1
    Membre à l'essai
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Août 2013
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Alimentation

    Informations forums :
    Inscription : Août 2013
    Messages : 41
    Points : 15
    Points
    15
    Par défaut Remplacer chaine entre parenthèses dans un champ
    Bonjour à tous,

    Je m'explique...
    J'ai un champ TEXT qui comprend plusieurs valeurs séparées par un trait d'union.
    Lors d'un select, j'ai besoin de ressortir les résultats sans la valeur située entre parenthèses.
    Ex :
    champ='-Room 1-Room 2(18:00:00)-Room 3(12:00:00)-Villa 4(13:30)'
    et j'ai besoin de faire un select en ayant mon champ like %-Room 2-%

    Comme vous pouvez le voir mon champ entre parenthèses diffère, ainsi que la longueur de la chaine située avant.

    Me suis-je bien fait comprendre ?

    Merci d'avance à tous les spécialistes MySQL ;-)

  2. #2
    Expert éminent sénior Avatar de Artemus24
    Homme Profil pro
    Agent secret au service du président Ulysses S. Grant !
    Inscrit en
    Février 2011
    Messages
    6 346
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Agent secret au service du président Ulysses S. Grant !
    Secteur : Finance

    Informations forums :
    Inscription : Février 2011
    Messages : 6 346
    Points : 18 959
    Points
    18 959
    Par défaut
    Salut slimshady2878.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    --------------
    select REGEXP_REPLACE('-Room 1-Room 2(18:00:00)-Room 3(12:00:00)-Villa 4(13:30)','[(][0-9:]*[)]','') as expr
    --------------
     
    +-------------------------------+
    | expr                          |
    +-------------------------------+
    | -Room 1-Room 2-Room 3-Villa 4 |
    +-------------------------------+
     
    Appuyez sur une touche pour continuer...
    @+
    Si vous êtes de mon aide, vous pouvez cliquer sur .
    Mon site : http://www.jcz.fr

  3. #3
    Membre à l'essai
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Août 2013
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Alimentation

    Informations forums :
    Inscription : Août 2013
    Messages : 41
    Points : 15
    Points
    15
    Par défaut Merci
    Merci Artemus,

    Mais ça marche pô...

    Voilà ma requête:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    SELECT intervention_date as last_intervention,type, custom_add, confirmed FROM interventions WHERE (id_customer='100'
     and REGEXP_REPLACE(recommendations,'[(][0-9:]*[)]','') like '%CONDOMINIO 2%' and deleted=0)
     and intervention_date< '2018-12-08 00:00:00'
     ORDER BY intervention_date DESC LIMIT 0,1
    et le message :
    #1305 - FUNCTION crm_inguzweb.REGEXP_REPLACE does not exist

  4. #4
    Expert éminent sénior Avatar de Artemus24
    Homme Profil pro
    Agent secret au service du président Ulysses S. Grant !
    Inscrit en
    Février 2011
    Messages
    6 346
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Agent secret au service du président Ulysses S. Grant !
    Secteur : Finance

    Informations forums :
    Inscription : Février 2011
    Messages : 6 346
    Points : 18 959
    Points
    18 959
    Par défaut
    Salut slimshady2878.

    Quelle est la version MySql que vous utilisez ?

    @+
    Si vous êtes de mon aide, vous pouvez cliquer sur .
    Mon site : http://www.jcz.fr

  5. #5
    Membre à l'essai
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Août 2013
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Alimentation

    Informations forums :
    Inscription : Août 2013
    Messages : 41
    Points : 15
    Points
    15
    Par défaut
    5.5.60

  6. #6
    Expert éminent sénior Avatar de Artemus24
    Homme Profil pro
    Agent secret au service du président Ulysses S. Grant !
    Inscrit en
    Février 2011
    Messages
    6 346
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Agent secret au service du président Ulysses S. Grant !
    Secteur : Finance

    Informations forums :
    Inscription : Février 2011
    Messages : 6 346
    Points : 18 959
    Points
    18 959
    Par défaut
    Salut slimshady2878.

    En effet, dans la version mysql 5.5, la fonction "regexp_replace()" n'existe pas :
    --> https://dev.mysql.com/doc/refman/5.5/en/regexp.html

    A comparer avec la version 8.0 où elle est présente :
    --> https://dev.mysql.com/doc/refman/8.0/en/regexp.html

    Ce que vous cherchez à faire est de remplacer une expression régulière par une chaîne de caractères, qui dans votre cas est vide.
    Je n'ai pas de solution à vous proposer.

    Peut-être devriez-vous envisager de migrer vers mysql version 8.0.

    @+
    Si vous êtes de mon aide, vous pouvez cliquer sur .
    Mon site : http://www.jcz.fr

  7. #7
    Membre à l'essai
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Août 2013
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Alimentation

    Informations forums :
    Inscription : Août 2013
    Messages : 41
    Points : 15
    Points
    15
    Par défaut
    HELP PLEASE HELP !
    J'ai fait ma Maj de Mysql pour passer en 5.7 et sur tous mes sites web j'ai un "error connecting database"
    Une idée ? un paramètre à modifier en ligne de commande ?
    Je suis sous debian Jessie sur un VPS OVH

  8. #8
    Expert éminent sénior Avatar de Artemus24
    Homme Profil pro
    Agent secret au service du président Ulysses S. Grant !
    Inscrit en
    Février 2011
    Messages
    6 346
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Agent secret au service du président Ulysses S. Grant !
    Secteur : Finance

    Informations forums :
    Inscription : Février 2011
    Messages : 6 346
    Points : 18 959
    Points
    18 959
    Par défaut
    Salut slimshady2878.

    Il y a quelques changements entre la version 5.5 et la version 5.7.
    Vous devez consulter le compte rendu (fichier erreur) de MySql afin de savoir ce qui ne va pas.

    A tout hasard je vous donne mon fichier "my.ini" (versin vindowsà pour mysql 5.7.
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    # *********************** #
    #                         #
    #     Sphere "Fraise"     #
    #                         #
    # *********************** #
     
    # ==================== #
    #     MySql Client     #
    # ==================== #
     
    [client]
    port   = 3306
    socket = mysql
     
    # ----------------------- #
    #     access features     #
    # ----------------------- #
     
    user     = root
    password = root
    host     = 127.0.0.1
     
    # --------------- #
    #     Charset     #
    # --------------- #
     
    # default-character-set = latin1
     
     
    # ==================== #
    #     MySql Server     #
    # ==================== #
     
    [mysqld]
    port   = 3306
    socket = mysql
     
    # -------------- #
    #     Master     #
    # -------------- #
     
    server-id = 1
    skip-slave-start
     
    # --------------- #
    #     Charset     #
    # --------------- #
     
    character-set-server     = latin1
    collation-server         = latin1_general_ci
    character-set-filesystem = latin1
     
    init-connect             = 'SET collation_connection = latin1_general_ci; SET NAMES latin1 COLLATE latin1_general_ci'
     
    # ------------------- #
    #     Date & Time     #
    # ------------------- #
     
    default-time-zone = SYSTEM
     
    explicit-defaults-for-timestamp = on
     
    # ------------------- #
    #     Directories     #
    # ------------------- #
     
    basedir = f:/Wamp/bin/mysql/mysql5.7.23/
    datadir = f:/Wamp/bin/mysql/mysql5.7.23/data
    tmpdir  = f:/Wamp/tmp
     
    # -------------------------#
    #     Full Text Search     #
    # -------------------------#
     
    ft-max-word-len  = 10
    ft-min-word-len  = 1
    ft-stopword-file = ""
     
    # ---------------#
    #     InnoDB     #
    # ---------------#
     
    default-storage-engine              = InnoDB
    default-tmp-storage-engine          = InnoDB
     
    innodb-adaptive-hash-index          = on
     
    innodb-buffer-pool-dump-now         = off
    innodb-buffer-pool-dump-at-shutdown = off
    innodb-buffer-pool-instances        = 2
    innodb-buffer-pool-load-at-startup  = OFF
    innodb-buffer-pool-size             = 128M
     
    innodb-data-file-path               = ibdata1:12M:autoextend
    innodb-data-home-dir                = f:/Wamp/bin/mysql/mysql5.7.23/data/ibdata/
    innodb-default-row-format           = compact
    innodb-doublewrite                  = 1
    #skip-innodb_doublewrite
     
    innodb-file-format-check            = on
    innodb-file-per-table               = 1
     
    innodb-flush-log-at-trx-commit      = 1
    innodb-flush-method                 = normal
    #innodb-force-recovery               = 1
     
    innodb-ft-enable-stopword           = off
    innodb-ft-max-token-size            = 10
    innodb-ft-min-token-size            = 0
     
    innodb-io-capacity                  = 2000
    innodb-lock-wait-timeout            = 600
     
    innodb-log-buffer-size              = 16M
    innodb-log-file-size                = 20M
    innodb-log-files-in-group           = 2
    innodb-log-group-home-dir           = f:/Wamp/bin/mysql/mysql5.7.23/data/ibdata/
     
    innodb-max-dirty-pages-pct          = 90
    innodb-optimize-fulltext-only       = 1
    innodb-page-size                    = 16K
    innodb-purge-threads                = 10
    innodb-read-io-threads              = 4
    innodb-stats-on-metadata            = 0
    # innodb-strict-mode                  = OFF
    innodb-support-xa                   = 1
    innodb-thread-concurrency           = 16
    innodb-undo-log-truncate            = 1
    innodb-write-io-threads             = 4
     
    # ---------------- #
    #     Language     #
    # ---------------- #
     
    lc-messages   = fr_FR
    lc-time-names = fr_FR
     
    # -------------------#
    #     Binary Log     #
    # -------------------#
     
    #log-bin              = f:/Wamp/logs/mysql_binary_log
    #binlog-cache-size    = 1M
    #binlog-format        = mixed
     
    # --------------------#
    #     General Log     #
    # --------------------#
     
    #general-log         = 1
    #general-log-file    = f:/Wamp/logs/mysql_general.log
    #log_output          = 'FILE';
     
    # ------------#
    #     Log     #
    # ------------#
     
    log-error                              = f:/Wamp/logs/mysql_error.log
    log-error-verbosity                    = 3
     
    log-queries-not-using-indexes          = 1
    log-slow-admin-statements              = 1
    log-throttle-queries-not-using-indexes = 60
     
    # ------------#
    #     Max     #
    # ------------#
     
    max-allowed-packet     = 16M
    max-connections        = 20
    max-connect-errors     = 10
    max-error-count        = 64
    max-heap-table-size    = 1G
    max-user-connections   = 0
    max-sp-recursion-depth = 255
     
    # --------------------#
    #     Buffer-Size     #
    # --------------------#
     
    join-buffer-size      = 512M
    read-buffer-size      = 512M
    read-rnd-buffer-size  = 512M
    sort-buffer-size      = 512M
     
    # ---------------#
    #     MyIsam     #
    # ---------------#
     
    bulk-insert-buffer-size   = 64M
     
    key-buffer-size           = 2G
     
    myisam-max-sort-file-size = 1G
    myisam-recover-options    = 1
    myisam-repair-threads     = 1
    myisam-sort-buffer-size   = 128M
    myisam-stats-method       = nulls_unequal
    myisam-use-mmap           = OFF
     
    # -------------------#
    #     Networking     #
    # -------------------#
     
    back-log           = 50
     
    bind-address       = 0.0.0.0
     
    net-buffer-length  = 8K
    net-read-timeout   = 60
    net-write-timeout  = 60
     
    # -----------------#
    #     Password     #
    # -----------------#
     
    default-password-lifetime      = 0
    disconnect-on-expired-password = 0
     
    # ---------------------------#
    #     Performance-Schema     #
    # ---------------------------#
     
    # performance-schema                                = ON
    # performance-schema-events-waits-history-size      = 20
    # performance-schema-events-waits-history-long-size = 1500
     
    # ----------------#
    #     Pluggin     #
    # ----------------#
     
    early-plugin-load =
    # early-plugin-load = keyring_file.dll
     
    # --------------#
    #     Query     #
    # --------------#
     
    query-alloc-block-size       = 8M
    query-cache-limit            = 1G
    query-cache-min-res-unit     = 4096
    query-cache-size             = 512M
    query-cache-type             = On
    query-cache-wlock-invalidate = Off
     
    # -------------#
    #     Skip     #
    # -------------#
     
    disable-partition-engine-check
     
    #skip-innodb-doublewrite
     
    skip-external-locking
    skip-federated
     
    #skip-grant-tables
    #skip-log-warnings
    skip-slave-start
    # skip-innodb-adaptive-hash-index
     
    # --------------------#
    #     Long & Slow     #
    # --------------------#
     
    long-query-time      = 0
     
    slow-query-log       = 1
    slow-query-log-file  = f:/Wamp/logs/mysql_slow.log
     
    # ------------#
    #     Ssl     #
    # ------------#
     
    skip-ssl
     
    # --------------#
    #     Table     #
    # --------------#
     
    table-definition-cache = 512
    table-open-cache       = 512
     
    # -------------------#
    #     Temp Table     #
    # -------------------#
     
    tmp-table-size = 1G
     
    # ---------------#
    #     Thread     #
    # ---------------#
     
    thread-cache-size = 8
    thread-stack      = 256K
     
    # ------------------------------#
    #     Timeout Configuration     #
    # ------------------------------#
     
    connect-timeout     = 600
    interactive-timeout = 600
    wait-timeout        = 600
     
    # --------------------#
    #     Transaction     #
    # --------------------#
     
    transaction-isolation = SERIALIZABLE
     
    # ---------------#
    #     Tuning     #
    # ---------------#
     
    concurrent-insert = 2
    open-files-limit  = 8192
     
    # secure-file-priv  = f:/wamp/tmp
    secure-file-priv  =
     
     
    # =================== #
    #     MySql Admin     #
    # =================== #
     
    [mysqldadmin]
    force
     
     
    # ================== #
    #     MySql Dump     #
    # ================== #
     
    [mysqldump]
    add-drop-database
    add-drop-table
    add-drop-trigger
     
    default-character-set = utf8
     
    flush-logs
    flush-privileges
     
    lock-all-tables
    max-allowed-packet    = 16M
    no-autocommit
    order-by-primary
    quick
    routines
     
    skip-comments
    skip-opt
    skip-set-charset
    skip-tz-utc
     
    triggers
     
     
    # ===================== #
    #     My Isam Check     #
    # ===================== #
     
    [myisamchk]
    key-buffer-size  = 128M
    sort-buffer-size = 128M
    read-buffer      = 2M
    write-buffer     = 2M
     
     
    # ====================== #
    #     MySql Hot Copy     #
    # ====================== #
     
    [mysqlhotcopy]
    interactive-timeout
     
     
    # ===================== #
    #     MySql Monitor     #
    # ===================== #
     
    [mysql]
    default-character-set = latin1
    no-auto-rehash
    #safe-updates
    skip-reconnect
    table
     
     
    # ================== #
    #     MySql Safe     #
    # ================== #
     
    [mysqld_safe]
    open-files-limit = 8192
     
    log-error        = f:/Wamp/logs/mysql_error.log
    Ce fichier dépend de mon environnement et risque de ne pas fonctionner chez vous.
    Mais vous pouvez vous en inspirer.


    @+
    Si vous êtes de mon aide, vous pouvez cliquer sur .
    Mon site : http://www.jcz.fr

  9. #9
    Membre à l'essai
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Août 2013
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Alimentation

    Informations forums :
    Inscription : Août 2013
    Messages : 41
    Points : 15
    Points
    15
    Par défaut
    Ouf ! Je m'en suis sorti ! C'était une ligne a commenter dans mon my.cnf
    Je vais faire la maj vers la version 8 si pas d'autres solutions... merci

  10. #10
    Membre à l'essai
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Août 2013
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Alimentation

    Informations forums :
    Inscription : Août 2013
    Messages : 41
    Points : 15
    Points
    15
    Par défaut
    Bon, tout compte fait j'ai abandonné le passage en V8 de MySQL parce que ça m'a mis un bo.... pas possible sur mon VPS et j'ai du restaurer une sauvegarde.
    Si ça peut aider, j'ai trouvé une fonction bien sympathique pour pouvoir faire un REGEXP_REPLACE sur ma V5 :

    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
    -- ------------------------------------------------------------------------------------
    -- USAGE
    -- ------------------------------------------------------------------------------------
    -- SELECT reg_replace(<subject>,
    --                    <pattern>,
    --                    <replacement>,
    --                    <greedy>,
    --                    <minMatchLen>,
    --                    <maxMatchLen>);
    -- where:
    -- <subject> is the string to look in for doing the replacements
    -- <pattern> is the regular expression to match against
    -- <replacement> is the replacement string
    -- <greedy> is TRUE for greedy matching or FALSE for non-greedy matching
    -- <minMatchLen> specifies the minimum match length
    -- <maxMatchLen> specifies the maximum match length
    -- (minMatchLen and maxMatchLen are used to improve efficiency but are
    --  optional and can be set to 0 or NULL if not known/required)
    -- Example:
    -- SELECT reg_replace(txt, '^[Tt][^ ]* ', 'a', TRUE, 2, 0) FROM tbl;
    DROP FUNCTION IF EXISTS reg_replace;
    DELIMITER //
    CREATE FUNCTION reg_replace(subject VARCHAR(21845), pattern VARCHAR(21845),
      replacement VARCHAR(21845), greedy BOOLEAN, minMatchLen INT, maxMatchLen INT)
    RETURNS VARCHAR(21845) DETERMINISTIC BEGIN 
      DECLARE result, subStr, usePattern VARCHAR(21845); 
      DECLARE startPos, prevStartPos, startInc, len, lenInc INT;
      IF subject REGEXP pattern THEN
        SET result = '';
        -- Sanitize input parameter values
        SET minMatchLen = IF(minMatchLen < 1, 1, minMatchLen);
        SET maxMatchLen = IF(maxMatchLen < 1 OR maxMatchLen > CHAR_LENGTH(subject),
                             CHAR_LENGTH(subject), maxMatchLen);
        -- Set the pattern to use to match an entire string rather than part of a string
        SET usePattern = IF (LEFT(pattern, 1) = '^', pattern, CONCAT('^', pattern));
        SET usePattern = IF (RIGHT(pattern, 1) = '$', usePattern, CONCAT(usePattern, '$'));
        -- Set start position to 1 if pattern starts with ^ or doesn't end with $.
        IF LEFT(pattern, 1) = '^' OR RIGHT(pattern, 1) <> '$' THEN
          SET startPos = 1, startInc = 1;
        -- Otherwise (i.e. pattern ends with $ but doesn't start with ^): Set start pos
        -- to the min or max match length from the end (depending on "greedy" flag).
        ELSEIF greedy THEN
          SET startPos = CHAR_LENGTH(subject) - maxMatchLen + 1, startInc = 1;
        ELSE
          SET startPos = CHAR_LENGTH(subject) - minMatchLen + 1, startInc = -1;
        END IF;
        WHILE startPos >= 1 AND startPos <= CHAR_LENGTH(subject)
          AND startPos + minMatchLen - 1 <= CHAR_LENGTH(subject)
          AND !(LEFT(pattern, 1) = '^' AND startPos <> 1)
          AND !(RIGHT(pattern, 1) = '$'
                AND startPos + maxMatchLen - 1 < CHAR_LENGTH(subject)) DO
          -- Set start length to maximum if matching greedily or pattern ends with $.
          -- Otherwise set starting length to the minimum match length.
          IF greedy OR RIGHT(pattern, 1) = '$' THEN
            SET len = LEAST(CHAR_LENGTH(subject) - startPos + 1, maxMatchLen), lenInc = -1;
          ELSE
            SET len = minMatchLen, lenInc = 1;
          END IF;
          SET prevStartPos = startPos;
          lenLoop: WHILE len >= 1 AND len <= maxMatchLen
                     AND startPos + len - 1 <= CHAR_LENGTH(subject)
                     AND !(RIGHT(pattern, 1) = '$' 
                           AND startPos + len - 1 <> CHAR_LENGTH(subject)) DO
            SET subStr = SUBSTRING(subject, startPos, len);
            IF subStr REGEXP usePattern THEN
              SET result = IF(startInc = 1,
                              CONCAT(result, replacement), CONCAT(replacement, result));
              SET startPos = startPos + startInc * len;
              LEAVE lenLoop;
            END IF;
            SET len = len + lenInc;
          END WHILE;
          IF (startPos = prevStartPos) THEN
            SET result = IF(startInc = 1, CONCAT(result, SUBSTRING(subject, startPos, 1)),
                            CONCAT(SUBSTRING(subject, startPos, 1), result));
            SET startPos = startPos + startInc;
          END IF;
        END WHILE;
        IF startInc = 1 AND startPos <= CHAR_LENGTH(subject) THEN
          SET result = CONCAT(result, RIGHT(subject, CHAR_LENGTH(subject) + 1 - startPos));
        ELSEIF startInc = -1 AND startPos >= 1 THEN
          SET result = CONCAT(LEFT(subject, startPos), result);
        END IF;
      ELSE
        SET result = subject;
      END IF;
      RETURN result;
    END//
    DELIMITER ;

  11. #11
    Expert éminent sénior Avatar de Artemus24
    Homme Profil pro
    Agent secret au service du président Ulysses S. Grant !
    Inscrit en
    Février 2011
    Messages
    6 346
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Agent secret au service du président Ulysses S. Grant !
    Secteur : Finance

    Informations forums :
    Inscription : Février 2011
    Messages : 6 346
    Points : 18 959
    Points
    18 959
    Par défaut
    Salut slimshady2878.

    Désolé de pouvoir faire plus pour vous.

    Je pense , en dehors de la fonction "REGEXP_REPLACE()", que vous avez un problème de modélisation de votre colonne ci-après :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    champ='-Room 1-Room 2(18:00:00)-Room 3(12:00:00)-Villa 4(13:30)'
    Il aurait fallu, lors de son insertion dans votre base de données, l'éclater en au moins deux colonnes et plusieurs lignes de façon à obtenir cette structure suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    +---------+----------+
    |   Lieu  | horaire  |
    +---------+----------+
    | Room  1 |          |
    | Room  2 | 18:00:00 |
    | Room  3 | 12:00:00 |
    | Villa 4 | 13:30:00 |
    +---------+----------+
    Ce qui vous aurait simplifier la vie.

    @+
    Si vous êtes de mon aide, vous pouvez cliquer sur .
    Mon site : http://www.jcz.fr

Discussions similaires

  1. Réponses: 1
    Dernier message: 01/06/2007, 13h50
  2. Réponses: 9
    Dernier message: 10/03/2007, 11h02
  3. Réponses: 2
    Dernier message: 07/03/2007, 11h46
  4. Réponses: 3
    Dernier message: 21/08/2006, 12h31
  5. Remplacer une PARTIE de chaine de caractères dans un champ
    Par Turlututuchapopointu dans le forum Langage SQL
    Réponses: 1
    Dernier message: 07/08/2005, 12h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo