SQL >> Database >  >> RDS >> Oracle

Oracle 11g: records zoeken in een CLOB met carriage return line feed

Uiteindelijk bleek het een geval van slechte data te zijn. De data in mijn testdatabase was corrupt en bevatte alleen LF-tekens in plaats van CRLF.

GIGO :-)

Bedankt voor alle hulp.

Trouwens, in mijn codevoorbeeld ben ik voor de functie INSTR gegaan in plaats van LIKE. Als een gebruiker een %-teken invult in de tekst om door te zoeken, kan dat de LIKE-uitdrukking verstoren. Die tekens eruit filteren is geen optie, want % kan een legitiem teken in mijn data zijn.

De definitieve code

PROCEDURE FindReplaceResponsibilities ( iOldResponsibilities IN JP_JOB_FAMILIES.RESPONSIBILITIES%TYPE, iNewResponsibilities IN JP_JOB_FAMILIES.RESPONSIBILITIES%TYPE, oNumRowsUpdated OUT INTEGER 

) IS

BEGIN oNumRowsUpdated := 0;

 SAVEPOINT sp_jf_findrepresp; -- If there is no old text to search for then, -- append the new text to the end of every row. -- Else replace all occurrences of the old text with the new text IF iOldResponsibilities IS NULL THEN UPDATE JP_JOB_FAMILIES SET RESPONSIBILITIES = RESPONSIBILITIES || iNewResponsibilities; oNumRowsUpdated := SQL%ROWCOUNT; ELSE UPDATE JP_JOB_FAMILIES SET RESPONSIBILITIES = REPLACE(RESPONSIBILITIES, iOldResponsibilities, iNewResponsibilities) WHERE dbms_lob.instr(RESPONSIBILITIES, iOldResponsibilities) > 0; oNumRowsUpdated := SQL%ROWCOUNT; END IF; RETURN; EXCEPTION WHEN OTHERS THEN BEGIN oNumRowsUpdated := -1; ROLLBACK TO sp_jf_findrepresp; dbms_output.put_line('error: ' || sqlerrm); RETURN; END; 

END FindReplaceResponsibilities;

De code aan de applicatiekant was in orde:

public int FindReplaceJobFamilyResponsibilities(String oldResponsibilities, String newResponsibilities, IDbTransaction transaction = null) { using (IDbCommand cmd = this._dataHelper.GetStoredProcedure(_connectionString, "JP_JOBFAM_PKG.FindReplaceResponsibilities", true)) { _dataHelper.SetParameterValue(cmd, "iOldResponsibilities", oldResponsibilities); _dataHelper.SetParameterValue(cmd, "iNewResponsibilities", newResponsibilities); DataHelperBase.VerifyParameters(cmd.Parameters, false); base.SetExecuteConnection(cmd, transaction); _dataHelper.ExecuteNonQuery(cmd); return Convert.ToInt32(_dataHelper.GetParameterValue(cmd, "oNumRowsUpdated")); } } 
  1. Geneste XML in Oracle queryen met XMLTable

  2. Een C# DataSet vullen vanuit Oracle

  3. Waarom TransactionScope en Oracle niet goed samenwerken

  4. Oracle Developer VM met Oracle 11g en SQL Developer