How to use Pl/sql block to edit check user input

Hi,
Please advise on PL/SQL Block code that could be used to Check User input from within a Loop and proceed conditionally based upon User Supplied compliant Input. Thanks in advance.

Hi,
yakub21 wrote:
You could use the ACCEPT to get user input and then assign the input to a variable that could then be verified.
I believe that anything is possible because we don't yet have proof that it is not!
I do have code that can accept user input. Is it PL/SQL code? Sybrand was clearly talking about PL/SQL:
sybrand_b wrote:
Pl/sql is for server side code, it is not a front end tool, and it is incapable of the functionality you describe.If you do have PL/SQL code that accepts user input, please post an example. A lot of people, including me, would be very interested.
Pass the user-input value to a variable and then assign that value to another variable from within a Declare of a PL/SQL Block.
The opportunity here is to figure a way to loop with user input until desired input is entered by the user before proceeding with the code. I'm using PL/SQL Block because I don't want the code to persist. I just want to run it as part of database configuration procedure. ThanksIt sounds like you're talking about SQL*Plus, which is a very poor tool for looping or branching.
It's possible, but it's not pretty. The following thread shows one way of looping in SQL*Plus:
Re: How to give the different values to runtime parameters in a loop?

Similar Messages

  • How to Use Dynamic SQL

    Can anybody please send me a small program on How to Use Dynamic SQL.
    How to execute and run give details.
    Thanks
    null

    You can certainly use the INTO (and USING) clauses of EXECUTE IMMEDIATE to pass in and return data, i.e.
    EXECUTE IMMEDIATE sqlStmt
      USING variable1, variable2
       INTO output1, output2The more complex the statement, however, the more appropriate DBMS_SQL is. DBMS_SQL also has the potential to allow you to use bind variables rather than reparsing the statement many times.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Hi experts, how to use open sql to read data from one " maintenance view"?

    i want to use this part of data within report ,so how to use open sql statement to read data from one " maintenance view"?

    Hi
    You can't use OPEN SQl statements to fetch data from maintenance view
    You have to use only Database views
    see the different types of views and the difference
    The followings are different types of views:
    - Database View (SE11)
    Database views are implement an inner join, that is, only records of the primary table (selected via the join operation) for which the corresponding records of the secondary tables also exist are fetched. Inconsistencies between primary and secondary table could, therefore, lead to a reduced selection set.
    In database views, the join conditions can be formulated using equality relationships between any base fields. In the other types of view, they must be taken from existing foreign keys. That is, tables can only be collected in a maintenance or help view if they are linked to one another via foreign keys.
    - Help View ( SE54)
    Help views are used to output additional information when the online help system is called.
    When the F4 button is pressed for a screen field, a check is first made on whether a matchcode is defined for this field. If this is not the case, the help view is displayed in which the check table of the field is the primary table. Thus, for each table no more than one help view can be created, that is, a table can only be primary table in at most one help view.
    - Projection View
    Projection views are used to suppress or mask certain fields in a table (projection), thus minimizing the number of interfaces. This means that only the data that is actually required is exchanged when the database is accessed.
    A projection view can draw upon only one table. Selection conditions cannot be specified for projection views.
    - Maintenance View ( SE54 )
    Maintenance views enable a business-oriented approach to looking at data, while at the same time, making it possible to maintain the data involved. Data from several tables can be summarized in a maintenance view and maintained collectively via this view. That is, the data is entered via the view and then distributed to the underlying tables by the system.
    Please have a look at below link. It will help you.
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ed06446011d189700000e8322d00/frameset.htm
    for more detailed info look on:
    http://www.sap-img.com/abap/what-is-the-different-types-and-usage-of-views.htm
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/abap+dictionary&
    Reward points for useful Answers
    Regards
    Anji

  • How to use Try Catch Block in ABAP Like JAVA

    Hi Experts,
       I am using BAPI to post MIGO in one of my application. If the MIGO is successfully gets posted then BAPI returns no message, but if there is some error in posting then it returns an error message. Now I want to print that error message in catch block by calling method RAISE_ERROR_MESSAGE. How to use try catch block in ABAP. Please suggest with example.
    Thanks and Regards.
    Vaibhav Tiwari.

    Hi Vaibhav
    You may not catch exceptions returned by function module using try endtry block.
    It works well with the exception returned by methods.
    In case of function modules or BAPI what u can do is to check sy-subrc returned and give message accordingly. If it returns a structure like bapireturn then display message returned.
    in case of exception returned by a method,  do it like this...
    data: excep type cx_root.
    data: v_str type string.
    try.
    *any method call or division by zero (for ex)
    catch cx_root into excep.
    endtry.
    if  excep is not initial.
    CALL METHOD   excep->if_message~get_text
      receiving
        RESULT = v_str.
    endif.
    *display the value returned in v_str on screen

  • How to use self-signed Certificate or No-Check-Certificate in Browser ?

    Folks,
    Hello. I am running Oracle Database 11gR1 with Operaing System Oracle Linux 5. But Enterprise Manager Console cannot display in Browser. I do it in this way:
    [user@localhost bin]$ ./emctl start dbconsole
    The command returns the output:
    https://localhost.localdomain:1158/em/console/aboutApplication
    Starting Oracle Enterprise Manager 11g Database Control ... ...
    I open the link https://localhost.localdomain:1158/em/console/aboutApplication in browser, this message comes up:
    The connection to localhost.localdomain: 1158 cannot be established.
    [user@localhost bin]$ ./emctl status dbconsole
    The command returns this message: not running.
    [user@localhost bin]$ wget https://localhost.localdomain:1158/em
    The command returns the output:
    10:48:08 https://localhost.localdomain:1158/em
    Resolving localhost.localdomain... 127.0.0.1
    Connecting to localhost.localdomain|127.0.0.1|:1158... connected.
    ERROR: cannot verify localhost.localdomain's certificate, issued by `/DC=com/C=US/ST=CA/L=EnterpriseManager on localhost.localdomain/O=EnterpriseManager on localhost.localdomain/OU=EnterpriseManager on localhost.localdomain/CN=localhost.localdomain/[email protected]':
    Self-signed certificate encountered.
    To connect to localhost.localdomain insecurely, use `--no-check-certificate'.
    Unable to establish SSL connection.
    A long time ago when I installed Database Server Oracle 11gR1 into my computer, https://localhost.localdomain:1158/em in Browser comes up this message:
    Website certified by an Unknown Authority. Examine Certificate...
    I select Accept this certificate permanently. Then https://localhost.localdomain:1158/em/console/logon/logon in Browser displays successfully.
    But after shut down Operating System Oracle Linux 5 and reopen the OS, https://localhost.localdomain:1158/em/console/logon/logon in Browser returns a blank screen with nothing, and no more message comes up to accept Certificate.
    My browser Mozilla Firefox, dbconsole, and Database Server 11gR1 are in the same physical machine.I have checked Mozilla Firefox in the following way:
    Edit Menu > Preferences > Advanced > Security > View Certificates > Certificate Manager > Web Sites and Authorities
    In web sites tab, there is only one Certificate Name: Enterprise Manager on localhost.localdomain
    In Authorities tab, there are a few names as indicated in the above output of wget.
    My question is: How to use self-signed certificate and no-check-certificate in Mozilla Firefox for EM console to display ?
    Thanks.

    Neither problem nor solution do involve Oracle DB
    root cause of problem & fix is 100% external, detached, & isolated from Oracle DB.
    This thread is OFF TOPIC for this forum.

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • Using PL/SQL Block how do you check if the character string value is aA-zZ

    I have a pl/sql block that I prompt the user for password and I load the string into an array and interrogate each index(entry) to see if it is "aA-zZ".
    How can I check if the value entered is Alpha.
    I need to do the same for number and Special character. Please advise. Thanks

    Thanks to All of you. The desired solution to verify complex password that enforces desired security policies. An example that I am using is the following:
    IF NOT (regexp_like(sz_complex_pw,'[[:digit:]]') AND regexp_like(sz_complex_pw,'[[:alpha:]]') AND regexp_like(sz_complex_pw,'[[:punct:]]') AND regexp_like(sz_complex_pw,'[[:upper:]]'))
    THEN
    --dbms_output.put_line('Password is not complex...');
    RAISE sz_err_pw_complex; -- Complex Password is not compliant
    END IF;
    DBMS_OUTPUT.PUT_LINE('Complex Password is in Compliance...');
    EXCEPTION
    This was helpful to me and I trust others will find helpful.
    Edited by: yakub21 on Oct 16, 2010 9:05 PM

  • How to update PL/SQL block/Specs in Repository without cut/paste ?

    (cross-posted in METALINK form also)
    Hello,
    Question: How to quickly update PL/SQL block/specs in a package
    Repository Object Browser? (without cut/paste)
    Tools: Designer 9i, ROB 9.0.2.6
    Detailed description of a problem:
    -- there is no good pl/sql IDE working with ROB
    (JDeveloper can not work with NOT PRIVATE repository workspace)
    -- I use Toad and develop/generate pl/sql object
    directly in database.
    -- I have to synchronize my work with repository as often
    as possible the following way (we do not use read-server model
    because afraid of getting 1000s of atomik func and proc):
    ---- navigate to the pl/sql package
    ---- select properties
    ---- click on pl/sql block - get old code in editor
    ---- copy all new code from Toad into editor
    ---- remove CREATE OR REPLACE and last line
    ---- save
    ---- do the same with specifications
    I am looking for some way to do this with some script or
    one-button click...
    For example, for text files it is possible to use command line
    Repository Tool. But I did not found the possibility to make
    a script like this:
    checkout
    update workarea/container/plsql_definition/package_name/body....
    .....with new_package_body.txt
    checkin
    Thanks in advance for any help/advice,
    Alex V.

    Hi Alex,
    I just had an "Ah! I see!" moment. I now understand why you're having trouble and I can explain things so you can move on... I hope!
    First it's important to understand that Oracle SCM is designed to support versioning of both files and Oracle Designer objects. Designer objects are stored as rows in specially structured tables that support that specific product. When you look at PL/SQL definitions in the RON you're looking at Designer definitions - not files. As I mentioned before, these are not the definitions of 'real' PL/SQL objects in the data dictionary, but definitions used by Designer (from which the real things can be generated - but that's another story).
    If you're using TOAD you should probably avoid accessing the Designer objects. You need to work with files.
    Here's a suggestion for a sequence of operations:
    - In the RON check out & download the file (e.g. mypkg.plb)
    - In TOAD load the package (from DB, or downloaded file), edit, update package in DB
    - In TOAD save as mypkg.plb (overwriting the downloaded copy)
    - IN RON upload mypkg.plb and check in
    If you've not stored the file in Oracle SCM yet, jsut omit the first step.
    You could even automate this to an extent using SQL to query the data dictionary views (e.g. USER_SOURCE) after making changes to get the code and edit/overwrite the file contents that way.
    Does this help at all?
    Keith.

  • How to use PL/SQL & Forms6i for a logon screen

    i am new user to oracle. just wanna now how to create a user logon screen using SQL and Forms6i. well, i have created a table for logon with data item of username and password. in the form, i hava successfully created the data blocks but i don't know how to link them using PL/SQL or triggers or etc.
    ur concern will be very grateful. TQ.

    Hi MatrixMan
    Just create button and write the follwing inside
    trigger when_button_pressed :\
    begin
    logout;
    LOGON(:USER_NAME,:PASSWORD );
    IF FORM_SUCCESS THEN
    MESSAGE('Login Successful');
    MESSAGE('Login Successful');
    ELSE
    MESSAGE('Check username or password');
    MESSAGE('Check username or password');
    GO_ITEM('USER_NAME');
    :USER_NAME:=NULL;
    :PASSWORD:=NULL;
    END IF;
    end;
    Thanks
    Mohammed Al-shake

  • Item data using PL/SQL block region

    hello community,
    I have searched the whole forum using Pl/SQL but couldn't find an answer for this.
    I have a PL/SQL Anonymous block region, containing database items fetched by a process and custom items getting set by the Pl/SQL source.
    based on the ID I am getting the records i.e.
    Region Source (PL/SQL Anonymous block)
    declare
    CURSOR cpc_cur is SELECT "PRODUCT", "APPCODE", "COMCODE", "DESCRIPTION" from cp2 where "ID" = :P4_ID;
    begin
    for cpc_rec in cpc_cur
    loop
    :P4_P_NAME := cpc_rec.product;
    end loop;
    end;
    The custom item is text field with source Item.
    The item value is not filled in for the first time after login, but it shows the value in the session state as with status 'I', but from then onwards it works fine.
    Why is the value not fetched the first time?
    even I tried the postcalculation using nvl and it sets it to null.
    Also set_session state doesn't work.
    If I make the custom Item as Pl/SQL function, and write the query then it works fine, but gives problem as while inserting a new record the query has no ID to refer.
    Thanks in advance.
    Piyush

    Thanks Scott!!
    1) I am using PL/SQL region to get the data for few items on the form region which is based on a table, all table attributes are database items and additional Items whose data I am fetching from the PL/SQL are Custom items.
    2) Yes the loop executes only once per page view, Is their a better query?
    3) Well its very dumb to have a item source as item pointing to itself, but since the values are in session with status 'I' I thought this could do the trick!
    4) As the item source type used is [only..], the first time user logs in it doesn't displays the value, need to refresh the page, but the second time its gets the values form the session.
    5) If I make the Item source as PL/SQL function, I just fetch the records individually, same as in the query which works fine, but the items are also used for insertion (add new) and I clear the cache, so it gives error as it cannot execute the pl/sql function(no ID while addition)
    I hope I have answered your questions! If you have patience you can read the detail description.
    test application on oracle server
    http://apex.oracle.com/pls/otn/f?p=24296:1:3544773135949858:::::
    login/password test/test
    Application name :Test
    The page has 2 regions. when clicking on SN the values are transfered to form, except for 'Appcode'.
    Detail Description:
    I have a page with 2 regions.
    One region is a report region showing fewer details from a view. The other region is a PL/SQL(form region), which shows all the details and is linked to the report region.
    While linking I pass the ID from report and autofetch the data in form region.
    But some Items are not related to that database, so I created few items on form region (Custom Items). To fill in these values I did these things.
    1) Pass them through script (but passing 7 parameters through script is not good)
    2) Made another autofetch process to fetch the remaining Items, but it seems that its not possible to have 2 autofetch process on one form region.
    3) Changed the form type from HTML to PL/SQL, to assign the custom items values through code.
    for cpc_rec in cpc_cur
    loop
    :P_custom_item := cpc_rec.data;
    end loop;
    Either make source type static or Item (the same item P_custom_item).
    This pl/sql code do assign them the values, In the session state their status is 'I', but are not displayed on the page for the first login, need to refresh the page, as the source used is (only when..) it gets the value the second time.
    4) Made the item source as PL/SQL function and assign them the value. It works fine, but the same item is also used displaying description while insertion(gives error while insertion), so made a conditional process, even that gives the same error.
    I have a questions.
    If an Item status is 'I' in the session state, why is it not displaying the value on page.
    Thanking you in anticipation
    Piyush
    Message was edited by:
    user523112

  • How to use PL/SQL table

    Hi all,
    can you guys suggest me how can I use pl/sql tables for the below query to incresing the performance.
    DECLARE
        TYPE cur_typ IS REF CURSOR;
        c           cur_typ;
        total_val varchar2(1000);
        sql_stmt varchar2(1000);
        freeform_name NUMBER;
        freeform_id NUMBER;
        imgname_rec EMC_FTW_PREVA.EMC_Image_C_Mungo%rowtype;
        imgval_rec  EMC_FTW_PREVA.EMC_Content_C_Mungo%rowtype;
        CURSOR imgname_cur IS
            select * from EMC_FTW_PREVA.EMC_Image_C_Mungo
            where cs_ownerid in (
                        select id from EMC_FTW_PREVA.EMC_Image_C
                        where updateddate > '01-JUN-13'
                        and path is not null
                        and createddate != updateddate)
            and cs_attrid = (select id from EMC_FTW_PREVA.EMC_ATTRIBUTE where name = 'Image_Upload');
    BEGIN
        OPEN imgname_cur;
        LOOP
          FETCH imgname_cur INTO imgname_rec;
          EXIT WHEN imgname_cur%NOTFOUND;
          total_val := 'EMC_Image_C_' || imgname_rec.cs_ownerid;
          sql_stmt := 'SELECT instr(textvalue,''' || total_val || '''), cs_ownerid FROM EMC_FTW_PREVA.EMC_Content_C_Mungo a Where cs_attrid = (select id from EMC_FTW_PREVA.EMC_ATTRIBUTE where name = ' || '''' || 'Body_freeform' || '''' || ')';
            OPEN c FOR sql_stmt;
            LOOP
              FETCH c INTO freeform_id,freeform_name;
              EXIT WHEN c%NOTFOUND;
                                      IF freeform_id > 0 THEN
                dbms_output.put_line (imgname_rec.cs_ownerid || ',' || total_val || ',' || freeform_id || ',' || freeform_name);
                                      END IF;
            END LOOP;
            CLOSE c;     
       END LOOP;
       CLOSE imgname_cur;
    END;
    Thanks in Advance.

    can you guys suggest me how can I use pl/sql tables for the below query to incresing the performance.
    There would be absolutely no point at all in improving the performance of code that has NO benefit.
    The only result of executing that code is to possibly produce some lines of output AFTER the entire procedure if finished:
    dbms_output.put_line (imgname_rec.cs_ownerid || ',' || total_val || ',' || freeform_id || ',' || freeform_name);
    So first you need to explain:
    1. what PROBLEM you are trying to solve?
    2. why you are trying to use PL/SQL code to solve it.
    3. why are you using 'slow by slow' (row by row) processing and then, for each row, opening a new cursor to query more data?
    You should be using a single query rather than two nested cursors. But that begs the question of what the code is even supposed to be doing since the only output is going to a memory buffer.

  • How to use count sql statement?

    i've never used the count function and i'm not sure how to use it to print it onto a html page...my code is below...
    <%
    String tot = (String)session.getAttribute("total");
    int total = Integer.parseInt(tot);
    Class.forName("org.postgresql.Driver");
    // create connection url
    String URL2 = "jdbc:postgresql://dbhost/ug59sxn";
    // pass database parameters to JDBC driver
    Connection Conn2 = DriverManager.getConnection(URL2, "ug59sxn", "hupeswop");
    // query statement
    Statement SQLStatement2 = Conn2.createStatement();
    // generate query
    String Query2 = "SELECT COUNT(*) FROM userteam WHERE total > '"+total+"'";
    // get result code
    ResultSet SQLResult2 = SQLStatement2.executeQuery(Query2);
    int position = (int)SQLResult2 + 1;
    %>
    <TD valign=top>
    <P align=center><FONT size=+1>Welcome <%= session.getAttribute("fName") %> <%= session.getAttribute("surname") %><BR>
    Your Team, <%= session.getAttribute("teamname") %>, are currently lying in position <FONT color=red><% out.println(position) %></font>, with <FONT color=red><%= session.getAttribute("total") %></font> points.<BR>
    </FONT></P>
    <P align=justify>      Use the shorcuts on the left to visit different sections of the game.
    You can change your squad around to prepare for forthcoming games (fixtures can be found in the statistics section),
    transfer a player in to your squad to add some depth or replace injured members, or perhaps browse the statistics section to see how your team is doing in the FFL table.</P>
    <HR>
    <%
    SQLResult2.close();
    SQLStatement2.close();
    Conn2.close();
    %>
    i get the following errors:
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    An error occured between lines: 62 and 84 in the jsp file: /main2.jsp
    Generated servlet error:
    /home/students/ug/ug59sxn/servlets-local/work/localhost/myapp/main2$jsp.java:80: Invalid cast from java.sql.ResultSet to int.
    int position = (int)SQLResult2 + 1;
    ^
    An error occurred at line: 88 in the jsp file: /main2.jsp
    Generated servlet error:
    /home/students/ug/ug59sxn/servlets-local/work/localhost/myapp/main2$jsp.java:108: Invalid type expression.
    out.println(position)
    ^
    An error occurred at line: 88 in the jsp file: /main2.jsp
    Generated servlet error:
    /home/students/ug/ug59sxn/servlets-local/work/localhost/myapp/main2$jsp.java:111: Invalid declaration.
    out.write("</font>, with <FONT color=red>");
    ^
    3 errors, 1 warning
    if anyone can help me out, please do so..thanx in advance...

    You cannot cast a ResultSet object (or any other object for that matter) to a primitive (such as an int)
    Replace the following line of code:
    int position = (int)SQLResult2 + 1;with this:
    int position = 0;
    if(SQLResult2.next())
      position = SQLResult2.getInt(1) + 1;
    }Additionally I noticed that you have put single quotes around total in the following line:
    String Query2 = "SELECT COUNT(*) FROM userteam WHERE total > '"+total+"'";Are you sure that the total column in the userteam table is of string type? If not, you don't need the single quotes.

  • How to use Native SQL statement in JDBC receiver interface

    Dear All,
    Can any one please help us in using Native SQL statement in a JDBC receiver channel. The reason why I need to use Native SQL statement instead of standard XML structure is that I need to execute a dynamic SQL query in third party database system lke:-
    Select Field1 Field2 from TABLE Where Field3 like "%Name'
    I expect the the response in the form of XML file which I can pick up using synchornous interface as mentioned on help.sap.com:-
    http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    The value for %Name can change dynamically according to the transaction and hence cannot be inluded as a KEY element in standard XLM structure,
    Hence I need to know:-
    1. What message mapping I should use in case if I have to use Native SQL statement.
    2.What operation mapping I should use in case if I have to use Native SQL statement.
    If guess correclty I may have to use Java mapping to do the above activities. Hence I want to know
    3 .How do to go about it to do the Java mapping.
    Thanks
    Ameet

    >
    Ameet Deshpande wrote:
    > Dear All,
    >
    > Can any one please help us in using Native SQL statement in a JDBC receiver channel. The reason why I need to use Native SQL statement instead of standard XML structure is that I need to execute a dynamic SQL query in third party database system lke:-
    >
    > "
    > Select Field1 Field2 from TABLE Where Field3 like "%Name'
    > "
    > I expect the the response in the form of XML file which I can pick up using synchornous interface as mentioned on help.sap.com:-
    >
    > http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    > http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/frameset.htm
    >
    > The value for %Name can change dynamically according to the transaction and hence cannot be inluded as a KEY element in standard XLM structure,
    >
    > Hence I need to know:-
    >
    > 1. What message mapping I should use in case if I have to use Native SQL statement.
    > 2.What operation mapping I should use in case if I have to use Native SQL statement.
    > If guess correclty I may have to use Java mapping to do the above activities. Hence I want to know
    > 3 .How do to go about it to do the Java mapping.
    >
    > Thanks
    > Ameet
    You can use a stored procedure, and call it from jdbc receiver adapter.
    I also solve this issue, with a DBLookup in message mapping. You can refer to my blog, and this usefull 3d:
    http://simonlesflex.wordpress.com/2010/12/07/pi-oracle-dblookup/
    /people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
    /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler

  • 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;

  • How to convert pl/sql block into single update statement

    Dear all gurus,
    I have pl/sql block mention below, Can I convert this pl/sql block to single update statement if possible?
    If not how to optimize this block?
    Pleaese suggest.
    thanks in advance.
    Vijay
    DECLARE
    CURSOR vt_mlr_cursor IS Select master_key, user4 from vt_mlr Where USER4 is not null;
    USERFIELD VARCHAR2(100);
    C1 VARCHAR2(3); /* this will return location of first space = 12 */
    C2 VARCHAR2(3); /* this will return location of second space = 20 */
    C3 VARCHAR2(3); /* this will return location of third space = 28 */
    C4 VARCHAR2(3); /* this will return location of forth space = 35 */
    Field1 VARCHAR2(40); /* this will return FTMYFLXA04W */
    Field2 VARCHAR2(10); /* this will return VPI0043 */
    Field3 VARCHAR2(10); /* this will return VCI0184 */
    Field4 VARCHAR2(10); /* this will return 005 */
    Field5 VARCHAR2(10); /* this will return 00001 */
    Field_2_n_3 VARCHAR2(25);
    key VARCHAR2(10);
    BEGIN
    FOR vt_mlr_record IN vt_mlr_cursor
    LOOP
    key := vt_mlr_record.master_key;
    USERFIELD := vt_mlr_record.user4;
    C1 := INSTR(vt_mlr_record.user4,' ',1,1); /* this will return location of first space = 12 */
    C2 := INSTR(vt_mlr_record.user4,' ',1,2); /* this will return location of second space = 20 */
    C3 := INSTR(vt_mlr_record.user4,' ',1,3); /* this will return location of third space = 28 */
    C4 := INSTR(vt_mlr_record.user4,' ',1,4); /* this will return location of forth space = 35 */
    Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1); /* this will return FTMYFLXA04W */
    Field2 := SUBSTR(vt_mlr_record.user4,C1+4,C2-C1-4); /* this will return VPI0043 */
    Field3 := SUBSTR(vt_mlr_record.user4,C2+4,C3-C2-4); /* this will return VCI0184 */
    Field4 := SUBSTR(vt_mlr_record.user4,C3+4,C4-C3-4); /* this will return 005 */
    Field5 := SUBSTR(vt_mlr_record.user4,C4+4,LENGTH(vt_mlr_record.user4)-C4-3); /* this will return 00001 */
    Field_2_n_3 := Field2 || '/' || Field3;
    /*DBMS_OUTPUT.PUT_LINE ('Current key is: ' || vt_mlr_record.master_key);*/
    UPDATE vt_mlr
    SET
    aggregator_clli = Field1,
    aggregator_vpi_vci = Field_2_n_3,
    aggregator_slot = Field4,
    aggregator_port = Field5
    WHERE
    master_key = vt_mlr_record.master_key;
    END LOOP;
    END;
    /

    Hi Vijay,
    Here's something to start with, you should be able to complete it.
    First, combine your select and update statements:
    update vt_mlr
       set aggregator_clli = field1
          ,aggregator_vpi_vci = field_2_n_3
          ,aggregator_slot = field4
          ,aggregator_port = field5
    where user4 is not null;Then put these two
    C1 := INSTR(vt_mlr_record.user4,' ',1,1); 
    Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1);into
    Field1 := SUBSTR(vt_mlr_record.user4,1,INSTR(vt_mlr_record.user4,' ',1,1) -1);And put it into the update statement, removing reference to record
    (I have also removed default values for position and occurrence in instr function):
    update vt_mlr
       set aggregator_clli = substr(user4, 1, instr(user4,' ') - 1)
          ,aggregator_vpi_vci = field_2_n_3
          ,aggregator_slot = field4
          ,aggregator_port = field5
    where user4 is not null; I think you can do the rest from here ;-)
    Regards
    Peter

Maybe you are looking for

  • How can i Know the email linked to icloud

    Please can anyone help me how to know teh email linked to my phone ?? it shows me h********@hotmail.com i tried to logged in with my account that belong to h********@hotmail.com and it says inocrrect password or email i tried to reset my id but no re

  • Which Power Adaptor

    Hi guys, I have an iBook G4 (late 2004) and stupidly left the power adaptor in a hotel last weekend. I am looking to get a replacement, but having trouble figuring out which to get - the 45w or 65w adaptor. The tech page below seems to suggest the 45

  • Delivery Quantity

    Hi All, Iam working in version 4.7. Iam Using RM_DELIVERY_CREATE function module to create delivery for a SALE ORDER. But After creation delivery if i go to VL03n transaction , DELIVERY QUANTITY field is showing '0' and OPEN QUANTITY field is showing

  • Another Deploy problems

    when i deploy the sample of convetor,occur such errors: there was a deployment error java.rmi.ServerException:RemoteException occurred in server thread;nested exception is: java.rmi.RemoteException : An error was encountered while loading a web compo

  • Several unrelated issues

    I have several unrelated issues. 1) My computer recently started failing to startup. It flashes an image of a globe, and then an image of a finder folder alternated with a questionmark, and then, if I'm lucky, proceeds to normal start up. What is goi