The concurrent use of multiple drugs may result in drug-drug interactions, increasing the risk of adverse reactions. Hence, it is particularly crucial to propose computational methods for precisely identifying unknown drug-drug interactions, which is of great significance for drug development and health. However, most recent studies have limited the drug-drug interaction prediction task to identifying interactions between substructures, overlooking molecular hierarchical information. Moreover, the extracted substructures in these methods are always restricted to have the same number of atoms as contained in the molecular graph, which does not align with real-world facts. In this study, a molecular fragment representation learning framework for drug-drug interaction prediction is introduced. Initially, a fragment extraction module is designed to acquire a series of molecular fragments. Subsequently, to capture more comprehensive features, molecular hierarchical information is effectively integrated, enabling drug-drug interaction prediction by identifying pairwise interactions between molecular fragments of each drug. Comprehensive evaluations demonstrate that the proposed method achieved state-of-the-art performance in both DrugBank and Twosides datasets, particularly achieving an improved accuracy of over 20% for unseen drugs in both two datasets. Furthermore, case studies and visual analysis confirm that the proposed method can accurately identify crucial substructures influencing the interactions, which are basically consistent with functional group structures in reality. In conclusion, this method not only enhances the performance of drug-drug interaction prediction but also offers high interpretability. Source code is freely available at https://github.com/kennysyp/MFR-DDI .