我一直在尝试将我编写的一些SQL Server查询转换为Oracle。我在这里使用pastebin进行原始SQL查询:https://pastebin.com/Ru19FCzG但我一次只能处理一个块。
这是我目前正在处理的块(这是最重要的块) 原始查询:
declare @name varchar(max) = 'SPRING 1 2017 RTP';
declare @term varchar(30), @session varchar(1), @loc varchar(2), @id nvarchar(255);
set @term = '17SP1';
set @session='1';
set @loc = 'RT';
set @id = CASE WHEN @session = '2'
then ('%-%-' + @loc + '[5-9]%-' + @term)
else ('%-%-' + @loc + '[0-4]%-'+ @term)
END;
select dr.crsmain_batch_uid [course_id], (us.firstname+' '+us.lastname)[instructor],
q.qtext_body[question], qr.answer_text[answer], ac.points[points]
into #survey_results
from clp_sv_question_response qr
join deployment_response dr on qr.deployment_response_pk1=dr.pk1
join deployment d on dr.deployment_pk1=d.pk1
join clp_sv_answer_choice ac on qr.clp_sv_answer_choice_pk1=ac.pk1
join clp_sv_subquestion sq on ac.clp_sv_subquestion_pk1=sq.pk1
join clp_sv_question q on sq.clp_sv_question_pk1=q.pk1
left join (
select c.batch_uid, u.firstname, u.lastname from course_users cu
join users u on u.pk1=cu.users_pk1
join course_main c on cu.crsmain_pk1=c.pk1
where (c.course_id like @id)
and cu.role='P' and u.user_id not like '%_admin') us on dr.crsmain_batch_uid=us.batch_uid
where d.name=@name
order by dr.crsmain_batch_uid, instructor,
q.qtext_body, qr.answer_text, ac.points;
以下是我所使用的修改后的查询。
甲骨文:
define name = 'SPRING 1 2017 RTP';
define term = '17SP1';
define session = '1';
define loc = 'RT';
define id = IF &session = '1'
then (course_id, '[a-z]{3,}|[0-9]{3}|'loc'[0-4]{1}[0-9]{1}'term,'i')
else (course_id, '[a-z]{3,}|[0-9]{3}|'loc'[5-9]{1}[0-9]{1}'term,'i')
END IF;
create table survey_results as
select dr.crsmain_batch_uid as "course_id", (us.firstname+' '+us.lastname) as "instructor",
q.qtext_body as "question", qr.answer_text as "answer", ac.points as "points"
from clp_sv_question_response as qr
inner join deployment_response as dr on qr.deployment_response_pk1=dr.pk1
inner join deployment as d on dr.deployment_pk1=d.pk1
inner join clp_sv_answer_choice as ac on qr.clp_sv_answer_choice_pk1=ac.pk1
inner join clp_sv_subquestion as sq on ac.clp_sv_subquestion_pk1=sq.pk1
inner join clp_sv_question as q on sq.clp_sv_question_pk1=q.pk1
left join (
select c.batch_uid, u.firstname, u.lastname from course_users as cu
join users as u on u.pk1=cu.users_pk1
join course_main as c on cu.crsmain_pk1=c.pk1
where (c.course_id regexp_like &id)
and cu.role='P' and u.user_id not like '%_admin') as "us" on dr.crsmain_batch_uid=us.batch_uid
where d.name=&name
order by dr.crsmain_batch_uid, instructor,
q.qtext_body, qr.answer_text, ac.points;
任何帮助都将不胜感激。
答案 0 :(得分:0)
尝试使用PL / SQL块
END:
你的其余部分
{{1}}