sys.dm_exec_sql_text returns NULL in dbid, objectid, and number columns, but not text
This is by design as of now. There is a connect item about this problem which is closed as of now.

sys.dm_exec_query_stats DBID column NULL for dynamic SQL - by Theo Ekelmans

But at the end there is a comment:


  Thank you for the feedback! We will consider it for the next release
  of SQL Server.


There is also some workaround in the comment section and also as mentioned by @sp_BiltzErik in the comment above.