How to string concatination in pl/sql

I'm working on
   
 IF LENGTH(v_final_string) < 3800 THEN
        SELECT nvl2(v_final_string,v_final_string
          ||',' ,v_final_string)
          || temp.temp_string
        INTO v_final_string
        FROM DUAL;
        DBMS_OUTPUT.put_line ('v_final_string=' || v_final_string );
      ELSE
        EXIT;
      END IF;
inside a loop. But it is not concatenate. I'm alwas empties v_final_string

Hello

Always show a complete script that people can run to recreate the problem and test their ideas.

Beginning of v_final_string is null?
If so, the condition

IF LENGTH(v_final_string) < 3800

won't be TRUE.

I think you want something like:

...
IF  v_final_string  IS NULL
THEN
    v_final_string := temp.temp_string;
ELSIF  LENGTH (v_final_string) < 3800
THEN
    v_final_string := v_final_string
                 || ','
             || temp.temp_string;
ELSIF
    EXIT;
END IF;

or

...
v_final_string := v_final_string
            || ','
            || temp.temp_string;

IF  LENGTH (v_final_string) >= 3800
THEN
    v_final_string := LTRIM (v_final_string, ',');
    EXIT;
END IF;

I prefer the second way. Since then he has not test if v_final_string is NULL each time through the loop, it will probably be a little faster.

It is rarely needed the double table in PL/SQL.

Tags: Database

