Sponsored Content
Top Forums Shell Programming and Scripting How to get value from a close and open parenthesis? Post 302997993 by ernesto on Wednesday 24th of May 2017 01:13:56 AM
Old 05-24-2017
after long hours. Finally got the code to work for this.

Code:
echo "insert into table_name (col1,col2,col3,col4,col5,DATE1,DATE2,col6,col7,col8,col9,col10,col11) values (6752,14932156,24,'ALL','Staff',to_date('04/17/2017 00:00:00','MM/DD/YYYY HH24:MI:SS'),to_date('05/24/2017 23:59:59','MM/DD/YYYY HH24:MI:SS'),'aso 4','device',148,null,null,null);" | while read file; do table=$(echo $file | awk -F"(" '{print $1}' | cut -d' ' -f3); cols=$(echo $file | awk -F"(" '{print $(NF - 3)}' | cut -d')' -f1); vals=$(echo $file | cut -d'(' -f3- | sed -e 's/);//g'); echo $table; echo $cols; echo $vals; done
table_name
col1,col2,col3,col4,col5,DATE1,DATE2,col6,col7,col8,col9,col10,col11
6752,14932156,24,'ALL','Staff',to_date('04/17/2017 00:00:00','MM/DD/YYYY HH24:MI:SS'),to_date('05/24/2017 23:59:59','MM/DD/YYYY HH24:MI:SS'),'aso 4','device',148,null,null,null);
while read line
do
tab=$(echo $file | cut -d' ' -f3)
value=$(echo $file | awk -F "values" '{print $2}' | sed -e 's/^ (//g' -e 's/);//g' -e "s/','MM/'|'MM/g")
cols=$(echo $file | awk -F"[()]" '{print $2}')
statement=$(echo -e "SELECT $cols FROM $tab $(paste -d"= " <(echo $cols | tr ',' '\n') <(echo $val |  sed -e 's/$/;/g' | tr ',' '\n') | sed -e '1s/^/WHERE /g' -e '2,100s/^/AND /g' | sed 's/=/ = /g' | sed -e 's/|/,/g')\n")

#Check a word null is present
#If yes, then need to change "= null" to "IS NULL"
if [[ $(echo ${statement} | grep -ic "null") -gt 0 ]]
then
   
   #We need to replace the line with null to "IS NULL"
   echo $statement | sed -e 's/= null/IS NULL/g'
fi

done

share if your have any other way to solve it
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File status - open/close ??

Is there any commands in UNIX, like isopen(),isclose() to know whether a file has been opened for read/write purpose.? Thanks (3 Replies)
Discussion started by: Pal
3 Replies

2. UNIX for Dummies Questions & Answers

Should a UNIX daemon process close open fds?

I have a UNIX daemon process that's been started by a parent process, an application server. The behavior of this daemon process is to inherit and use the app server's file descriptors (ports/sockets). When I shutdown the app server, the daemon continues to run, because there may be other... (1 Reply)
Discussion started by: kunalashar
1 Replies

3. Solaris

close open files before remove

Hi I have a script to remove log files when it reaches %70 usage in order to descending order of dates. But sometimes it happens to remove open - being processes files , so makes them unlinked from the directors and results them disappeared. How can I solve this problem , simple scenario I... (9 Replies)
Discussion started by: xramm
9 Replies

4. UNIX for Advanced & Expert Users

Number of open files (Dir's) how to close?

I am having a client/server application which will download files from server. If server has directories, it will create directories/sub directories and then download files. In this process, I observed that number of open files are more than 400 (which is approxmately same as number of dir/subdir... (1 Reply)
Discussion started by: satyam90
1 Replies

5. Windows & DOS: Issues & Discussions

Can DOS close an open file?

I'm trying to setup a cron job for my brother that goes out to the web and retrieves an excel file and overwrites the existing copy on his desktop. The problem I'm facing is I have to kill the process (excel.exe) if the file is open while the batch file runs, otherwise, it will create another copy... (2 Replies)
Discussion started by: quattro20v
2 Replies

6. Solaris

file open/read/write/close/access by process

Hi want to know what file (descriptor+filename+socket) is being accessed by particular process on solaris. Purpose : while running perf. test, needs to find where is the bottleneck. We are providing concurrnet load for around 1 hr and needs to capture data related to file usage pattern... (1 Reply)
Discussion started by: raxitsheth
1 Replies

7. Shell Programming and Scripting

Cleanup between parenthesis

Hi, I am trying to clean up data between parenthesis () in a file. See example below.... Input File : (New York) Chicago (London) New York (Chicago) London New York Chicago (London) (New York) (Chicago) (London) New York (Chicago) ... (3 Replies)
Discussion started by: msalam65
3 Replies

8. Programming

when parent process close, how to close the child?

can someone provide an example, where if the parent process quits for any reason, then the child process will also close? (3 Replies)
Discussion started by: omega666
3 Replies

9. IP Networking

Open/close of ports

Hi, I have read some forum theads about the open and close ports. some points are clear and it is not working on my machine or something am i missing? I have commented out a port /etc/services, one application uses then when i use the telnet <hostname> <port_blocked> it shows connected..... (1 Reply)
Discussion started by: balamv
1 Replies

10. Shell Programming and Scripting

Work with setsid to open a session and close it correctly

I would like to create the following script: run a python script with setsid python may or may not fail with exception check if all of the group processes were terminated correctly if not, kill the remaining processes How can I do that? Thanks a lot (3 Replies)
Discussion started by: ASF Studio
3 Replies
OCI_FIELD_SIZE(3)														 OCI_FIELD_SIZE(3)

oci_field_size - Returns field's size

SYNOPSIS
int oci_field_size (resource $statement, mixed $field) DESCRIPTION
Returns the size of a $field. PARAMETERS
o $statement - A valid OCI statement identifier. o $field - Can be the field's index (1-based) or name. RETURN VALUES
Returns the size of a $field in bytes, or FALSE on errors. EXAMPLES
Example #1 oci_field_size(3) example <?php // Create the table with: // CREATE TABLE mytab (number_col NUMBER, varchar2_col varchar2(1), // clob_col CLOB, date_col DATE); $conn = oci_connect("hr", "hrpwd", "localhost/XE"); if (!$conn) { $m = oci_error(); trigger_error(htmlentities($m['message']), E_USER_ERROR); } $stid = oci_parse($conn, "SELECT * FROM mytab"); oci_execute($stid, OCI_DESCRIBE_ONLY); // Use OCI_DESCRIBE_ONLY if not fetching rows echo "<table border="1"> "; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Type</th>"; echo "<th>Length</th>"; echo "</tr> "; $ncols = oci_num_fields($stid); for ($i = 1; $i <= $ncols; $i++) { $column_name = oci_field_name($stid, $i); $column_type = oci_field_type($stid, $i); $column_size = oci_field_size($stid, $i); echo "<tr>"; echo "<td>$column_name</td>"; echo "<td>$column_type</td>"; echo "<td>$column_size</td>"; echo "</tr> "; } echo "</table> "; // Outputs: // Name Type Length // NUMBER_COL NUMBER 22 // VARCHAR2_COL VARCHAR2 1 // CLOB_COL CLOB 4000 // DATE_COL DATE 7 oci_free_statement($stid); oci_close($conn); ?> NOTES
Note In PHP versions before 5.0.0 you must use ocicolumnsize(3) instead. This name still can be used, it was left as alias of oci_field_size(3) for downwards compatability. This, however, is deprecated and not recommended. SEE ALSO
oci_num_fields(3), oci_field_name(3). PHP Documentation Group OCI_FIELD_SIZE(3)
All times are GMT -4. The time now is 06:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy