读取值并将其存储在主变量中时出现问题吗?
我的程序从文件中读取记录,并为文件中的每条记录从数据库中获取值。我在 Pro*C 程序中声明了一个主机变量。我在程序内的一个选择查询中使用了该主机变量。不会为每条记录清除变量的内存。
例如,对于第一条记录,sql 查询获取“ABCD”。然后,对于第二条记录,查询获取“EFGHIJKL”。对于第三条记录,DB 中的实际值为“GHI”,但内存不会被清除,并且会打印“GHIHIJKL”。
如何解决呢?
My program reads records from file and for each record in file it fetches value from DB. I have declared a host variable in my Pro*C program. I used that host variable in one of my select query inside the program. The memory of the variable doesn't get cleared for each record.
For example, for the first record the sql query fetches "ABCD". Then for the second record the query fetches "EFGHIJKL". For the third record the actual value in DB is "GHI" but the memory doesn't get cleared and it prints "GHIHIJKL".
How to resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上你应该做什么。还有一个 Pro*C 内联设置应该自动执行此操作,但我遇到了一些问题,所以我更喜欢这个解决方案,它快速且简单。
Here basically what you should do. There's also a Pro*C inline setting that should do that automatically, but I had some problems with it, so I prefer this solution, which is fast and simple.
您应该使用数据库调用提供的长度,从而使您能够处理包含 NUL 字节的数据。
或者您以给定的长度手动终止字符串。这仅适用于“无 NUL”字符串。
You either should work with the length provided with the database call, providing you with the capability of working with data containing NUL bytes.
Or you terminate your string manually with the given length. This works only with "NUL-less" strings.