WHILE Loop - NEW TO ORACLE & SQL

I was assigned a task to loop through an organization heirachy drill until a certain a value is reached. What I mean by this is that I have to select three fields from a ORGN table to find the correct ORGN_CODE: ORGN_CODE, ORGN_CODE_PRED, ORGN_ID.
I need to be able to check if ORGN_ID = 'CONVERT'.
If it is true, then I need run another select statement where ORGN_CODE_PRED = ORGN_CODE. Then I check if ORGN_ID = 'CONVERT' again. Eventually, ORGN_ID <> 'CONVERT' and I have successfully drilled down to the correct ORGN_CODE Level. I'll then need to create a new field and insert the value into a table
I can run a basic query but when it comes to this functionality, I'm rather new. Here is my select statement to bring in the data the first time.
select ftvorgn_orgn_code as ORG_CODE,
ftvorgn_orgn_code_pred as PREDECESSOR,
ftvorgn_user_id as NEXT_PREDESSOR
from ftvorgn
The way "I think" I need to do this is like this:
Declare
MyORG Integer
MyValue Char(10)
Declare ORG_CURSOR for
select ftvorgn_orgn_code as ORG_CODE,
ftvorgn_orgn_code_pred as PREDECESSOR,
ftvorgn_user_id as NEXT_PREDESSOR
from ftvorgn
Declare NEW_ORG_CURSOR for
select ftvorgn_orgn_code as ORG_CODE,
ftvorgn_orgn_code_pred as PREDECESSOR,
ftvorgn_user_id as NEXT_PREDESSOR
from ftvorgn
where ftvorgn_orgn_code = MyORG
Open ORG_CURSOR
Fetch Next from ORG_CURSOR
WHILE (NOT SURE WHAT GOES HERE)
Begin
If NEXT_PREDECESSOR = 'CONVERT'
set MyORG = ORGN_CODE
set MyValue = 'CU'||ORGN_CODE
{Have to work on code to insert into table}
ELSE
set MyORG = ORGN _CODE
Open NEW_ORG_CURSOR
Fetch Next from NEW_ORG_CURSOR
WHILE (NOT SURE WHAT GOES HERE)
Begin
If NEXT_PREDECESSOR = 'CONVERT'
set MyORG = ORGN_CODE
set MyValue = 'CU'||ORGN_CODE
{Have to work on code to insert into table}
Else
set MyORG = ORGN _CODE
Open NEW_ORG_CURSOR
Fetch Next from NEW_ORG_CURSOR
End
End
Close ORG_CURSOR
Close NEW_ORG_CURSOR
Deallocate ORG_CURSOR
Deallocate NEW_ORG_CURSOR
GO
I can only imagine how horrible this looks to average ORACLE DB/SQL programmer and would appreciate any help on this. I'm scheduled from some training down the road, but for now I'm trying to learn on my own.
Thanks for any constructive feedback and input.

