如何检查条件并将文本写入文本文件oracle表格

我正在 Oracle Forms 中创建程序,其中检查验证数据并将数据插入表中.还要检查验证数据如果条件为真,则将一些文本写入文本文件,如果条件不为真,则将一些文本写入文本文件.

喜欢:

验证编号 1 : OK验证 2 :好的

我成功地为TRUE"条件创建了程序.现在我想要如果一个条件为真,第二个条件为假,则将文本写入文本文件.

喜欢:

验证编号 1 : OK验证二:错误

如果两个条件都是假"则

验证编号 1:错误验证二:错误

代码:

PROCEDURE VALIDATION_TEST(p_mid we_group_hof_k.mstatusid%TYPE,p_status we_group_hof_k.cardstatus%TYPE) 是LC$行 Varchar2(4000);TFile CLIENT_TEXT_IO.FILE_TYPE ;开始插入测试选择 mstatusid,cardstatus来自 we_group_hof_k其中 mstatusid = p_mid和 cardstatus = p_status;IF p_mid = 1 AND p_status = 'A' THENLC$Line := 'log_' ||TO_CHAR (SYSDATE, 'yyyymmdd_HH24miss') ||'.日志';TFile := CLIENT_TEXT_IO.FOpen('E:HMISState	est.log', 'W');CLIENT_TEXT_IO.put_line (TFile, '日志文件' || LC$Line);CLIENT_TEXT_IO.new_line (TFile);CLIENT_TEXT_IO.put_line (TFile, '作业开始于:' || TO_CHAR (SYSDATE, 'dd-mm-yyyy HH24:mi:ss'));CLIENT_TEXT_IO.new_line (TFile);CLIENT_TEXT_IO.put_line (TFile, 'Validation No.1:' || 'OK');CLIENT_TEXT_IO.new_line (TFile);CLIENT_TEXT_IO.put_line (TFile, 'Validation No.2:' || 'OK');CLIENT_TEXT_IO.fclose (TFile);万一;结尾;

解决方案

您还没有告诉我们实际的条件是什么,所以您需要填写详细信息.

CLIENT_TEXT_IO.put (TFile, 'Validation No.1:');如果 condition_1 那么CLIENT_TEXT_IO.put_line (TFile, 'OK');别的CLIENT_TEXT_IO.put_line (TFile, '错误');万一;CLIENT_TEXT_IO.new_line (TFile);CLIENT_TEXT_IO.put (TFile, 'Validation No.2:');如果 condition_2 那么CLIENT_TEXT_IO.put_line (TFile, 'OK');别的CLIENT_TEXT_IO.put_line (TFile, '错误');万一;

<块引用>

我总共有 15 个条件

在这种情况下,您可能希望将其包装到辅助函数中:

PROCEDURE VALIDATION_TEST (p_mid we_group_hof_k.mstatusid%TYPE,p_status we_group_hof_k.cardstatus%TYPE ) 是LC$行 Varchar2(4000);TFile CLIENT_TEXT_IO.FILE_TYPE ;过程打印_验证(CLIENT_TEXT_IO.FILE_TYPE 中的 p_file, p_validation_number 的数量, 布尔值中的 p_condition )是开始CLIENT_TEXT_IO.new_line (p_file);CLIENT_TEXT_IO.put (p_file, '验证号'||to_char(p_validation_number) || ': ' );如果 p_condition 那么CLIENT_TEXT_IO.put_line (p_file, 'OK');别的CLIENT_TEXT_IO.put_line (p_file, '错误');万一;结束打印验证;开始插入测试选择 mstatusid,cardstatus来自 we_group_hof_k其中 mstatusid = p_mid和 cardstatus = p_status;IF p_mid = 1 AND p_status = 'A' THENLC$Line := 'log_' ||TO_CHAR (SYSDATE, 'yyyymmdd_HH24miss') ||'.日志';TFile := CLIENT_TEXT_IO.FOpen('E:HMISState	est.log', 'W');CLIENT_TEXT_IO.put_line (TFile, '日志文件' || LC$Line);打印验证(TFile,1,condition_1);打印验证(TFile,2,condition_2);...打印验证(TFile,15,condition_15);CLIENT_TEXT_IO.fclose (TFile);万一;结尾;

I am creating Procedure in Oracle Forms in which Check Validation data and insert data into table. Also check Validation data If condition true then write Some texts into text file and If condition is not true then write some texts into text file.

