假设有一个表有一列和列名称就像FULL_NAME(Rajeev Pratap Sing)。但是我想在具有First_Name,Middle_Name,Last_Name三列的其他表中插入相同的数据。
结果应该像在其他表中一样......
First_Name-- Middle_Name-- Last_Name
拉杰夫 - 普拉塔普 - 辛格
答案 0 :(得分:1)
尝试以下:
SELECT REGEXP_SUBSTR('Rajeev Pratap Sing','[^ ]+',1,1) "First Name",
REGEXP_SUBSTR('Rajeev Pratap Sing','[^ ]+',1,2) "Middle Name",
REGEXP_SUBSTR('Rajeev Pratap Sing','[^ ]+',1,3) "Last Name"
FROM DUAL
答案 1 :(得分:1)
INSERT INTO table2
SELECT regexp_substr(full_name,'\S+'),--first name
regexp_substr(full_name,'\S+',regexp_instr(full_name,' ',1,1)),--middle
regexp_substr(full_name,'\S+',regexp_instr(full_name,' ',1,2)) --last
FROM table_1;
答案 2 :(得分:1)
Insert into emp_name(First_Name,Middle_Name,Last_Name) select substr(FULL_NAME,1,instr(full_name,' ')) as First_Name, substr(Full_Name,instr(full_name,' ',1,1)+1,instr(full_name,' ',1,2)-instr(full_name,' ',1,1)) as Middle_Name, substr(Full_Name,instr(full_name,' ',1,2)) as Last_Name from full_name;