大家好我为Microsoft SQL Server编写了以下查询。 我需要将此查询转换为Oracle语法。我对Oracle语法没有任何了解。 我需要你的帮助才能使这个查询在Oracle数据库上运行。 我尝试了很多方法但没有返回数据。
SELECT SISPREV_student.Stu_Id, SISPREV_student.CwId,
SISPREV_student.Sex, SISPREV_student.Nok_Name, SISPREV_student.Nok2_Name,
SISPREV_student.Birth_Dt,
SISPREV_student.Currently_Enrolled, SISPREV_student.Stu_Athlete, SISPREV_student.LivingOnCampus,
SISPREV_student.ImmigrationStatus,
SISPREV_student.ScholarStatus, SISPREV_student.Stu_FirstName, SISPREV_student.Stu_MiddleName,
SISPREV_student.Stu_LastName, SISPREV_student.Ethnicity
FROM SISPREV_address RIGHT OUTER JOIN
SISPREV_student ON SISPREV_address.StudentID =
SISPREV_student.Stu_Id LEFT OUTER JOIN
SISPREV_email ON SISPREV_student.Stu_Id =
SISPREV_email.StudentID LEFT OUTER JOIN
SISPREV_phone ON SISPREV_student.Stu_Id =
SISPREV_phone.StudentID
WHERE ((SISPREV_student.Stu_Id LIKE '%' + '@StudentId' + '%') OR
('@StudentId' = '')) AND
((UPPER(SISPREV_student.Stu_FirstName) LIKE '%' +
UPPER('@StudentFirstName') + '%') OR ('@StudentFirstName' = '')) AND
((UPPER(SISPREV_student.Stu_MiddleName) =
UPPER('@StudentMiddleName')) OR ('@StudentMiddleName' = '')) AND
((UPPER(SISPREV_student.Stu_LastName) LIKE '%' +
UPPER('@StudentLastName') + '%') OR ('@StudentLastName' = '')) AND
((UPPER(SISPREV_student.Nok_Name) LIKE '%' +
UPPER('@StudentNextOfKinName') + '%') OR ('@StudentNextOfKinName' = '')) AND
((UPPER(SISPREV_address.Street) LIKE '%' + UPPER('@StudentStreet') +
'%') OR ('@StudentStreet' = '')) AND
((UPPER(SISPREV_address.City) LIKE '%' + UPPER('@StudentCity') +
'%') OR ('@StudentCity' = '')) AND
((UPPER(SISPREV_address.State) LIKE '%' + UPPER('@StudentState') +
'%') OR ('@StudentState' = '')) AND
((UPPER(SISPREV_address.ZipCode) LIKE '%' + '@StudentZipCode' + '%'
) OR ('@StudentZipCode' = '')) AND
((SISPREV_student.Birth_Dt = CONVERT(SMALLDATETIME,'@StudentBirthDay')) OR ('@StudentBirthDay' = '')) AND
((SISPREV_phone.Phone = '@StudentPhoneNumber') OR
('@StudentPhoneNumber' = '')) AND
((UPPER(SISPREV_student.Sex) = UPPER('@StudentGender')) OR
('@StudentGender' = ''))
GROUP BY SISPREV_student.Stu_Id, SISPREV_student.CwId,
SISPREV_student.Sex, SISPREV_student.Nok_Name, SISPREV_student.Nok2_Name,
SISPREV_student.Birth_Dt,
SISPREV_student.Currently_Enrolled, SISPREV_student.Stu_Athlete, SISPREV_student.LivingOnCampus,
SISPREV_student.ImmigrationStatus,
SISPREV_student.ScholarStatus, SISPREV_student.Stu_FirstName, SISPREV_student.Stu_MiddleName,
SISPREV_student.Stu_LastName, SISPREV_student.Ethnicity
答案 0 :(得分:4)
以下需要更改:
((upper(sisprev_address.street) like '%' + upper('@StudentStreet') + '%')
在Oracle中||串联不是+
((upper(sisprev_address.street) like '%' || upper('@StudentStreet') || '%') or ('@StudentStreet' = ''))
如果@StudentStreet来自用户输入并且可以为空,则可以在Oracle中检查
or ('@StudentStreet' is null)
日期:
convert(smalldatetime, '@StudentBirthDay')
取决于您收到日期字符串的方式
to_date('@StudentBirthDay','some date format')
'某些日期格式'='DD-MM-YYYY'或您处理的任何格式。查找Oracle数据格式字符串。