使用 C++Builder 調用預存程序,執行 StoredProc1->ExecProc() 時拋出錯誤:
錯誤:indicator variable required but not supplied
預存程序執行過程中,若有**輸出參數回傳 NULL 值**,驅動程式要求提供指標變數來標示 NULL 狀態,但預設參數建立未處理此情況。
在預存程序**內部**對可能產生的 NULL 值進行處理,確保輸出參數不會回傳 NULL。例如使用 ISNULL()、COALESCE() 或 CASE WHEN 將 NULL 轉為預設值(如 0、空字串等)。
StoredProc1->Params->Clear();
StoredProc1->Params->CreateParam(ftSmallint, "@m1", ptInput);
StoredProc1->Params->CreateParam(ftString, "@m2", ptOutput);
StoredProc1->Params->CreateParam(ftInteger, "@m3", ptOutput);
StoredProc1->Params->CreateParam(ftInteger, "@m4", ptOutput);
StoredProc1->Params->CreateParam(ftInteger, "@m5", ptOutput);
StoredProc1->Params->CreateParam(ftInteger, "Result", ptResult);
StoredProc1->Prepare();
StoredProc1->ExecProc(); // 此處原本拋出錯誤
修正預存程序定義後,上述呼叫碼即可正常執行。