Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: tidb循环要怎么写
【TiDB Usage Environment】Production Environment
【TiDB Version】
【Reproduction Path】
【Encountered Problem: Problem Phenomenon and Impact】Don’t know how to write a TiDB loop, hoping for an example from experts
【Resource Configuration】
【Attachments: Screenshots/Logs/Monitoring】
Write a loop from the host level, like this:
for i in `seq 10000`; do
mysql -uroot -h 10.10.10.16 -P4000 -pxxxxxx -e "insert into test.t1 values($i, floor(rand()*10000000))";
done;
Use backticks for seq 10000
.
How to write loop data results?
for i in seq 10
; do echo “insert into test.t1 values($i,floor(rand()*10000000))”; done;
for i in `seq 10`; do
exec_sql="insert into test.t1 values($i,floor(rand()*10000000))"
mysql -uroot -h 10.10.10.16 -P4000 -pxxxxxx --comments -e "${exec_sql}"
done;
Currently, it can only be supported through external scripts.
More complex requirements can be written using shell scripts.
What I mean is whether there is something similar to MySQL while or stored procedures.
I want to write an SQL right now.
Currently, stored procedures are not supported.
Use shell or python instead.
TiDB does not support stored procedures. Currently, this can only be achieved through shell, or Java, Python, etc. It cannot be done purely with SQL.
TiDB currently does not support Procedures, UDF functions, etc. You can achieve your needs through scripting languages like Shell, Perl, Python. I believe that in the future, the stored procedure and function features will be improved, and Ti/SQL (similar to Oracle PL/SQL) might be introduced as well. 
Awesome, I really don’t know how to do this. How about using Python to write it?
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.