oracle 如何在一个字段中插入多个值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16212393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:37:03  来源:igfitidea点击:

how to insert multiple values in one field?

sqloracleoracle10g

提问by VextoR

I have a query:

我有一个疑问:

    INSERT
INTO I#journal
  (
    Type_,
    Mndnr,
    Obj,
    Status,
    Reason
  )
  VALUES
  (
    'PO',
    '0177',
    '000222',
    'NEW',
    '1'
  )

this one works OK. But instead of '1' I want to insert multiple values in one field, like '1','2','3'

这个工作正常。但是我想在一个字段中插入多个值而不是 '1',例如 '1','2','3'

And usually you do it like this:

通常你这样做:

INSERT
INTO I#journal
  (
    Type_,
    Mndnr,
    Obj,
    Status,
    Reason
  )
  VALUES
  (
    'PO',
    '0177',
    '000222e',
    'NEW',
    '1,2,3'
  )

But how to do it if values will put there as '1','2','3'?

但是如果值将放在那里怎么办'1','2','3'

INSERT
INTO I#journal
  (
    Type_,
    Mndnr,
    Obj,
    Status,
    Reason
  )
  VALUES
  (
    'PO',
    '0177',
    '000222e',
    'NEW',
    '1','2','3'
  )

So, we can'tchange '1','2','3'(due of some automation) but we can add anything before and past this string. In result information in Reasonfield should be something like 1,2,3

因此,我们无法更改'1','2','3'(由于某些自动化),但我们可以在此字符串之前和之后添加任何内容。在Reason字段中的结果信息应该是这样的1,2,3

How to do that?

怎么做?

回答by TechDo

Insert value replace(q'$'1','2','3'$', '''', '')Single quotes(') is the escape character. i.e.

插入值replace(q'$'1','2','3'$', '''', '')单引号( ') 是转义字符。IE

INSERT
INTO I#journal
  (
    Type_,
    Mndnr,
    Obj,
    Status,
    Reason
  )
  VALUES
  (
    'PO',
    '0177',
    '000222',
    'NEW',
    replace(q'$'1','2','3'$', '''', '')
  );

回答by A.B.Cade

Try:

尝试:

INSERT
INTO I#journal
  (
    Type_,
    Mndnr,
    Obj,
    Status,
    Reason
  )
  VALUES
  (
    'PO',
    '0177',
    '000222e',
    'NEW',
    replace(q'['1','2','3']', q'[',']', '')  )

回答by xHerickx

Try this

尝试这个

INSERT INTO I#journal
 (
   Type_,
   Mndnr,
   Obj,
   Status,
   Reason
 )
 VALUES
 (
   'PO',
   '0177',
   '000222',
   'NEW',
   '''1'',''2'',''3'''
 )

回答by swetha

try this INSERT.

试试这个 INSERT

INTO I#journal
  (
    Type_,
    Mndnr,
    Obj,
    Status,
    Reason
  )
  VALUES
  (
    'PO',
    '0177',
    '000222',
    'NEW',
    '1'
  ),(
    'PO',
    '0177',
    '000222e',
    'NEW',
    '1,2,3'
  )