Hi Folks! Greetings to all! I want to create a pl/sql query by declaring variables for the following eg:
:stay_id = (SELECT Stay_Id from MVStay where StayNumber = 'xxxx' AND StayState = 2);
-- get passage linked to the stay and is 'discharged'
:passage_id = (SELECT Passage_Id from MVStayWorkflow where Stay_Id = :stay_id and WorkflowAction = 31);
-- get current date
:now = to_char(sysdate, 'YYYYMMDD HH:MI:SS.FF')
-- get a new sequence number
:stay_workflow_id = (get it from the concerned table)
--insert ‘Admin discharged’ workflow step
if( passage_id is not NULL)
begin
Insert into MVStayWorkflow (StayWorkflow_Id, Stay_Id, Passage_Id, User_Id, RespUnit_Id, Resource_Id,
WorkflowAction, CurrentState, PreviousState, WorkflowTime, UserStamp, TimeStamp)
values (:stay_workflow_id, :stay_id, :passage_id, 1, 0, 0, 11, 7, 7, :now, 1, :now)
end
Regards Mohammed
Hi Alex..
I used your code but encountered an error: Error starting at line 3 in command: declare l_stay_id MVStay.Stay_Id%TYPE; l_passage_id MVStayWorkflow.Passage_Id%TYPE; l_stay_workflow_id MVStayWorkflow.Stay_Workflow_Id%TYPE; l_now MVSTAY.ENDDATETIME%TYPE; begin
/* get closed stay having stay_number = '030074559' */ select Stay_Id into l_stay_id from MVStay where StayNumber = '030074559' and StayState = 2;
/* get passage linked to the stay and is 'discharged' */
select Passage_Id into l_passage_id
from MVStayWorkflow
where Stay_Id = l_stay_id
and WorkflowAction = 31;
/* get current date types in MVStayWorkflow? */
l_now := to_char(sysdate, 'YYYYMMDD HH:MI:SS.FF');
/* get a new sequence number */
l_stay_workflow_id := 500000
/* insert ‘Admin discharged’ workflow step */
if passage_id is not NULL then
insert into MVStayWorkflow (StayWorkflow_Id, Stay_Id, Passage_Id,
User_Id, RespUnit_Id, Resource_Id, WorkflowAction, CurrentState,
PreviousState, WorkflowTime, UserStamp, TimeStamp)
values (l_stay_workflow_id, l_stay_id, l_passage_id,
1, 0, 0, 11, 7, 7, l_now, 1, l_now);
end if;
end; Error report: ORA-06550: line 27, column 5: PLS-00103: Encountered the symbol "IF" when expecting one of the following:
- & = - + ; < / > at in is mod remainder not rem
<> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
The symbol ";" was substituted for "IF" to continue.
- 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action: