Most existing relation extraction methods focus on extracting relations with the flat or overlapping structure, where constituent elements of these relations are only entities. However, in many application scenarios, relations with nested structures are more common, of which the elements can be both entities or relation triples. The almost vacant research on nested relation extraction can be attributed to two difficulties: (1) how to formalize and recover the nested structures of relations from the unstructured texts. (2) how to keep the extraction method effective in low-data settings. To solve these problems, first, we formally define the nested RE task and propose a prompt-tuning-based method, called iterPrompt, through constructing the iterative prompt templates for all possible relation triples to establish the nested structures. Then, we combine the prompts with the pre-trained language model by converting the nested RE task into the masked word prediction task to adapt our method to low-data settings. Furthermore, to alleviate the data sparsity problem, a dynamic relation identifier assignment strategy is proposed by associating the candidate relation triple with the randomly generated relation identifier, for representing the semantics of the current extracted relation. Extensive experiments demonstrate that the proposed iterPrompt method outperforms previous state-of-the-art baselines and has good compatibility for both flat and overlapping relation extraction tasks.