Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1051603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:57:37+00:00 2026-05-16T16:57:37+00:00

Greetings to all! I want to create a pl/sql query by declaring variables for

  • 0

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.

    1. 00000 – “line %s, column %s:\n%s”
      *Cause: Usually a PL/SQL compilation error.
      *Action:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:57:38+00:00Added an answer on May 16, 2026 at 4:57 pm

    Question seems to be that you want to learn PL/SQL, rather than help with a query. Various issues with datatypes in here but the basic outline would be something like:

    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 varchar2(20); /* but why isn't this a date? */
    begin
        select Stay_Id into l_stay_id
        from MVStay
        where StayNumber = 'xxxx' /* number or string? */
        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 - really, why hold it as a string? what are the field
           types in MVStayWorkflow? */
        l_now := to_char(sysdate, 'YYYYMMDD HH:MI:SS.FF');
    
        /* get a new sequence number */
        l_stay_workflow_id := (get it from the concerned table)
        /* or, select ... into; or use a proper sequence for the insert? */
    
        /* 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;
    

    You need to understand what each part is doing though, and read up on the differences between SQL and PL/SQL…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.