本文介绍了PL SQL - 查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我是Pl / SQl的新手。我有3列表测试。 Column1 Column2 Column3 ----------------------- -------------------------- 100 CA,OH AR,CA 200 FL,MI MI,NY 所以在这里表,当我将column2与column3进行比较时,我已经添加了AR并删除了ID为100的OH。对于200我删除了FL并添加了NY。 如何找到我在第3列中添加的字符串以及从Column2删除的字符串? 我需要回答... 从100开始,删除OH并增加AR。 从200开始,删除FL并添加纽约。 有谁可以帮我找到这个? 非常感谢您提前。 我尝试了什么: 我试过strcomp函数,它给了我字符串是否已经改变。但我需要更改的确切字符串。解决方案 以下查询将解决您的问题 使用 Test_CTE(Column1,FirstColumn2,SecondColumn2,Column2,FirstColumn3,SecondColumn3,Column3) AS ( 选择 column1,SUBSTRING(column2, 1 , charindex(' ,',Column2, 1 ) - 1) as FirstColumn2, SUBSTRING(column2,charindex(' ,',Column2, 1 )+ 1, 10 )SecondColumn2,Column2, SUBSTRING(column3, 1 ,charindex(' ,',Column3, 1 ) - 1) as FirstColumn3, SUBSTRING(column3,charindex(' ,',Column3, 1 )+ 1, 10 )SecondColumn3,Column3 来自 tab1 ) 选择 Column1,( CASE WHEN CHARINDEX(FirstColumn2,column3, 1 )GT; 0 然后( CASE WHEN CHARINDEX(SecondColumn2,column3, 1 )> 0 然后 ' ' else SecondColumn2 + ' 已删除' 结束) else FirstColumn2 + ' 已删除' 结束) + ' 和' +( CASE WHEN CHARINDEX(FirstColumn3,column2, 1 )> 0 然后( CASE WHEN CHARINDEX(SecondColumn3,column2, 1 )GT; 0 然后 ' ' else SecondColumn3 + ' 已添加' 结束) else FirstColumn3 + ' 已添加' 结束)为结果,Column2,column3,CHARINDEX(FirstColumn2,column3, 1 )来自 TEst_CTE Hi,I am new to Pl/SQl. I have table Test with 3 columns.Column1 Column2 Column3-------------------------------------------------100 CA,OH AR,CA200 FL,MI MI,NYSo here in the table, when I compare column2 to column3, I have added AR and deleted OH for ID 100. For 200 I have deleted FL and added NY.How can I find which string I have added in column 3 and which string I have deleted from Column2?I need answer like ...From 100, OH deleted and AR added.From 200, FL deleted and NY added.Can anyone please help me find out this?Thank you very much in advance.What I have tried:I have tried strcomp function and it gave me whether the string has changed or not. But I need the exact string what has been changed. 解决方案 Following query will solve your problemWith Test_CTE(Column1,FirstColumn2,SecondColumn2,Column2,FirstColumn3,SecondColumn3,Column3)AS(Select column1,SUBSTRING(column2,1, charindex(',',Column2,1)-1) as FirstColumn2,SUBSTRING(column2,charindex(',',Column2,1)+1,10) SecondColumn2,Column2,SUBSTRING(column3,1, charindex(',',Column3,1)-1) as FirstColumn3,SUBSTRING(column3,charindex(',',Column3,1)+1,10) SecondColumn3,Column3 from tab1)Select Column1,( CASE WHEN CHARINDEX(FirstColumn2 ,column3,1)> 0 then (CASE WHEN CHARINDEX(SecondColumn2 ,column3,1)> 0 then '' else SecondColumn2 + ' Deleted' end ) else FirstColumn2 + ' Deleted ' end )+ ' and ' + (CASE WHEN CHARINDEX(FirstColumn3 ,column2,1)> 0 then (CASE WHEN CHARINDEX(SecondColumn3 ,column2,1)> 0 then '' else SecondColumn3 + ' Added' end ) else FirstColumn3 + ' Added ' end) as Result ,Column2,column3 ,CHARINDEX(FirstColumn2 ,column3,1)from TEst_CTE 这篇关于PL SQL - 查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-22 15:29