Similar Questions

  • How to use my bellows PL/SQL PROCEDURE to export data to a directory with a button in the ADF?

    Mr President.

    Any body give me advice step by step that how can I use my pl/sql below procedure to take the small schema oracle backup with a touch of the adf.

    DECLARE  
       h1   NUMBER;  
       dt   VARCHAR2 (20);  
       myschema VARCHAR2(32):='SCOTT';  
    BEGIN  
       SELECT TO_CHAR (SYSDATE, 'YYYYMMDD')  
         INTO dt  
         FROM DUAL;  
      
      
       h1 :=  
          DBMS_DATAPUMP.OPEN (operation      => 'EXPORT',  
                              job_mode       => 'SCHEMA',  
                              job_name       => myschema||'_EXP_' || dt,  
                              VERSION        => 'COMPATIBLE'  
                             );  
       DBMS_DATAPUMP.set_parallel (handle => h1, DEGREE => 1);  
       DBMS_DATAPUMP.add_file (handle         => h1,  
                               filename       => myschema||'_EXP.LOG',  
                               DIRECTORY      => 'ADMIN_DIR',  
                               filetype       => 3  
                              );  
       DBMS_DATAPUMP.set_parameter (handle      => h1,  
                                    NAME        => 'KEEP_MASTER',  
                                    VALUE       => 0  
                                   );  
       DBMS_DATAPUMP.metadata_filter (handle      => h1,  
                                      NAME        => myschema||'_EXPR',  
                                      VALUE       => 'IN('''||myschema||''')'  
                                     );  
       DBMS_DATAPUMP.add_file (handle         => h1,  
                               filename       => myschema||'_EXP_' || dt || '.DMP',  
                               DIRECTORY      => 'DATA_PUMP_DIR',  
                               filetype       => 1  
                              );  
       DBMS_DATAPUMP.set_parameter (handle      => h1,  
                                    NAME        => 'INCLUDE_METADATA',  
                                    VALUE       => 1  
                                   );  
       DBMS_DATAPUMP.set_parameter (handle      => h1,  
                                    NAME        => 'DATA_ACCESS_METHOD',  
                                    VALUE       => 'AUTOMATIC'  
                                   );  
       DBMS_DATAPUMP.set_parameter (handle      => h1,  
                                    NAME        => 'ESTIMATE',  
                                    VALUE       => 'BLOCKS'  
                                   );  
       DBMS_DATAPUMP.start_job (handle => h1, skip_current => 0, abort_step => 0);  
       DBMS_DATAPUMP.detach (handle => h1);  
    END;  
    /  
    
    
    

    Concerning

    Hello world!

    It's the simple code to call an appModule procedure

        public void callStoreprocedureWithoutInput() {
                String stmt = "BEGIN\n" +
                "  \"dbBackup\"();\n" +
                "--rollback; \n" +
                "END;";
                PreparedStatement st = null;
                try {
                    st = getDBTransaction().createPreparedStatement(stmt, 0);
                    st.executeUpdate();
                    st.close();
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
    

    Concerning

  • a single comparison string and get pure SQL strings,

    Hi all

    These are two strings

    S1 = "HAS, B, C, D, F;
    S2 ='C, F, H, B, A, K';

    output should be like unique string values.

    S3 = A, B, C, D, F, H, K;


    How to get this in pure sql...

    Thanks in advance,

    Roots

    Hello

    In a relational database, each column of each row needs to store a value, not a repleating group of values, such as a delimited list. It is so basic to the design of database it is called "First Normal Form." You don't have to follow the rules like that, but if you do not, your code will be complicated, inefficient and prone to errors. It might be better to re-design your application so that each value was on a separate line.

    If you can't do that, then you can start by dividing your lists of delimitd in separate lines. Then you can easily fond distinct values and use any technique of chain aggregation to combine the results into an output line.
    Here's a way to do this:

    WITH     got_params     AS
    (
         SELECT     'A,B,C,D,F' AS str, 1 AS str_id     FROM dual     UNION ALL
         SELECT     'C,F,H,B,A,K',          2            FROM dual
    )
    ,     got_part_cnt     AS
    (
         SELECT     str
         ,     1 + LENGTH (str)
                - LENGTH (REPLACE (str, ','))     AS part_cnt
         FROM    got_params
    )
    ,     cntr          AS
    (
         SELECT     LEVEL     AS n
         FROM     (
                  SELECT  MAX (part_cnt)     AS max_part_cnt
                  FROM    got_part_cnt
              )
         CONNECT BY     LEVEL     <= max_part_cnt
    )
    ,     got_substr     AS
    (
         SELECT DISTINCT
                REGEXP_SUBSTR ( p.str
                               , '[^,]+'
                        , 1
                        , c.n
                        )          AS sub_str
         FROM    got_part_cnt p
         JOIN     cntr          c  ON     c.n     <= p.part_cnt
    )
    ,     got_r_num     AS
    (
         SELECT     sub_str
         ,     ROW_NUMBER () OVER (ORDER BY  sub_str)     AS r_num
         ,     ROWNUM                                        AS r
         FROM     got_substr
    )
    SELECT     MIN ( SUBSTR ( SYS_CONNECT_BY_PATH (sub_str, ',')
                          , 2
                          )
             )          AS unique_sub_strs
    FROM    got_r_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    -- START WITH     r_num     = 1
    CONNECT BY     r_num     = 1 + PRIOR r_num
    ;
    

    It works in 10.2.0.2.0 Oracle Express Edition, which is the only database, can I use it right now. For the main query, you should be able to say:

    SELECT     SUBSTR ( SYS_CONNECT_BY_PATH (sub_str, ',')
                , 2
                )     AS unique_sub_strs
    FROM    got_r_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     r_num     = 1
    CONNECT BY     r_num     = 1 + PRIOR r_num
    ;
    

    but, when I try it on my database, I get only "A, B" as output. CONNECT is very buggy in Oracle 10.2; If you have Oracle 10.1, simplest form might work.

    The above query can be shortened, some, but I wrote it this way to make it easier to understand.
    For example, you can combine got_sub_str and got_r_num subqueries. If you do so, substitute DENSE_RANK, ROW_NUMBER.

    This does not imply that the sub-qtrings are all 1 characters long. If they are, the query can be simplified.

    For more information on aggregation of chain, see
    http://www.Oracle-base.com/articles/10G/StringAggregationTechniques.php

  • How convert string to number

    How convert string to number


    my character


    Select form double to_number ('1,6,9,4'); my putting here 1,6,9,4

    get the character of number conversion error.

    concerning

    Published by: vr on March 31, 2011 23:59

    Published by: vr on March 31, 2011 23:59

    VR says:
    Getting error while the conversion of character to the number in instring is possible to get the position of the channels at one time

    I have the following table, called pack

    Acct_No pack2 pack3 pack1
    1000 10101011 111111101 01010101111

    Select * Pack
    where instr (pack2, ' 1') and * (to_number (replace('1,6,9,4',','))); * - getting values of function as string '1,6,9,4'

    If you want to retrieve lines where the position of the first "1" in the pack2 chain is one of the positions in your list number e.g. position 1, 6, 9, or 4?

    Something with regexp_like can help...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with pack as (select '1000' as acct_no, '10101011' as pack1, '111111101' as pack2, '01010101111' as pack3 from dual union all
      2                select '1001', '10101011', '000011111', '10101010110' from dual union all
      3                select '1001', '10101011', '000000001', '10101010110' from dual)
      4  --
      5  -- end of test data
      6  --
      7  select pack.*, case when regexp_like('1,6,9,4','(^|,)'||to_char(instr(pack2,'1'),'fm9999')||'(,|$)') then 'Yes' else 'No' end as x
      8* from pack
    SQL> /
    
    ACCT PACK1    PACK2     PACK3       X
    ---- -------- --------- ----------- ---
    1000 10101011 111111101 01010101111 Yes
    1001 10101011 000011111 10101010110 No
    1001 10101011 000000001 10101010110 Yes
    
  • How to enable a connection to SQL Denali remotely?

    How to enable a connection to SQL Denali remotely?

    Hello

    Your question of Windows is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the public on the TechNet site. Please post your question in the below link:

    http://social.technet.Microsoft.com/forums/en-us/category/SQLServer

  • How can I expose a PL/SQL package to a webservice

    Hello

    Using Jdeveloper 12 c, how can I expose a PL/SQL package as a webservice?

    Thanks in advance

    Look for the option 'Web of TopLink-DB services provider' under the section of Web Service in the new gallery.

    Timo

  • How to run DBMS_SQLTUNE.report_sql_monitor of SQL Developer 4.0

    Hello-

    We have new SQL Developer 4.0 as a single stop for all reports of performance tuning.

    (So far, we know how to generate the AWR and ASH ADDM directly from SQL DEV 4.0 and we can do as a NON-privileged user)

    Now, the question is how to run DBMS_SQLTUNE.report_sql_monitor API SQL DEV 4.0?

    I tried this way:

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    SELECT DBMS_SQLTUNE.report_sql_monitor)

    sql_id = >: SQL_ID

    Type = > 'TEXT ',.

    report_level = > 'ALL') AS myreport

    DOUBLE;

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    and then right button click of the mouse on the line "myreport" and the EXPORT of 'text' in the menu drop down and save in the. FichierTSV on the local file system.

    It works this way, as expected, but seems to be a lot of hassle: too many steps.

    Then I tried the HTML format:

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    SELECT DBMS_SQLTUNE.report_sql_monitor)

    sql_id = >: SQL_ID

    Type = > 'HTML. "

    report_level = > 'ALL') AS myreport

    DOUBLE;

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    and it didn't work well at all SQL dev 4.0

    Any help will be greatly appreciated.

    (once again, the idea here is to set up our development and QA groups with full access to performance all reports without having them call DBA for help in the production of any SQL tuning report).

    Thank you

    VR

    There is certainly a 'room' to improve the interface, just tell me what you would like to be like him. For example, you want an overview of the SGS of all SQLIDs running on the nodes you could then select this option to run a report for? Don't say it is what we would do, but I was wondering what it is that you ask for.

  • How do I get all the SQL executed by my session?

    How do I get all the SQL executed by my session?

    Published by: user11300376 on 01/28/2013 11:27

    user11300376 wrote:
    I had tried, brings itself however only select table v $ session.

    Executed orders:

    SELECT * FROM MBS_ITEM;

    SELECT b.sql_id, b.sql_text
    SESSION $ v a, v$ sql b
    WHERE a.sql_id = b.sql_id;

    The output result:

    SQL_ID SQL_TEXT
    1 4qg3bft0w37rt SELECT b.sql_id, b.sql_text FROM session $ v a, v$ sql b WHERE a.sql_id = b.sql_

    The listed application is good, but does not limit the output of your session - it should return data from all sessions.

    You must add an AND condition in the WHERE clause to limit your session. You can try this (untested)

     where audsid=(select userenv('sessionid') from dual);
    

    You can also perform a SQL trace and tkprof to obtain data to SQL executed the trace start and end of the trace.

  • How can I save cfquery text sql, not the results

    Hello

    I have the need to save a dynamically generated real sql, cfquery, not the results.

    I can see it in < cfdump var = "# < qry_name > #" > but, how can I capture the real sql

    and save it in a var for later use?

    Thank you

    Bob

    The property of the results of the tag to put this information in a variable for later use.

    I.E.

    ...
    
    
  • How to generate Trace files in SQL * more

    Hi friends,

    How to generate Trace files in SQL * more?

    I have no idea



    Thank you

    REDA

    http://www.orafaq.com/wiki/SQL_Trace

  • How to create a connection for Toolkit CVI/SQL string when connecting to SQL Server 2008

    I tried to connect to my database of MS SQL Server 2008 for two days using the CVI/SQL Toolbox with no luck.  I use the function of connection BD and I tried a lot of different formats for the connection string with no luck.  I get an error "SQL Server doesn't exist or the access denied" after a long pause, trying to connect.  Anyone know what's the right format for this string?  I even setup of SQL Server on my local machine and I still not able to get the right format for the connection string.

    -Tom

    I have successfully connected to the database, I thank you all for your help.  It was a combination of errors of syntax and configurations that had to be changed.

  • How to integrate string literals in pl/sql?

    DECLARE

    message from varchar2 (50): = "that"s tutorialspoint.com!";

    BEGIN

    dbms_output.put_line (message);

    END;

    /

    I have to out put like this below, but when I try to do it doesn't display any output.... plz suggest what might be wrong in this code?

    output

    It's tutorialspoint.com!

    Dsrc00 wrote:

    DECLARE

    message from varchar2 (50): = ' that "s tutorialspoint.com!';    / * change * /.

    BEGIN

    dbms_output.put_line (message);

    END;

    /

    I have to out put like this below, but when I try to do it doesn't display any output.... plz suggest what might be wrong in this code?

    output

    It's tutorialspoint.com!

    Hello

    Single quote, you need to put at the beginning and end of a string.

  • How to do the Validation of SQL in extended OT?

    Hello

    I'm new to OFA. I have a requirement on a Page of the OAF that when a new record is created system must check whether the same value already exists in one of our custom paintings, then it should trigger a warning.

    I guess I have to code this extended logic in OT. I checked the examples in tutorial Toolbox of framework in which they use VVO and experts of the entity to do Validation based on SQL, but how can I do in extended OT?

    Can we do direct SQL calls in OT?

    Can someone please?

    Hey Hi there,

    At the click of a button, you can get the handle to the action of submit and use the code to validate if the record already exists below

    String codeUpper = pageContext.getParameter ('Code'); get your field values

    String actionUpper = pageContext.getParameter ("Action");

    String seqNoUpper = pageContext.getParameter ("PacelineStdSeqNum");

    If (PageContext.GetParameter ('Save')! = null)

    {

    context of the page get the value of the code and action.

    String codeValue = pageContext.getParameter ('Code');

    String actionValue = pageContext.getParameter ("Action");

    String stdSeqNumValue = pageContext.getParameter ("PacelineStdSeqNum");

    declare the variable to count the number of records returned by the query.

    int result = 0;

    get the JDBC connection.

    Connection Conn = pageContext.getApplicationModule (webBean) .getOADBTransaction () .getJdbcConnection ();

    Try

    {

    Query to check the combination for the records.

    Dim Query = ' SELECT count (*) count of SDA_PACELINE_STD where CODE =: AND ACTION = 1: 2.

    PreparedStatement stmt = conn.prepareStatement (Query);

    stmt.setString(1, codeValue);

    stmt.setString (2, actionValue);

    for (ResultSet resultset = stmt.executeQuery (); resultset.next ();)

    {

    pageContext.writeDiagnostics (Thi, "query Executed", 1);

    pageContext.writeDiagnostics (Thi, "query Executed", 2);

    result = resultset.getInt ('count');

    pageContext.writeDiagnostics (this, 'query Executed' + result, 1);

    pageContext.writeDiagnostics (this, 'query Executed' + result, 2);

    }

    }

    catch (System.Exception Exception)

    {

    Incase of any error during execution of the statement to throw an exception.

    throw new OAException ("Error in the application of staffing" + exception, OAException.ERROR);

    }

    if(result >0) / / result > 0 indicates that there is a combination record already

    {

    throw new OAException ("The Record combination already exists", OAException.INFORMATION);

    }

    Let me know if this isn't clear.

    -Had

  • How to hide password when calling sql, more than command promt?

    When I try to open sql more in the window command prompt and enter the command sqlplus by chain of username/password@connection followed, the password is not masked.
    How do I show * instead of display characters of password out?

    Also, what is the command to clear the screen: when I try to cls or clears the screen, I get an exception memory windows of somekind and the only option he must kill the command window.

    Advice on her work around this?

    Thank you very much for your time and help.

    user8848256 wrote:
    Can you please give more details on how to do not enter a password when you call sqlplus command window, as you say?

    I tried this:

    sqlplus username / @connection string--> Hit Enter: request password, it does not recognize the connection string to connect to.

    sqlplus username /--> Hit Enter: it does same thing again.asks password but gives AMT error adapter after you have entered the password.

    Leave aside the slash:
    sqlplus username@connect_string

  • How to read the BIT of SQL Server value in CVI

    Hello

    I try to get a value of SQL Server 2005 (ture or false) bit in CVI (with SQL toolkit). I use the DBBindInt, but overall the return value is - 1.

    How can I get the real value of SQL?

    Thanks for your help

    Region

    Do you mean that you never receive the value FALSE, IE 0? Or you expect a TRUE value to be exactly 1? It is very common for TRUE to be represented as -1; If you are concerned just hide all the bits in the value returned with the exception of bit 0 - this will then give your alternative 0/1.

    JR

Maybe you are looking for

  • Want to join a wireless printer in XP Media Center Edition 2004.

    Original title: XP Media Center Edition 2004? Can I attach a printer wireless with XP Media Center Edition 2004?

  • More driver problems

    I am running Vista Home Premium.  I have two questions regarding the installation of the drivers. Windows tells me I don't need to update the driver for the modem, but according to Dell, I need to update. Who should I believe?  Second, Windows Update

  • Windows 7 left me after death without password

    My father-in-law just died & it linked its two computers of the family business. 1, it's an hp pavilion p6714y desktop running windows 7 Home Edition premium, the other is an asus laptop running windows 8.1. the problem here is none of the discs or p

  • Windows 7 Media Center no longer works

    I have an existing facility that has stopped working. I tried to turn off windows media, and referred to an earlier date he was working, tried scanning, tried all the suggestion that nothing seems to work. Comment is the Media Center has stopped work

  • Ignore existing data using impdp

    Hi allPlease let know us if there are ways to import data without replacing these existing rows of data.For example, if Mapping_id is the primary keyImported tableMapping_id name1                    John2 Peter3                    MaryTarget tableMap