Parse User Pasted Text and use in SQL query

I am trying to take some user pasted text (typically would come from Excel) and parse those values and put into a query.
text area:
":P11_text"
query:
"select *
from table
where column in :P11_text;"
I have tried some variations of replace and translate in order to parse that list of values...something like: translate(:P11_text, chr(10)||chr(13), ',' ).....and many variations of this.
I have been able to replace the end of lines with the commas, but it appears that I am not getting my single quotes captured, even when trying to force them in. The best attempt returned single quotes and commas in between values but not at the beginning and end of the list of values.
I would bet that there is an easy way to accomplish this or an easy way to accomplish the requirement in a different way altogether.
Please point me in the right direction.

I finally got this one figured out!
create or replace type myTableType as table
of varchar2(4000)
create or replace
function in_list( p_string in varchar2 ) return myTableType
as
l_string long default p_string || ',';
l_data myTableType := myTableType();
n number;
begin
loop
exit when l_string is null;
n := instr( l_string, ',' );
l_data.extend;
l_data(l_data.count) :=
ltrim( rtrim( substr( l_string, 1, n-1 ) ) );
l_string := substr( l_string, n+1 );
end loop;
return l_data;
end;
--The SQL Query is:
select *
from t wher c in (select *
from THE
( select cast( in_list(translate(:p10_prolist,chr(10)||chr(13),',')) as
mytableType ) from dual ) a);
--Working like a champion!!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Generating text file using PL/SQL

    can any body send sample program how to generate text file using PL/SQL program.I want to store table data into that text file.

    Hi,
    try this.
    Thanks
    CREATE OR REPLACE procedure write_index (TABLE_NAME_ACCEPT VARCHAR2) IS
    id UTL_FILE.FILE_TYPE;
    name VARCHAR2(20) := 'e:\db_coca\input';      
    err VARCHAR2(100);      
    ColNameLength Integer;
    NumberoFColumns Integer;
    num NUMBER;           
    i integer;
    loc_query VARCHAR2(2000);
    cursor_name INTEGER;
    ret INTEGER;
    l_const_name VARCHAR2(30);
    CURSOR c_columns(i_Constraint_name VARCHAR2) IS
         SELECT *
         FROM     all_cons_columns
         WHERE     CONSTRAINT_NAME = i_Constraint_name
         order by table_name;
    BEGIN
    DBMS_OUTPUT.PUT_LINE('BEFORe OPEN');
    --id := UTL_FILE.FOPEN('e:\db_coca\input',name,'w');          
         --IF UTL_FILE.IS_OPEN(id) THEN
         --     DBMS_OUTPUT.PUT_LINE('Opened');
         --ELSE
         --     DBMS_OUTPUT.PUT_LINE('Still Closed');           
         --END IF;          
    DBMS_OUTPUT.PUT_LINE('AFTER OPEN');
    --The table generation script
         loc_query := 'Select CONSTRAINT_NAME from user_constraints ';
         loc_query := loc_query || ' where owner = ' || '''CPS''';
         loc_query := loc_query || ' AND CONSTRAINT_TYPE = ' || '''P''';
         dbms_output.put_line('TABLE_NAME_ACCEPT = ' || TABLE_NAME_ACCEPT);
         IF NOT (TABLE_NAME_ACCEPT IS NULL ) THEN
              loc_query := loc_query || ' AND TABLE_NAME like ''';
              loc_query := loc_query || TABLE_NAME_ACCEPT ;
              loc_query := loc_query || '''';
         END IF;
         cursor_name := DBMS_SQL.OPEN_CURSOR;
    dbms_output.put_line('Query = ' || loc_query);
         DBMS_SQL.PARSE(cursor_name, loc_query, DBMS_SQL.v7);
    dbms_output.put_line('After parse');
         dbms_sql.DEFINE_COLUMN(cursor_name, 1,l_const_name, 30);
         ret := DBMS_SQL.EXECUTE(cursor_name);
    --     IF ret > 0 THEN
         LOOP
         dbms_output.put_line('return = ' || ret);
              IF DBMS_SQL.FETCH_ROWS(cursor_name) > 0 THEN
                   dbms_sql.COLUMN_VALUE(cursor_name, 1,l_const_name);
              --     dbms_sql.BIND_VARIABLE(cursor_name,
    l_const_name,CONSTRAINT_NAME);
              --     FOR C10 in Table_Loop Loop          --The cursor
    for the table name
                   Select COunt(*) INTO NumberoFColumns from
                   all_cons_columns
                   Where CONSTRAINT_NAME = l_const_name;
         --          FOR C11 IN c_columns(l_const_name) LOOP
         --          End loop;
         --          UTL_FILE.PUT(id, ');');
              ELSE EXIT;
              END if;     --THe 1 st cursor if is closed
         End Loop;     --The table loop ends here
              DBMS_SQL.CLOSE_CURSOR(cursor_name);
    --     END IF;     
    --     UTL_FILE.PUT_LINE(id,name);
    --     UTL_FILE.PUT(id,'It worked and wrote to this file');
         UTL_FILE.FCLOSE(id);
         DBMS_OUTPUT.PUT_LINE('Successful write to file');          
    EXCEPTION     
    WHEN OTHERS THEN               
         err := SQLERRM;          
         num := SQLCODE;
         DBMS_OUTPUT.PUT_LINE(err);          
         DBMS_OUTPUT.PUT_LINE(num);
         DBMS_OUTPUT.PUT_LINE('Error in writing to file');     
    END write_index;

  • Creating a text file using pl/sql

    how can one create a text file using pl/sql?
    Say for example abcd.txt in the d: drive
    (d:\abcd.txt)
    on a windows nt server

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by bhrigu nagal ([email protected]):
    thanks for your replies
    I had already set the utl_file_dir parameter
    I tried the utl package and wrote the following code but got some errors
    declare
    filehandler UTL_FILE.FILE_TYPE;
    begin
    filehandler:=UTL_FILE.fopen('d:/intel/','myfile.txt','w');
    utl_file.put_line(filehandler,'look masjdfgsd\n');
    utl_file.fclose(filehandler);
    exception when utl_file.invalid_path then
    raise_application_error(-20023,'bhrigu ,chk the path');
    end;
    the errors
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 101
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at line 4
    if u know what this is please tell me
    thanks bhrigu
    <HR></BLOCKQUOTE>
    U need :
    1) To have UTL_FILE_DIR param in the init file of the instance with the same directory (don't forget to stop and restart the base)
    2) Handled the exceptions listed in the utl_file package (Oracle_home\rdbms\admin\utlfile.sql) in your source.
    3) Turn set serveroutput on in SQL*Plus.
    Run your procedure and see the error message to debug.
    Good luck
    null

  • Multi-language support for user-specified text strings used in the forms

    multi-language support for user-specified text strings used in the forms
    Instead of creating multiple forms, 1 in each different language, for the same service, is there any workaround?

    Hoan - is your question what are the considerations when creating multiligual catalogs? If so, I can tell you that at other clients I have seen them use a single catalog for one or two languages. For the two langugages, such as Spanish/English, you can create a single catalog with both of them. Once you get to more than two languages, the catalog would get unweildy and is therefore not suggested.

  • Using a SQL Query in an Alert and Matching a String

    I've created an alert in 12.0.4 using a SQL Query and the field that I'm trying to match is a string.  Originally the query returned multiple rows but when the alert still didn't fire, I modified the query WHERE clause to return only one row:
    NAME                                RESPONSE
    Are area lights working?            No
    My expression in the metric is RESPONSE.  In the Monitor I'm matching a string equal to No.  (Do I need double quotes around the matchvalue?  Single quotes?  No quotes?)  The metric is in the 15min scan group, the role is xMII Developers and I'm in that role. The monitor alert string is ' =  '.  Both metric and monitor are active and I've subscribed to the monitor.  Other alerts in the 15min scan group (all based on tag queries) are firing off properly.
    Why is nothing showing up in the Alert Log?
    David Macindoe

    David,
    Did you figure out the answer?  If not, I will try to find someone to address your question.
    Mike

  • I want to buy photoshop creative cloud for teams, how users can install and use it?

    i want to buy photoshop creative cloud for teams, how users can install and use it?

    Cancel old and buy new is the only way I know, but you MAY be able to exchange
    Return, cancel, or exchange an Adobe order

  • Copy and paste text and graphics between Flash and Illustrator

    When copying text in Illustrator and pasting them to Flash, some text would become drawing objects and some remain text. A drawing object is not editable. If I import the AI file, then text remains text but the placement of graphics can be a little bit off sometimes.
    It's just not possible to copy-and-paste text and graphics from Flash to Illustrator.
    Is it just me? If not, when will Adobe have better integration between the 2?
    Thanks,

    Even though you can change your InDesign preferences for Clipboard Handling to allow formatted information to be pasted into InDesign from other programs, unfortunately Illustrator still won't allow you paste in text with formatting. This is due to how Illustrator and InDesign handle text differently. Even if you copy the text from Illustrator and paste it into a program like Word, which has a lot of different ways to handle formatted text, Illustrator just treats text differently than other Adobe applications.

  • Can't make or receive calls but can text and use data

    I have had signal problems since I have got this phone which is an s4 my wife s3 mini gets better signal while at the same location. Tried everything customer service doesn't know and now I can't even make or receive a call. I can though send and receive text and use data but when I try to make a call it just says dialing then quits. Anyone trying to call says it will ring until voicemail but I never got the call. Can anyone help

        haynes88,
    Yikes! I want you to be able to make phone calls on your cell phone! I would recommend what others have stated on here as well. Remove the sim card for a good 30 seconds while the phone is off. Then try to make the phone call again. Have you ever replaced the sim card on your device before? You can always get a new sim card for free at a corporate store location: http://bit.ly/3SdsA Please keep us posted.
    KevinR_VZW
    Follow us on Twitter @VZWSupport

  • How to use this sql query in oracle?

    Hi all,
    i am using one sql query that is
    SELECT @ToDate = '2012-10-03 00:00:00.000'
    select @BetweenDate = DATEADD(MM,-1,@ToDate)
    select @FromDate = DATEADD(m,DATEDIFF(m,0,@BetweenDate),0)
    SELECT @ToDate = DATEADD(month, ((YEAR(@BetweenDate) - 1900) * 12) + MONTH(@BetweenDate), -1)
    so @todate value is = '2012-10-03 00:00:00.000'
    so in @betweendate value will come 1 month before like '2012-09-03 00:00:00.000'
    again in @fromdate value will come like that '2012-09-01 00:00:00.000' means first date of @betweendate
    and again @todate value will come like that '2012-09-30 00:00:00.000' means last date of @betweendate
    it's happening in sql and i have to use same logic in oracle also.
    how to use it??
    thanks

    declare
    todate date:= to_date('2012-10-03 00:00:00','yyyy-mm-dd hh:mi:ss');
    betwendate date := add_months(todate,-1);
    for datediff / additions you can direct subtract/add two different date variables
    like
    datediff = betweendate -todate
    dateadd := todate+1;

  • Starting and stopping an SQL query from within a Shell script

    DB version:10gR2
    OS Version:AIX
    We have a C++ application called WpnCreate.cpp, which is causing some locking problems.
    So, we have decided to capture(using SPOOL) the locking info(session info, blocking program,..etc) using an SQL query.
    WpnCreate.cpp program is initiated by a shell script. So we need this SQL query(.sql) to start firing just before WpnCreate.cpp is called and when WpnCreate.cpp has finished executing, we need the SQL query execution to stop.
    But how do i stop the sql query execution? Should i capture the session id and serial# of this session and use kill -9 at the end of the shell script?
    Flow of the Shell script should be like this
    Step1. Start firing the SQL query which captures the locking info and SPOOL them to a file
    Step2. Execute WpnCreate.cpp program
    Step3. Stop the firing of SQL query once WpnCreate.cpp has finished executing ( i don't know how)How will i go about achieving this?

    How can you run your step 2 untill & unless your step 1 gets over. You can run in background but then it will not capture the correct information.
    I think you need to run your step 1 after step 2 , then only you will be able to capture the information.
    You can run your C++ program in background and can wait for some time using sleep command and then run the query to check the locking information.

  • I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work

    Hi,
    I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work
    (fault number -2147217900)
    I want to search for a value in a ms access table , if it exist i want to update it, if not i want to insert a new row.
    Working with LabView 7.1, database con. toolset.
    Who can HELP?
    Thanks a lot
    Marco

    Hello,
    I think that If exist is not a standar SQL command (I know it exists I think in Oracle and SQL server), MS access doesn't support it, so I think the best way to do it is first make a Select and then either an Update or an insert, sorry...
    Paulo

  • Using multiple sql query

    Im writing a jsp that pulls data from the database and loads it into dropdown-list looks like this:
    <select name="Source">
    <%
    conn = DriverManager.getConnection(url, username, password);
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = stmt.executeQuery("SELECT BBCourseID(Sroffer.SrofferID)course_name, SrofferSchedule_Faculty.FacultyID AS FacultyID FROM SrofferSchedule_Faculty srofs JOIN SrofferScheduleID sros ON srofs.SrofferScheduleID= sro.SrofferScheduleID JOIN Sroffer sro ON sro.SrofferID= sros.SrofferID WHERE srofs.FacultyID=IDnumber");
    rs.beforeFirst();
    while (rs.next()) {%>
    <option value="<%=courseid=rs.getString("BBCourseID")%>"><%=courseid%> <%=rs.getString("course_name")%></option>
    <%}
    %>
    </select>
    Problem is, I have to pull the FacultyID from cams using this sql query
    ("SELECT FacultyID FROM FacultyPortal WHERE PortalAlias="") berfore i can run the query above. Don't know how to do this in a jsp
    Edited by: JohnsonJ on Mar 26, 2009 5:53 PM

    You know how to get a connection and how to execute a query and how to process the resultset - so what's standing in your way of doing that for the faculty ID?
    Isn't there a join you can do to get that in one query?
    And finally - you really shouldn't do this in a JSP, use a servlet to package the result up in some Java Collection and process it with JSTL tags.

  • XML Generation using a sql query in an efficient way -Help needed urgently

    Hi
    I am facing the following issue while generating xml using an sql query. I get the below given table using a query.
         CODE      ID      MARK
    ==================================
    1 4 2331 809
    2 4 1772 802
    3 4 2331 845
    4 5 2331 804
    5 5 2331 800
    6 5 2210 801
    I need to generate the below given xml using a query
    <data>
    <CODE>4</CODE>
    <IDS>
    <ID>2331</ID>
    <ID>1772</ID>
    </IDS>
    <MARKS>
    <MARK>809</MARK>
    <MARK>802</MARK>
    <MARK>845</MARK>
    </MARKS>
    </data>
    <data>
    <CODE>5</CODE>
    <IDS>
    <ID>2331</ID>
    <ID>2210</ID>
    </IDS>
    <MARKS>
    <MARK>804</MARK>
    <MARK>800</MARK>
    <MARK>801</MARK>
    </MARKS>
    </data>
    Can anyone help me with some idea to generate the above given CLOB message

    not sure if this is the right way to do it but
    /* Formatted on 10/12/2011 12:52:28 PM (QP5 v5.149.1003.31008) */
    WITH data AS (SELECT 4 code, 2331 id, 809 mark FROM DUAL
                  UNION
                  SELECT 4, 1772, 802 FROM DUAL
                  UNION
                  SELECT 4, 2331, 845 FROM DUAL
                  UNION
                  SELECT 5, 2331, 804 FROM DUAL
                  UNION
                  SELECT 5, 2331, 800 FROM DUAL
                  UNION
                  SELECT 5, 2210, 801 FROM DUAL)
    SELECT TO_CLOB (
                 '<DATA>'
              || listagg (xml, '</DATA><DATA>') WITHIN GROUP (ORDER BY xml)
              || '</DATA>')
              xml
      FROM (  SELECT    '<CODE>'
                     || code
                     || '</CODE><IDS><ID>'
                     || LISTAGG (id, '</ID><ID>') WITHIN GROUP (ORDER BY id)
                     || '</ID><IDS><MARKS><MARK>'
                     || LISTAGG (mark, '</MARK><MARK>') WITHIN GROUP (ORDER BY id)
                     || '</MARK></MARKS>'
                        xml
                FROM data
            GROUP BY code)

  • Can we use Data Pump to export data, using a SQL query, doing a join

    Folks,
    I have a quick question.
    Using Oracle 10g R2 on Solaris 10.
    Can Data Pump be used to export data, using a SQL query which is doing a join between 3 tables ?
    Thanks,
    Ashish

    Hello,
    No , this is from expdp help=Y
    QUERY                 Predicate clause used to export a subset of a table.
    Regards

  • Parsing a txt doc and using the text to put into an arraylist

    so i have a sample doc like this:
    add name hairy; mass 4; species bird
    sort mass
    save myaddresses.txt
    so i would like to have a scanner read the above text and parse for words name, mass and species where it would store the word after it into an arraylist. there is a argument which reads the txt file. i also use a delimited to seperate out the variables.
    import java.util.*;
    import java.io.*;
    public class Animallog {
    public static void main (String [] args)throws Exception
    Animal a = new Person();
    name = a.getname();
    mass = a.getmass();
    species= a.getspecies();
    ArrayList <Animal> list = new ArrayList<Animal>();
    i=0;
    list.get(i).SetName();
    list.get(i).SetMass();
    list.get(i).SetSpecies();
    i++;
    break;
    File f = new File (args[0]);
    Scanner interactionsinput = new Scanner(f);
    interactionsinput.useDelimiter(";");
    nameinput = interactionsinput.next();
    if (nameinput.equalsIngnoreCase("name"))
    massinput = interactionsinput.next();
    if (massinput = equalsIgnoreCase("mass"))
    speciesinput = interactionsinput.next();
    if (speciesinput.equalsIgnoreCase("species"))
    so here i'm totally lost i'm surpose to parse this sample and put the data into the arraylist and a set of information for a single animal.
    }

    :o]
    Indeed, and it is important to notice the "like me" he added to it. If he had said Java to be too hard for newbies, there'd be enough proof that it isn't, because then there'd be no experts.

Maybe you are looking for