{"id":492,"date":"2014-08-03T12:18:08","date_gmt":"2014-08-03T10:18:08","guid":{"rendered":"http:\/\/www.rocworks.at\/wordpress\/?p=492"},"modified":"2014-08-03T12:27:32","modified_gmt":"2014-08-03T10:27:32","slug":"wincc-oa-read-csv-file","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=492","title":{"rendered":"WinCC OA read csv file&#8230;"},"content":{"rendered":"<p>A simple code how to read\/import a CSV file into an array (dyn_dyn_string).<\/p>\n<p><code>main()<br \/>\n{<br \/>\n&nbsp;string content;<br \/>\n&nbsp;fileToString(DATA_PATH+\"\/csvtest.txt\", content); \/\/ read file into a string variable<\/p>\n<p>&nbsp;dyn_dyn_string result;<br \/>\n&nbsp;dyn_string lines = strsplit(content, \"\\n\"); \/\/ split the string into lines<br \/>\n&nbsp;for ( int i=1; i&lt;=dynlen(lines); i++ ) {<br \/>\n&nbsp;&nbsp;result[i]=strsplit(lines[i], \";\"); \/\/ delimiter \";\"<br \/>\n&nbsp;}<br \/>\n&nbsp;DebugTN(result);<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Limitations:<br \/>\n* Don&#8217;t do it in that way with very big files because it is read from the file into memory<br \/>\n* The delimiter &#8220;;&#8221; cannot be inside of a cell value<\/p>\n<p>With oracle you can use external tables to access CSV files. After creating an external table it is possible to access the file by SQL:<\/p>\n<p><code>select * from ext_tab<\/p>\n<p>CREATE DIRECTORY EXT_DIR AS '\/home\/oracle\/data';<\/p>\n<p>-- Create table<br \/>\ncreate table ext_tab<br \/>\n(<br \/>\nCol1 VARCHAR2(30),<br \/>\nCol2 VARCHAR2(30),<br \/>\nCol3 VARCHAR2(30)<br \/>\n)<br \/>\norganization external<br \/>\n(<br \/>\ntype ORACLE_LOADER<br \/>\ndefault directory EXT_DIR<br \/>\naccess parameters<br \/>\n(<br \/>\nRECORDS DELIMITED BY NEWLINE FIELDS TERMINATED BY \";\"<br \/>\n)<br \/>\nlocation (EXT_DIR:csvtest.csv')<br \/>\n)<br \/>\nreject limit UNLIMITED;<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A simple code how to read\/import a CSV file into an array (dyn_dyn_string). main() { &nbsp;string content; &nbsp;fileToString(DATA_PATH+&#8221;\/csvtest.txt&#8221;, content); \/\/ read file into a string variable &nbsp;dyn_dyn_string result; &nbsp;dyn_string lines = strsplit(content, &#8220;\\n&#8221;); \/\/ split the string into lines &nbsp;for ( int i=1; i&lt;=dynlen(lines); i++ ) { &nbsp;&nbsp;result[i]=strsplit(lines[i], &#8220;;&#8221;); \/\/ delimiter &#8220;;&#8221; &nbsp;} &nbsp;DebugTN(result); } &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=492\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WinCC OA read csv file&#8230;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-492","post","type-post","status-publish","format-standard","hentry","category-wincc-oa"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=492"}],"version-history":[{"count":9,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/492\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/492\/revisions\/501"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}