CSV to array
Jun 07, 2016 pm 02:54 PM將CSV的字符串 截斷成相應的 字符串值數(shù)組 PL/SQL jQuery CSV function csv_to_array (p_csv_line in varchar2, p_separator in varchar2 := g_default_separator) return t_str_arrayas type t_str_array as table of varchar2(4000); l_returnvalue t_str_a
將CSV的字符串截斷成相應的 字符串值數(shù)組 PL/SQL jQuery CSV
function csv_to_array (p_csv_line in varchar2, p_separator in varchar2 := g_default_separator) return t_str_array as type t_str_array as table of varchar2(4000); l_returnvalue t_str_array := t_str_array();--返回的字符串數(shù)組類型 l_start_separator pls_integer := 0 ; l_stop_separator pls_integer := 0 ; l_length pls_integer := 0 ;--長度 l_idx binary_integer := 0 ; l_quote_enclosed boolean := false ; l_offset pls_integer := 1 ; begin /* Purpose: convert CSV line to array of values Remarks: based on code from http://www.experts-exchange.com/Database/Oracle/PL_SQL/Q_23106446.html Who Date Description ------ ---------- -------------------------------- MBR 31.03.2010 Created fartpig 07.03.2011 noted */ /* 相應的CSV中的注意 就是關于 "" 中包含分隔符 ,的情況,需要通過標記 是否有雙引號的 變量來進行掃描查找 同時保存三個掃描量:掃描開始位置(掃描頭),掃描結束位置(掃描尾),掃描偏移量(用來標記掃描的偏移) */ --獲得長度 l_length := length(p_csv_line) ; if l_length > 0 then loop --遞增 標記的數(shù)據(jù)下標 l_idx := l_idx + 1; l_quote_enclosed := false; --判斷開始分割的 下一個字符是否是 " if substr(p_csv_line, l_start_separator + 1, 1) = '"' then --如果是 標記其 有雙引號 l_quote_enclosed := true; --設定 掃描偏移單位為 2 l_offset := 2; --查找 下一個雙引號的位置 l_stop_separator := instr(p_csv_line, '"', l_start_separator + l_offset, 1); else --如果沒有 雙引號 --設定 掃描偏移單位為 1 l_offset := 1; --查找 下一個 分割符 的位置 l_stop_separator := instr(p_csv_line, p_separator, l_start_separator + l_offset, 1); end if; --如果 沒有找到 掃描的下一個 位置 if l_stop_separator = 0 then --設定 掃描的下一個位置為 總長度+1 從而推出循環(huán) l_stop_separator := l_length + 1; end if; --將 掃描得到的 值 保存到數(shù)組中 l_returnvalue.extend; l_returnvalue(l_idx) := substr(p_csv_line, l_start_separator + l_offset, (l_stop_separator - l_start_separator - l_offset)); --如果掃描到頭 就推出循環(huán) exit when l_stop_separator >= l_length; --如果有 雙引號 if l_quote_enclosed then --將掃描位置 +1 從而過濾掉" l_stop_separator := l_stop_separator + 1; end if ; --標記 掃描的開始位置 為 掃描到的位置 l_start_separator := l_stop_separator; end loop; end if; -- 返回結果 return l_returnvalue; end csv_to_array;

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

You can use substr() or mb_substr() to get the first N characters in PHP. The specific steps are as follows: 1. Use substr($string,0,N) to intercept the first N characters, which is suitable for ASCII characters and is simple and efficient; 2. When processing multi-byte characters (such as Chinese), mb_substr($string,0,N,'UTF-8'), and ensure that mbstring extension is enabled; 3. If the string contains HTML or whitespace characters, you should first use strip_tags() to remove the tags and trim() to clean the spaces, and then intercept them to ensure the results are clean.

There are two main ways to get the last N characters of a string in PHP: 1. Use the substr() function to intercept through the negative starting position, which is suitable for single-byte characters; 2. Use the mb_substr() function to support multilingual and UTF-8 encoding to avoid truncating non-English characters; 3. Optionally determine whether the string length is sufficient to handle boundary situations; 4. It is not recommended to use strrev() substr() combination method because it is not safe and inefficient for multi-byte characters.

You can use SQL's CREATETABLE statement and SELECT clause to create a table with the same structure as another table. The specific steps are as follows: 1. Create an empty table using CREATETABLEnew_tableASSELECT*FROMexisting_tableWHERE1=0;. 2. Manually add indexes, foreign keys, triggers, etc. when necessary to ensure that the new table is intact and consistent with the original table structure.

In JavaScript, check whether an array contains a certain value. The most common method is include(), which returns a boolean value and the syntax is array.includes(valueToFind), for example fruits.includes('banana') returns true; if it needs to be compatible with the old environment, use indexOf(), such as numbers.indexOf(20)!==-1 returns true; for objects or complex data, some() method should be used for in-depth comparison, such as users.some(user=>user.id===1) returns true.

InC ,stringscanbeconvertedtouppercaseorlowercasebyprocessingeachcharacterusingstd::toupperorstd::tolowerfrom1.Casteachcharactertounsignedcharbeforeapplyingthefunctiontoavoidundefinedbehavior.2.Modifycharactersinplaceorcopythestringifpreservingtheori

There are three common methods to find the Nth highest value of a column in SQL. 1. Use subquery and LIMIT/OFFSET: First sort the target column in descending order, skip the first N-1 record and then take one. It is suitable for simple scenarios but may affect performance; 2. Exclude maximum values ??layer by layer through nested subqueries: the logic is clear but the structure is complex when the hierarchy increases; 3. Use DENSE_RANK or ROW_NUMBER window function (recommended): Flexible processing of duplicate values, supports precise ranking, suitable for database environments that support window functions. Which method to choose depends on the specific database type, data volume and structural requirements.

There are many ways to traverse strings in Python, depending on the requirements. First, using a for loop, you can directly access characters one by one: s="hello", forcharins:print(char), and each character will be output in turn. Secondly, if you need index information, you can combine the enumerate() function: s="hello", forindex,charinenumerate(s):print(f"Position{index}:{char}"), so as to obtain the characters and their positions at the same time. In addition, list comprehension is suitable for batch processing of characters

When designing a relational database, four key principles should be followed. First, correctly use primary and foreign key constraints to ensure data integrity and association accuracy; second, perform standardized design reasonably, usually reaching the third normal form (3NF), eliminating redundancy and ensuring data consistency; third, establishing appropriate indexes for common queries to improve query performance but avoid over-index; finally, using consistent naming specifications and structural styles to enhance readability and maintainability. Mastering these principles can help build a clear, efficient and robust database structure.
