【问题标题】:how to declare a variable in pl sql the right way?如何以正确的方式在 pl sql 中声明变量?
【发布时间】:2013-09-03 17:08:52
【问题描述】:

这是我的代码

  vJS     VARCHAR2(3500); --25065
     gMaxDays    s_criteria%rowtype := get_criteria_rec('MAX_DAYS_BOOKING');

BEGIN
  IF NOT Sec_Pkg.chk_sec('ATLAS_INV_OVERBOOK') THEN
       -- Exit procedure if security did not pass
       RETURN;
   END IF;
    --
    vJS :=  ' gMaxDays;'||CHR(10)||
            'function checkfields() {' ||CHR(13) ||
            '    // Setting the target here' ||CHR(13) ||
            '    document.frmInvSelect.target="_top"' ||CHR(13) ||

我创建了 gMaxDays,起初我对其进行了硬编码,但现在它位于名为 s_criteria 的表上,MAX_DAYS_BOOKING 是 s_criteria 的一部分。我说得对吗?

这就是它过去的外观和工作方式

  vJS     VARCHAR2(3500); --25065

BEGIN
  IF NOT Sec_Pkg.chk_sec('ATLAS_INV_OVERBOOK') THEN
       -- Exit procedure if security did not pass
       RETURN;
   END IF;
    --
    vJS :=  'var gMaxDays = 366;'||CHR(10)||
            'function checkfields() {' ||CHR(13) ||
            '    // Setting the target here' ||CHR(13) ||
            '    document.frmInvSelect.target="_top"' ||CHR(13) ||
        [/code]

【问题讨论】:

  • 你有什么错误吗?如果有,是哪一个?
  • 我实际上没有收到错误,它只是没有进行任何搜索
  • 什么意思?你的变量是空的吗?
  • NO 不为空模块 max_days_booking 包含一行=366
  • include_list 中的行

标签: oracle plsql plsqldeveloper


【解决方案1】:

呃……你是在说这个吗

您曾经有一个“有效”的代码 sn-p:

vJS :=  'var gMaxDays = 366;'||CHR(10)||
        'function checkfields() {' ||CHR(13) ||
        '    // Setting the target here' ||CHR(13) ||
        '    document.frmInvSelect.target="_top"' ||CHR(13) ||

当你将 sn-p 修改为:

vJS :=  ' gMaxDays;'||CHR(10)||
        'function checkfields() {' ||CHR(13) ||
        '    // Setting the target here' ||CHR(13) ||
        '    document.frmInvSelect.target="_top"' ||CHR(13) ||

它不再“工作”了?

我猜您正在尝试生成 JavaScript 代码 sn-p。也许这就是你要找的:

declare
  vJS VARCHAR2(3500);
  gMaxDays s_criteria%rowtype := get_criteria_rec('MAX_DAYS_BOOKING');
begin
  -- here you have to call the correct field from the record
  -- in this example I assume it's max_day
  vJS := 'var gMaxDays = ' || gMaxDays.max_day || ';' || CHR(10)||
         'function checkfields() {' || CHR(10) ||
         '    // Setting the target here' || CHR(10) ||
         '    document.frmInvSelect.target="_top"' || CHR(10) ||
         ' // Add here something that makes this a valid JavaScript.'
end;

查看文档中关于 PL/SQL record variables 的内容。

【讨论】:

  • 你从哪里得到 max_day?
  • 当我把它放在 var gmaxdays 时它可以搜索所有数据库,但我只希望它能够搜索 366 天,这就是我放在表中的内容
  • @user1289509 因为你没有告诉所有必要的细节(s_criteria%rowtype 的结构)我不得不做出假设。在我的示例中,我假设gMaxDays 记录的相关字段是max_days。在您的真实代码中,您检查记录并使用正确的字段。如果这对您没有意义,我建议您研究有关记录的 PL/SQL 文档。
猜你喜欢
  • 2012-01-18
  • 2021-07-03
  • 2010-09-23
  • 1970-01-01
  • 1970-01-01
  • 2020-07-25
  • 1970-01-01
  • 2018-03-07
  • 2017-12-16
相关资源
最近更新 更多