需要创建 pl/sql 查询的帮助
向大家问好! 我想通过声明以下变量来创建 pl/sql 查询,例如:
: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
问候 Mohammed
你好,Alex..
我使用了你的代码,但遇到了错误: 从命令中的第 3 行开始出错: 宣布 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
/* 关闭stay,stay_number = '030074559' */ 选择 Stay_Id 进入 l_stay_id 来自 MVStay 其中住宿编号 = '030074559' 且保持状态 = 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;
结尾; 错误报告: ORA-06550: 第 27 行,第 5 列: PLS-00103:在期望以下其中一项时遇到符号“IF”:
- & = - + ; < //> at in 是 mod 余数不是 rem
<>或 != 或 ~= >= <= <>和或喜欢像2
like4 likec || 之间多重集成员子多重集
符号“;”替换为“IF”继续。
- 00000 - “第 %s 行,第 %s 列:\n%s” *原因:通常是 PL/SQL 编译错误。 *行动:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题似乎是您想学习 PL/SQL,而不是帮助查询。这里有数据类型的各种问题,但基本轮廓如下:
您需要了解每个部分在做什么,并阅读 SQL 和 PL/SQL 之间的差异...
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:
You need to understand what each part is doing though, and read up on the differences between SQL and PL/SQL...
在 Oracle 中,您使用 SELECT ... INTO ... 语法填充变量:
此外,Oracle 将以冒号(“:”)为前缀的文本解释为 BIND 变量,这意味着它应该是用传入参数值填充。
如果您希望将stay_id 与我提供的分开,请使用:
In Oracle, you populate variables using the
SELECT ... INTO ...
syntax:Also, Oracle interprets text prefixed with a colon (":") to be a BIND variable, meaning it expects to be populated with an incoming parameter value.
If you want the stay_id separate from what I provided, use: