在游标中使用SELECT stmt时获取null

时间:2017-09-12 10:29:53

标签: mysql

BEGIN
DECLARE GL_NUMBER VARCHAR(20);
DECLARE VALUE1 VARCHAR(20);
DECLARE ORG_NAME VARCHAR(150);
DECLARE VALUE2 VARCHAR(150);
DECLARE exp_base_curr VARCHAR(150);
DECLARE TFO_REF_NO VARCHAR(150);  
DECLARE exit_loop BOOLEAN;
DECLARE serviceProvider_cursor CURSOR FOR
     SELECT QUOTE(org.ORGANISATIONNAME), ed.expense_base_curr FROM 
        pmedb.expense_detail ed, pmedb.deal_expense de, pmedb.cost_sheet cs, 
pmedb.organisation org
    where 
        de.cost_sheet_id=cs.cost_sheet_id and 
        ed.deal_expense_id = de.deal_expense_id and
        ed.supplier_id = org.ORGANISATIONID and
        de.cost_sheet_id = NEW.COST_SHEET_ID;   
DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE;
SET TFO_REF_NO = NEW.COST_SHEET_ID; 

       -- open the cursor
       OPEN serviceProvider_cursor;
       -- start looping
       serviceProvider_loop: LOOP
         -- read the name from next row into the variables 
         FETCH  serviceProvider_cursor INTO VALUE2, exp_base_curr;       

     SET VALUE1 = (SELECT QUOTE(GL_NUMBER) from `aisadb-rai`.`vw_coa` where G0_CODE='CURRENT_ASSETS' AND G1_CODE='ADV_PAID_TO_SUPPLIERS' AND G2_CODE='NO_CODE' AND G3_CODE='NO_CODE' AND G4_DESC= 'SERVICE_PROVIDER3');

        IF (NEW.STATUS='COST_SHEET_APPROVED' AND OLD.STATUS='COST_SHEET_PENDING_FOR_APPROVAL') THEN
            INSERT INTO `aisadb-rai`.`accounting_transcation_details` (`TFO_REF_NO`, `TFO_DOC_TYPE`, `GL_NUMBER`, `THIRDPARTY_GL_NUMBER`, `DEBIT_AMOUNT`) VALUES (CONCAT(TFO_REF_NO,'_COSTSHEET'), 'COST_SHEET',VALUE1, '00000', exp_base_curr);
        END IF;          
         -- check if the exit_loop flag has been set by mysql, 
         -- close the cursor and exit the loop if it has.
         IF exit_loop THEN
             CLOSE serviceProvider_cursor;
             LEAVE serviceProvider_loop;
         END IF;
       END LOOP serviceProvider_loop;
 END

在MYSQL游标中使用SELECT stmt时获取null。 VALUE1始终为null。

0 个答案:

没有答案