1. 定义函数时,返回值需要定义为数组,比如int[]

2. 函数中需要根据数据的多少初始化数组的大小

3. 为数组一一赋值

// 查询某个学生的某课成绩所有成绩
function select_all_scores(address studentId, string courseName) public view returns(int[]){
 
		TableFactory tf = TableFactory(0x1001);
		Table table = tf.openTable("stu_score");
 
		string memory stuIdStr = addressToString(studentId);
		Condition condition = table.newCondition();
		condition.EQ("student_id", stuIdStr);
		condition.EQ("course_name", courseName);
 
		Entries entries = table.select(stuIdStr, condition);
 
        // 初始化数组大小
        int[] memory user_scores_list = new int[](uint256(entries.size()));
        
        // 给数组赋值
		for(int i=0; i<entries.size(); ++i) {
		    
            Entry entry = entries.get(i);
            // 添加数组元素
            user_scores_list[uint256(i)] = entry.getInt("score");

        }

        return user_scores_list;
 
}

FISCO BCOS Solidity 智能合约 返回数组_BCOS

FISCO BCOS Solidity 智能合约 返回数组_BCOS_02

 

智能合约的完整代码可以参考

https://blog.csdn.net/u013288190/article/details/108824439