I've tried this code with the following results:
select ftvorgn_orgn_code, ftvorgn_orgn_code_pred, ftvorgn_user_id,
substr(sys_connect_by_path(ftvorgn_orgn_code,'-'),2) as path
from ftvorgn
connect by ftvorgn_orgn_code = prior ftvorgn_orgn_code_pred
start with ftvorgn_ORGN_CODE = '530340' and ftvorgn_user_id <> 'CONVERT'
FTVORGN_ORGN_CODE     FTVORGN_ORGN_CODE_PRED     FTVORGN_USER_ID     PATH
530340     F00602     SUAGUILA     530340
F00602     E00602     CONVERT     530340-F00602
E00602     D00602     CONVERT     530340-F00602-E00602
D00602     C00598     CONVERT     530340-F00602-E00602-D00602
C00598     B00595     CONVERT     530340-F00602-E00602-D00602-C00598
B00595     A00002     MERROSS     530340-F00602-E00602-D00602-C00598-B00595
A00002          CONVERT     530340-F00602-E00602-D00602-C00598-B00595-A00002
C00598     B00595     GBLACK77     530340-F00602-E00602-D00602-C00598
B00595     A00002     MERROSS     530340-F00602-E00602-D00602-C00598-B00595
A00002          CONVERT     530340-F00602-E00602-D00602-C00598-B00595-A00002
Message was edited by: bjm
I then changed the code to the following and got the following results:
select substr(path,1,instr(path,'-')-1) base, substr(path,instr(path,'-',-1)+1,length(path)-instr(path,'-',-1)) top
from (
select substr(sys_connect_by_path(ftvorgn_orgn_code,'-'),2) path
from ftvorgn
connect by ftvorgn_orgn_code = prior ftvorgn_orgn_code_pred
start with ftvorgn_orgn_code = '530340' and ftvorgn_orgn_code_pred <> 'CONVERT'
BASE     TOP
     530340
530340     F00602
530340     E00602
530340     D00602
530340     C00598
530340     B00595
530340     A00002
530340     C00598
530340     B00595
530340     A00002
     530340
530340     F00602
530340     E00602
530340     D00602
530340     C00598
530340     B00595
530340     A00002
530340     C00598
530340     B00595
530340     A00002
Message was edited by:
This is my current code and results. I still can not capture when ftvorgn_user_id <> 'CONVERT' after the initial start with....do I need to include a where statement inside this query??
select substr(path,1,1) as bottom_level, min(substr(path,-1,1)) as vp, ftvorgn_orgn_code, ftvorgn_orgn_code_pred, ftvorgn_user_id from (
select ftvorgn_orgn_code, ftvorgn_orgn_code_pred, ftvorgn_user_id, substr(sys_connect_by_path(ftvorgn_orgn_code,'-'),2) as path
from ftvorgn
connect by ftvorgn_orgn_code = prior ftvorgn_orgn_code_pred
start with ftvorgn_orgn_code = '530340' and ftvorgn_orgn_code <> ftvorgn_orgn_code_pred and ftvorgn_user_id <>'CONVERT')
group by substr(path,1,1),ftvorgn_orgn_code, ftvorgn_orgn_code_pred, ftvorgn_user_id
BOTTOM_LEVEL     VP     FTVORGN_ORGN_CODE     FTVORGN_ORGN_CODE_PRED     FTVORGN_USER_ID
5     0     530340     F00602     SUAGUILA
5     2     A00002          CONVERT
5     5     B00595     A00002     MERROSS
5     8     C00598     B00595     CONVERT
5     8     C00598     B00595     GBLACK77
5     2     D00602     C00598     CONVERT
5     2     E00602     D00602     CONVERT
5     2     F00602     E00602     CONVERT

Similar Messages

  • Hi, i am new to oracle, SQL DEVELOPER:- ERROR:- ORA-01918

    Hi,
    I am new to oracle, and i have installed Oracle database 12c enterprise edition, and oracle jdeveloper 12c for adf web application development,
    I created a database and a new connection in it using sql developer, however while trying to create new user with the name db1 by right clicking on other users. by following the instructions in oracle documentation site. i get the error that new user db1 doesnt exist, and gives error:- ORA-01981. i even tried by changing the username as i thought may be it doesnt support alphanumeric name, but still i get the same error.
    So please tell me how to create a new user. is there any way to get out of this ora:-01918, as i googled and it says this is a bug.
    My os is win 7 x64(amd processor ).
    Thank you
    Baldwin

    A new user (called a schema in Oracle) is created using the CREATE USER SQL command. You need to be signed in as the SYS schema/user or as a schema that has been granted the rights to create schemas.
    12c database comes in two basic flavours. Container database (containing pluggable databases). Standard database. If connected to a container database, you cannot create standard user schemas - you need to be connected to a pluggable database.
    Also, your question has no relevance to either the SQL or PL/SQL languages - the subject matter of this forum. Please repost your question to a more appropriate forum dealing with SQL-Developer issues.

  • New to Oracle SQL Developer

    Getting the followung error, which I assume is a privs error, when using debugger:
    Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
    Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '10.200.10.79', '3824' )
    ORA-30683: failure establishing connection to debugger
    ORA-12535: TNS:operation timed out
    ORA-06512: at "SYS.DBMS_DEBUG_JDWP", line 68
    ORA-06512: at line 1
    Process exited.
    Please advise.
    Thank u

    I just got this working yesterday. I'm using SQL Developer on my Windows XP box. When I started the Remote Debugger I was prompted for a Port and Local Address. I accepted the default of port 4000 and entered my PC's IP Address as the Local Address. If you're also on a Window's box you get this address by going to the command line and typing "ipconfig".
    When your DBA is talking about the Oracle listener being on port 1521 he's talking about the Oracle server having a process on it listening for outside processes that want to connect to the database. I'm guessing that your DBA doesn't understand what you're trying to accomplish. In your case starting the Remote Debugger is creating a listener on your development box which listens for something like ApEx to connect to it. If the bottom left of my SQL Developer I see a little satellite icon that says Debug Listener (Port=4000 Timeout=0 Local address=xx.xx.xx.xx). This lets me know that the Remote Debugger is waiting for a connection.
    Your call...
    CALL DBMS_DEBUG_JDWP.CONNECT_TCP('remotedb','1521')should be connecting to the box that you're running SQL Developer on, not your Oracle database server. It's values should match those that you set when you started the Remote Debugger.
    I followed the tutorial found at:
    http://www.oracle.com/technology/oramag/oracle/08-may/o38browser.html
    Edited by: MARTIN_K on Aug 29, 2008 11:11 AM

  • New to Oracle SQL

    Hi all Im very new to his Oracle stuff.. Can anyone guide in learning where I can get a good and easily understable documentation. So that I can learn the oracle very fastly.
    Thanks in advance
    Mahesh Gupta

    Also there are some videos on youtube for Oracle tutorial. You can also refer them.
    http://www.google.co.in/#q=official+oracle+tutorial&hl=en&biw=837&bih=448&prmd=ivns&source=univ&tbs=vid:1&tbo=u&ei=PpUiTfL0CMKa8QOju7CDBQ&sa=X&oi=video_result_group&ct=title&resnum=5&ved=0CEYQqwQwBA&fp=71bb22fc7c95cf07

  • New to Oracle SQL : Cannot connect to the server

    I am familiar with MySql and find that some of the syntax are different. I would like to get certified in Oracle DB and would like to know whats the best approach to take. Where do I start? I downloaded 10g on my mac os and not sure what to do next. How do i run the Oracle DB now that it is installed?
    Also, It recommends trying Oracle Enterprise Manager Database Control via http://host.domain:5500/em/. I used my ip address for the host but but what is the domain? I typed for eg http://0.0.0.0:5500/em/ but i get the following error message
    Safari can’t connect to the server.
    Safari can’t open the page “http://0.0.0.0:5500/em” because Safari can’t connect to the server “0.0.0.0”.
    Thanks for any help you guys.
    Jeannie
    Edited by: user11892898 on Sep 12, 2009 6:31 AM
    Edited by: user11892898 on Sep 12, 2009 6:41 AM

    user11892898 wrote:
    Also, It recommends trying Oracle Enterprise Manager Database Control via http://host.domain:5500/em/. I used my ip address for the host but but what is the domain? I typed for eg http://0.0.0.0:5500/em/ but i get the following error message
    Safari can’t connect to the server.
    Safari can’t open the page “http://0.0.0.0:5500/em” because Safari can’t connect to the server “0.0.0.0”.
    ...If you have installed Oracle Server in your computer then you should see the menu item added in the Start -> Programs path. Look for "Database Control - <db_name>" or something similar. When you click on it, it opens up the browser with the correct URL. If the browser doesn't show up anything still, then check if the service is up. Start -> Settings -> Control Panel -> Administrative Tools -> Services. Ensure that the service "OracleDBConsole<db_name>" has "Started" status.
    Try using your full computer name for "host.domain". Right click "My Computer" on the desktop -> Properties -> "Computer Name" tab -> Full computer name. The Start menu item mentioned in the earlier paragraph does this for you.
    HTH,
    isotope

  • Oracle/sql/Datum Class not found

    Dear All ,
    I am very new in Oracle SQL XML utility.
    I am trying to run(gx.java) the following code, I am getting the following error :
    ============
    Error:
    java.lang.NoClassDefFoundError: oracle/sql/Datum
    at oracle.xml.sql.query.OracleXMLQuery.<init>(OracleXMLQuery.java:126)
    at gx.main(gx.java:41)
    Exception in thread "main"
    =============
    Can any one help me.
    Thanks & Regards
    Subrata SEN
    Source Code:
    ============
    import java.awt.*;
    import oracle.xml.sql.query.*;
    import java.sql.*;
    import java.net.*;
    import java.awt.*;
    import connection.connect;
    public class gx
    public static void main(String args[])
    String tabName = "emp";
    String user = "scott/tiger";
    Connection conn = null;
    connect initCon = new connect();
    OracleXMLQuery qry = null;
    try
    // DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    // conn = DriverManager.getConnection("jdbc:oracle:oci8:scott/tiger@");
    conn = initCon.setConnection( "scott", "tiger" );
    if( conn == null )
    System.out.println( " Connection failed ........returning" );
    return;
    catch(Exception dce)
    System.out.println( " Failure : " + dce);
    try
    System.out.println( " 1." );
    qry = new OracleXMLQuery( conn, "select empno, ename from emp" );
    System.out.println( " 2." );
    qry.setMaxRows(2);
    qry.setRowsetTag( "ROOTDOC" );
    qry.setRowTag( "DBROW" );
    qry.setStyleSheet( "emp.xsl" );
    String xmlString = qry.getXMLString();
    System.out.println( "OUTPUT : \n" + xmlString );
    catch(Exception eQry)
    System.out.println( " Exception QRY : " + eQry );
    System.out.println( "Program initialized....." );
    =================

    While the XML SQL Utility does not require the Oracle JDBC driver, it must have the Oracle JDBC driver in the CLASSPATH.

  • Problem with java.sql.Clob and oracle.sql.CLOB

    Hi,
    I am using oracle9i and SAP web application server. I am getClob method and storing that in java.sql.Clob and using the getClass().getName() I am getting the class name as oracle.sql.CLOB. But when I am trying to cast this to oracle.sql.CLOB i am getting ClassCastException. The code is given below
    java.sql.Clob lOracleClob = lResultSet.getClob(lColIndex + 1);
    lPrintWriter = new PrintWriter(new BufferedWriter (((oracle.sql.CLOB) lOracleClob).getCharacterOutputStream()));
    lResourceStatus = true;
    can anybody please tell me the what is the problem with this and solution.
    thanks,
    Ashok.

    Hi Ashok
    You can get a "ClassCastException" when the JVM doesn't have access to the specific class (in your case, "oracle.sql.CLOB").
    Just check your classpath and see if you are referring to the correct jar files.
    cheers
    Sameer
    PS: Please award points if you find the answer useful

  • Problem Encountering in oracle.sql.ARRAY type

    Hi,
    i am using one stored procedure to get a set of records.
    i am getting it by mapping those things with java.sql.Array. And after that i am getting the values as ResultSet from that Array. The same thing is working fine in Windows platform. If i posted those thing into Unix - AIX, i am facing an ArrayIndexOutofBoundsException while getting ResultSet from oracle.sql.ARRAY class. I checked out ARRAY instance.it is not null. Both Application and Database are same except O.S.
    Can Anybody help me. I need it imm.
    Thanks in Advance
    Regards
    Eswaramoorthy.G

    Hi
    Did you ever figure out what the problem was with this? We have a client that is experiencing the same problem on AIX but we cannot reproduce using their database running under NT nor Sun. Any information would be appreciated. You can respond directly to [email protected]
    Thanks in adavance
    Rick DeMilia
    Sungard DataSystems

  • Is ORACLE SQL DEVELOPER up to other Tools?

    Hi Experts,
    Am new to Oracle SQL Developer Tool. Can anyone tell me what are the drawbacks of this ORACLE SQL DEVELOPER.
    Is SQL DEVELOPER up to other Tools?
    Thanks in Advance!
    Regards,
    Anup

    Anup wrote:
    Yah it's true... But I want to know is there any drawbacks in case of User Interface or Performance or any as compared to other Tools like SQL Navigator or Toad ?This is a wrong place for this question. You need to post it in SQL Developer Forum.
    SQL Developer

  • Problems when starting with oracle SQL developer

    Hello,
    I am very much new with oracle SQL developer. I use oracle 10g and have a database named 'pallabDB' with username: xxxxxx and paswd:yyyyyy. I have installed oracle SQL developer.But i am unable to start up.What i should do? If any body replies it will be a great help.Thanks in advance.

    But i am unable to
    start up.How to understand this sentence without confusion?
    Can you explain exactly what is your problem at start up of SQL Developer?

  • My First while loop inside PL/SQL block not working , please help

    Hi ,
    I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
    declare
    v_A number constant :=10 ;
    j number constant := 3 ;
    BEGIN
    WHILE j < v_A
    LOOP
    DBMS_OUTPUT.PUT_LINE('Hai');
    END LOOP;
    END;
    please help as how to resolve this .
    Thanks in advance .

    btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
    DECLARE
       v_a CONSTANT PLS_INTEGER := 10;
       j   CONSTANT PLS_INTEGER := 3;
       i PLS_INTEGER := j;
    BEGIN
       WHILE i <= v_a LOOP
          DBMS_OUTPUT.PUT_LINE(i);
          i := i +1;
       END LOOP;
    END;or perhapsdeclare
       v_a constant pls_integer := 10;
       j   constant pls_integer := 3;
       i pls_integer := j;
    begin
       while i <= v_a loop
          dbms_output.put_line(i);
          i := i +1;
       end loop;
    end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see...

  • Error -While create a connection to Microsoft SQL Sever from Oracle SQL Dev

    Dear All,
    While I am trying to create a connection to Microsoft SQL Sever from Oracle SQL Developer. The following error: "Cannot connect to Microsoft SQL Server on localhost" has been occurred.
    Can anyone please guide me to solve this..
    Thanks in advance,
    Rider

    Hi,
    Issue not supported in sharepoint on-premise team.
    In addition, as this issue is related to Powerview, I suggest you create a new thread on for Powerview forum, more experts will assist you.
    https://social.technet.microsoft.com/Forums/en-US/home?forum=powerview
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Error while creating new user in Oracle 11i EBS

    I am getting following error while creating new user. How solve this issue?
    “Unable to load java class % specified profile option SIGNON_PASSWORD_CUSTOM. Please verify that the class exists and that it implements the java interface oracle.apps.fnd.security.PasswordValidation”.

    Following is the text from Note for Custom Password Validation logic:
    Customers who wish to use their own password validation logic may do
      so by writing their own Java classes that implement the
      oracle.apps.fnd.security.PasswordValidation Java interface.  The
      interface requires 3 methods to be implemented:
      1) public boolean validate(String user, String password)
        - This method takes a username and password, and then returns true
      or false, indicating whether the user's password is valid or invalid,
      respectively.
      2) public String getErrorStackMessageName()
        - This method returns the name of the message to display when the
      user's password is deemed invalid (i.e., the validate() method returns
      false).
      3) public String getErrorStackApplicationName()
        - This method returns the application shortname for the
      aforementioned error message.
      After writing the Java class to perform customized password
      validation, the customer must then set the value of the profile option
      SIGNON_PASSWORD_CUSTOM to be the full name of the class.  If, for
      example, the name of the Java class is
      oracle.apps.fnd.security.AppsPasswordValidation, then the value of the
      SIGNON_PASSWORD_CUSTOM profile option must be
      oracle.apps.fnd.security.AppsPasswordValidation.  Note that AOL/J
      will attempt to load this class dynamically.  Hence it is necessary to
      make the class accessible by AOL/J.  This means that in Forms, the
      class must first be loaded into the database using the loadjava
      command.
    You will need to apply the following patches for 11.5.1:
       1344802
       1363919
       1472974
       1351004
       1377615
    You will need to apply the following patches for 11.5.2:
       1377615

  • ClassCastException while inserting in oracle.sql.BLOB

    Hi,
    I have to insert a blob data in to database . I wrote the code . I'm having a ClassCastException problem in the line oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st.getConnection(), false,
    oracle.sql.BLOB.DURATION_CALL); while trying to store a BLOB value I'm using Oracle 9i. (JDBC classes12.jar).
    if I use the method with a dedicated database connection that specifies the driver as oracle.jdbc.driver.OracleDriver there is no problem .
    But when I use JBoss to run , I will get ClassCastException
    I imagine that somewhere in the code of this method there is a cast of the underlying connection leading to the ClassCastException when used in conjunction with the jboss datasource. The code to save the BLOB is as follows:
    String sql = " update test set code = ? where id = ?  ";
                 BLOB   newBlob = BLOB.createTemporary(dbcon, false, BLOB.DURATION_CALL);
                  newBlob.putBytes(1,data.getBytes());
                  stmt = dbcon.prepareStatement(newsql);
                 stmt.setBlob(1, newBlob);
                 stmt.setInt(2, Studid );
                 stmt.executeUpdate();
                 stmt.close();Can any one tell me how can I get this code to work with the datasource implementation.
    Thanks

    I think this could be a problem with the class loader . Take a look at this thread It should solve your problem.
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=788715

  • Error while converting schema from oracle to SQL server

    Hello,
    I am getting following error while converting schema from oracle to SQL server using SSMA.
    I get Errors 1-3 while migrating procedures and error 4 while migrating a table.
    1- O2SS0050: Conversion of identifier 'SYSDATE' is not supported.
    2- O2SS0050: Conversion of identifier 'to_date(VARCHAR2, CHAR)' is not supported.
    3- O2SS0050: Conversion of identifier 'regexp_replace(VARCHAR2, CHAR)' is not supported.
    4- O2SS0486: <Primary key name> constraint is disabled in Oracle and cannot be converted because SQL Server does not support disabling of primary or unique constraint.
    Please suggest.
    Thanks.

    The exact statement in oracle side which causing this error (O2SS0050:
    Conversion of identifier 'to_date(VARCHAR2, CHAR)' is not supported.) is below:
    dStartDate:= to_date(sStartDate,'MON-YYYY');
    Statement causing error O2SS0050:
    Conversion of identifier 'regexp_replace(VARCHAR2, CHAR)' is not supported is below.
    nCount2:= length(regexp_replace(sDataRow,'[^,]'));
    So there is no statement which is using to_date(VARCHAR2,
    CHAR) and regexp_replace(VARCHAR2, CHAR) in as such. 'MON-YYYY'  and '[^,]'
    are CHAR values hence SSMA is unable to convert it from varchar2 to char.
    Regarding SYSDATE issue, you mean to put below code in target(SQL) side in SSMA ?
    dDate date := sysdate;
    Thanks.

Maybe you are looking for

  • CLJ 2605dn Colors Off, Print Quality Issue

    My issue is that when printing colors, they aren't correct. The Magenta on a Supplies Status page is poor quality. Printing 'Reds' are also poor, but I'm not convinced the other colors are accurate, either, though not as poor and look fairly good. I

  • Opendocument failing when parameters populated by Report

    Post Author: Lesley CA Forum: General I don't know whether this has been raised before, but I am using Crystal Reports XI and trying to access the URL to call a report. When I pass a parameter to the report, it works.   eg http://localhost:8080/busin

  • 2.0 software

    Does anyone know when they will released this? thanks.

  • When typing on my iPad the screen does not move up so I can see what I am typing.

    Under normal operation, when using the virtual keypad, iOS shifts the screen so that it's possible to view what you are typing all the time. On my iPad if the text I am typing is below the keyboard, the screen is not automatically moved up. On some f

  • PSD (photoshop) file comes out stretched in video

    Hi everyone, I have a video made from my canon hv20, resolution is 1440 x 1080. At the end I want to put credits and a logo (2 separate psd files) but it always comes out a little stretched. I've tried a psd file with these resolutions: 1440 x 1080 1