Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Extracting only required length in a column in perl DBI

by marto (Bishop)
on Jan 15, 2013 at 12:37 UTC ( #1013385=note: print w/ replies, xml ) Need Help??


in reply to Extracting only required length in a column in perl DBI

If you only need the first three characters of each column, why not simply ask for that when doing your query? For example:

SELECT SUBSTR(COL1, 0, 3) FROM TABLENAME;

Consider using place holders where possible, See DBI and Bobby Tables.


Comment on Re: Extracting only required length in a column in perl DBI
Download Code
Re^2: Extracting only required length in a column in perl DBI
by Thomas Kennll (Acolyte) on Jan 15, 2013 at 12:48 UTC
    That will work.. But, I actually wanted to extract 6 characters for the 3 column... How do I achieve that??

      Replace the 3 in my example with a 6, you should consider learning basic SQL.

        What I meant is something like this my ($ansb_cktid, $ansb_mcn, $ansb_soc) =unpack("A3 A3 A6")
Re^2: Extracting only required length in a column in perl DBI
by Anonymous Monk on Jan 17, 2013 at 07:32 UTC

    Nitpick: even though substr() is implemented in most sql dialects, the standards-compliant function is substring(col1 from 1 for 3)

      OP stated they're using Oracle, substring(col1 from 1 for 3) doesn't work (ORA-00907). substr.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013385]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-07-06 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls