0

次のフィールドを持つ「キーワード」という名前のテーブルがあります。

ID [主キー] | キーワード [varchar(255)]

各レコードのキーワード フィールドには、"this, is, only, a test" のような文字列値が含まれています。

この文字列を区切り文字として「、」で分割し、各トークンを新しいテーブル内の新しいレコードとして挿入するストアド プロシージャを作成する方法がわかりません。

前もって感謝します。

4

3 に答える 3

1

ここで難しいのは、区切り文字で文字列をカットすることです。次のように FUNCTION を宣言する必要があります: http://fdegrelle.over-blog.com/article-1342263.html その後、テーブルに値を格納するだけで済みます。簡単です。幸運を!

于 2012-05-31T16:10:52.717 に答える
0

MySQL doesn't have any kind of SPLIT() or EXPLODE() string function. In a nutshell, you need to manually iterate over the string searching for commas and insert the value when you reach a delimiter (comma) or end of the string. Alternatively you could try doing fancy gyrations with INSTR() and such, your mileage may vary.

I would suggest reading some of the comments at the bottom of the String Functions reference page at MySQL. Do a search-on-page (Ctrl-F) for split and you'll see some useful ideas.

于 2012-05-31T16:10:04.887 に答える
0
  1. instr() を使用して、区切り文字 (,) の最初の出現を見つけます。

  2. 入力文字列を 0 番目の文字から最初に出現する 1 文字まで分割する Substring() これで、最初の文字列が分離されました。区切られた文字列をテーブルに挿入します。

  3. 入力文字列に対して replace() を使用して、最初の値を削除します。

  4. 入力文字列が空になるまで、手順 1 から 3 を繰り返します。これがうまくいくことを願っています..頑張ってください..

于 2012-06-05T03:28:39.670 に答える