Like:

Validation No.1 : OK
Validation No.2 : OK

I created procedure successfully for "TRUE" Condition. Now I want If One Condition is True and 2nd Condition is False then write texts into text file.

Like:

Validation No.1 : OK
Validation No.2 : ERROR

And If both conditions "FALSE" Then

Validation No.1 : ERROR
Validation No.2 : ERROR

Code:

PROCEDURE VALIDATION_TEST
(p_mid we_group_hof_k.mstatusid%TYPE,  
 p_status we_group_hof_k.cardstatus%TYPE
) is

LC$Line  Varchar2(4000);
TFile    CLIENT_TEXT_IO.FILE_TYPE ;

begin
insert into test
select mstatusid, cardstatus
from we_group_hof_k
where mstatusid = p_mid 
and cardstatus = p_status;

IF p_mid = 1 AND p_status = 'A' THEN
LC$Line := 'log_' || TO_CHAR (SYSDATE, 'yyyymmdd_HH24miss') || '.log';
TFile := CLIENT_TEXT_IO.FOpen( 'E:HMISState	est.log', 'W' );
CLIENT_TEXT_IO.put_line (TFile, 'Log file ' || LC$Line);
CLIENT_TEXT_IO.new_line (TFile);
CLIENT_TEXT_IO.put_line (TFile, 'Job started at: ' || TO_CHAR (SYSDATE, 'dd-mm-yyyy HH24:mi:ss'));
CLIENT_TEXT_IO.new_line (TFile);
CLIENT_TEXT_IO.put_line (TFile, 'Validation No.1 : ' || 'OK');

CLIENT_TEXT_IO.new_line (TFile);
CLIENT_TEXT_IO.put_line (TFile, 'Validation No.2 : ' || 'OK');

CLIENT_TEXT_IO.fclose (TFile);

END IF;
end;

解决方案

You haven't told us what the conditions actually are so you'll need to fill in the details.

CLIENT_TEXT_IO.put (TFile, 'Validation No.1 : ' );
if condition_1 then
    CLIENT_TEXT_IO.put_line (TFile, 'OK');
else
    CLIENT_TEXT_IO.put_line (TFile, 'ERROR');
end if;

CLIENT_TEXT_IO.new_line (TFile);

CLIENT_TEXT_IO.put (TFile, 'Validation No.2 : ' );
if condition_2 then
    CLIENT_TEXT_IO.put_line (TFile, 'OK');
else
    CLIENT_TEXT_IO.put_line (TFile, 'ERROR');
end if;

I have total 15 Conditions

In which case you might want to wrap that up into helper function:

PROCEDURE VALIDATION_TEST (p_mid we_group_hof_k.mstatusid%TYPE,  
 p_status we_group_hof_k.cardstatus%TYPE ) is    
    LC$Line  Varchar2(4000);
    TFile    CLIENT_TEXT_IO.FILE_TYPE ;

    procedure print_validation (
        p_file in CLIENT_TEXT_IO.FILE_TYPE
        , p_validation_number in number
        , p_condition in Boolean )
    is
    begin
        CLIENT_TEXT_IO.new_line (p_file);            
        CLIENT_TEXT_IO.put (p_file, 'Validation No.'||to_char(p_validation_number) || ': ' );
        if p_condition then
            CLIENT_TEXT_IO.put_line (p_file, 'OK');
        else
            CLIENT_TEXT_IO.put_line (p_file, 'ERROR');
        end if;
    end print_validation;    
begin
    insert into test
    select mstatusid, cardstatus
    from we_group_hof_k
    where mstatusid = p_mid 
    and cardstatus = p_status;

    IF p_mid = 1 AND p_status = 'A' THEN        
        LC$Line := 'log_' || TO_CHAR (SYSDATE, 'yyyymmdd_HH24miss') || '.log';
        TFile := CLIENT_TEXT_IO.FOpen( 'E:HMISState	est.log', 'W' );
        CLIENT_TEXT_IO.put_line (TFile, 'Log file ' || LC$Line);

        print_validation(TFile, 1, condition_1);
        print_validation(TFile, 2, condition_2);
        ...
        print_validation(TFile, 15, condition_15);

        CLIENT_TEXT_IO.fclose (TFile);

    END IF;
end; 

相关文章