Trees in pl/sql

hi,
It's possible, in runtime, create of structure tree new?
ID         ORDER     TREE
6546          3            1
6543          6            2
6465          3            2.1
8654          9            3              <= i change ORDER 9 to 1
8796          3            3.1
4646          3            3.1.1
RESULT:
ID      ORDER       TREE    NEWTREE
8654          1            3            1   
8796          3            3.1         1.1
4646          3            3.1.1      1.1.1
6546          3            1            2
6543          6            2            3
6465          3            2.1         3.1
new tree, it's possible?
how i can find functions,libraries in pl/sql in oracle?
thank's
jomar
 

> how i can find functions,libraries in pl/sql in oracle?
Oracle's main document portal is at http://tahiti.oracle.com
For functions (SQL and PL/SQL share the same set) refer to the [url
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm]Oracle® Database SQL Reference.
For PL/SQL libraries, refer to [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/toc.htm]Oracle® Database PL/SQL Packages and Types Reference.
The "trees" you mentioned are called hierarchies in Oracle and Oracle SQL supports hierarchical queries. Consult the CONNECT BY clause in the above SQL Reference guide.

Similar Messages

  • Invalid query tree 300-33 - SQL Error 8180 @ Query

    Hello,
    @ my Grid i geht the error Invalid query tree 300-33 - SQL Error 8180 @ the Select Statement.
    oGrid= ( ( SAPbouiCOM.Grid)(oItem.Specific));
                        oForm.DataSources.DataTables.Add("myGrid");
                        oForm.DataSources.DataTables.Item(0).ExecuteQuery("select U_NAG_CardCode, U_NAG_CardName, U_NAG_ProjName, U_NAG_ProjNr, U_NAG_ProjAbge, U_NAG_ProjStart from SBODemoDE.dbo.NAG_PROJEKTEE");
                        oGrid.DataTable = oForm.DataSources.DataTables.Item("myGrid");
    I dont know what´s wrong.
    When i execute this in SQL-Managmant Studio , it works.
    pls Help
    Thanks
    Dhomas

    Hi Dhomas,
    How did you solve this problem? I have the same and need some help.
    regards
    Ela

  • Reporting tree in MS SQL

    Hi
    In MS SQL I have a table with 2 columns:
    Employee          Manager
    Scott                Peter
    Nancy               Peter
    Paul                  Peter
    Damien             Scott
    German             Scott
    Astrid                Scott
    Beata                Nancy
    Christina           Nancy
    Nicole               Nancy
    How to get a reporting tree like this in Ms SQL?
    Manager            Employee
    Peter                  Scott
    Peter                  Nancy
    Peter                  Paul
    Scott                  Damien
    Scott                  German
    Scott                  Astrid
    Nancy                 Beata
    Nancy                 Christina
    Nancy                 Nicole
    Paul                   no _employee
    Thanks!
    Mecu
    gec

    You are welcome :-)
    Please close the thread my marking the answer (there is a link under the response), and you can vote for people's response that tired to help you as well (using the link in the left of the response).
    ** If you use UNION instead of UNION ALL then you don't have duplicate values, and you dont need the group by (but the server build the same execution plan in this case).
    select t1.Manager, ISNULL(t2.employee,'no _employee') as Employee
    from (
    select Employee as Manager
    from T
    union
    select Manager
    from T
    ) t1
    left join T t2 on t1.Manager = t2.Manager
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • Sql Developer - View source code of procedures, functions & packages in another schema

    Our developers need the ability to view procedures, function, packages etc. in the production database (using SQL DEVELOPER).  They don't have access to sign on as the owner of these
    objects in Production.  They must use their own limited access UserID for this purpose.
    This limited access UserID has been granted select privilege on DBA_SOURCE & DBA_OBJECTS.  The developers need the ability to view the source of these object via
    the tree view in SQL DEV.  They should be able to click on "other users" in the SQL DEV tree view and see a listing of the owner schema objects.  Then they should
    be able to select the desired object and view the source code.  These developers are used to using GUI interfaces.  Selecting from DBA_SOURCE would not be an
    option for them.
    I understand that if the limited user is granted SELECT ANY DICTIONARY or SELECT_CATALOG_ROLE then this functionality will work.  The problem is those
    privileges/roles  provide much more access than should be granted to these limited access users. Granting DBA to these users is also not an option.
    In TOAD and other end-user tools this functionality works when only select privilege on DBA_SOURCE & DBA_OBJECTS has been granted.  We need this same functionality
    in SQL DEV.
    While searching this forum and the internet, I see that other installations have this same issue.
    Please enhance SQL Developer with this functionality. 
    Thank you, ellen

    Just to double check that I'm interpreting the problem correctly, is the following true:
    select * from all_objects where object_name = 'DBA_SOURCE'
    returns nothing
    select * from dba_source where name = your PL/SQL module
    returns all the code

  • Sitemap using PL/SQL

    I hope someone can help!
    Trying to create a sitemap for my organisations new intranet.
    I have created a view below to capture the URL to the page.
    SELECT     p.ID page_id, s.title area, p.siteid, p.parentid, s.ID groupid,
                  settingssetid,
                     '<a href="http://croweb02.crown.copfs.gsi.gov.uk:8090/portal/page/portal/'
                  || p.guid
                  || '">'
                  || p.title title
             FROM dev_portal.wwv_sites s, dev_portal.wwpob_page$ p
            WHERE p.settingssetid = 1422 AND p.siteid > 6 AND s.ID = p.siteid
       START WITH p.parentid = 1
       CONNECT BY PRIOR p.ID = p.parentid
         --GROUP BY  siteid, parentid, title, LEVEL, ID, settingssetid, guid
       ORDER SIBLINGS BY p.siteid, p.parentid, p.title, p.ID;I have also created a SQL query report to populte the sitemap. However when I run the query only pages were its parentid = 1 has a link been added? How can I correct this to all pages?
    select siteid, page_id, area, parentid, LPAD (' ', 6 * (LEVEL - 1))  ||  title
    from dev_portal.view_site_map2
    START WITH parentid = 1
    CONNECT BY PRIOR page_id = parentid
    ORDER SIBLINGS BY siteid, parentid, title, page_idThanks
    Edited by: user8951581 on 16-Jun-2011 03:03
    Edited by: BluShadow on 16-Jun-2011 11:16
    removed poor bold formatting of code and added appropriate {noformat}{noformat} tags.
    Please read {message:id=9360002} to learn how to post code and data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I posted an example showing how to build a tree in pl/sql using the xmlparser and xmldom packages.

  • Tree/leaf and links

    Hi,
    I just created a tree based on sql, and it's great. But i like whenever users click branches or leaves, these branch/leaf will point to new pages. How to configure this?
    By the way, it looks the htmldb How-to url is changed. What is the new url for html how-to?
    Thanks.
    Fei

    hi fei--
    if you edit the tree definition of your newly created tree, you'll see that it's really defined as a sql query. the fouth column selected out in this query is your link. if you opted not to have your tree link to anything during the process of using our wizard to create your tree, you'll find that fourth column is null. so if you made your tree off the emp table, your might look like this...
    select "EMPNO" id,
    "MGR" pid,
    "ENAME" name,
    null link,
    null a1,
    null a2
    from "#OWNER#"."EMP"
    ...and if you change that fourth column like so...
    select "EMPNO" id,
    "MGR" pid,
    "ENAME" name,
    'f?p=&APP_ID.:1:&APP_SESSION.::NO::P1_EMPNO:'||"EMPNO" link,
    null a1,
    null a2
    from "#OWNER#"."EMP"
    ...you'd find that clicking on an employee's name in your tree would link you over to page 1 setting :P1_EMPNO to the value of that emp's empno. the better way to do this, though, would be to set your linking up as you go through the tree wizard. the ninth step of that wizard asks you to "Identify Query". that screen has a "Link Option" field on it. it defaults to "Nothing", but it sounds as if you'd like it to link somewhere in your app. to have it do so, simply select the "Existing Application Item" option in that radio group. the next screen will then help you set up that link.
    either of the above two approaches should work fine, but let us know if you need further assistance.
    regards,
    raj
    ps-the htmldb how-to's are currently at http://otn.oracle.com/products/database/htmldb/howtos/index.html .i don't think they've been moved recently, but that's at least where they are now.

  • Need help from SQL Developer users

    I’d like to run Decision Tree models in SQL Developer for monthly predications after running in ODM manually.
    I created PL/SQL Packages under Tools from ODM, and compiled them in SQL Developer successfully. According to Oracle documents, I should be able to run the same DT models (using create or replace PACKAGE BODY "DATAMININGACTIVITY1" .......). However, I am unable to run the entire “Package Body” or any part of it. One of the error messages shows "The select program is in an invalid state for running". I also tried to use "Call" to call functions to run my SQL Package, but that didn't work either. So far, the only SQL works for me is to create a view from a table.
    Please share how you use SQL to run models. Thanks, DC

    In PL/SQL Block you will see something like below.
    In the most simple case you need to supply to arguments ( see bold )
    CASE_TABLE := *'YOUR_TABLE_NAME_FOR_MODEL_BUILD'*;
    MODEL_NAME := *'MODEL_NAME_FOR_YOUR_NEW_MODEL';*
    That would be enough to build a model.
    Thanks,
    Jim
    DECLARE
    CASE_TABLE VARCHAR2(200);
    ADDITIONAL_TABLE_1 VARCHAR2(200);
    MODEL_NAME VARCHAR2(200);
    CONFUSION_MATRIX_NAME VARCHAR2(200);
    LIFT_RESULT_NAME VARCHAR2(200);
    ROC_RESULT_NAME VARCHAR2(200);
    TEST_METRIC_NAME VARCHAR2(200);
    FEATURE_TABLE VARCHAR2(200);
    MAPPING_TABLE VARCHAR2(200);
    DROP_OUTPUT BOOLEAN;
    BEGIN
    CASE_TABLE := *'YOUR_TABLE_NAME_FOR_MODEL_BUILD'*;
    ADDITIONAL_TABLE_1 := NULL;
    MODEL_NAME := *'MODEL_NAME_FOR_YOUR_NEW_MODEL';*
    CONFUSION_MATRIX_NAME := NULL;
    LIFT_RESULT_NAME := NULL;
    ROC_RESULT_NAME := NULL;
    TEST_METRIC_NAME := NULL;
    FEATURE_TABLE := NULL;
    MAPPING_TABLE := NULL;
    DROP_OUTPUT := NULL;
    DATAMININGACTIVITY1.DT_1428168079_BA(
    CASE_TABLE => CASE_TABLE,
    ADDITIONAL_TABLE_1 => ADDITIONAL_TABLE_1,
    MODEL_NAME => MODEL_NAME,
    CONFUSION_MATRIX_NAME => CONFUSION_MATRIX_NAME,
    LIFT_RESULT_NAME => LIFT_RESULT_NAME,
    ROC_RESULT_NAME => ROC_RESULT_NAME,
    TEST_METRIC_NAME => TEST_METRIC_NAME,
    FEATURE_TABLE => FEATURE_TABLE,
    MAPPING_TABLE => MAPPING_TABLE,
    DROP_OUTPUT => DROP_OUTPUT
    END;
    Edited by: jdadashev on Mar 12, 2010 9:08 AM

  • Tree does not display, Chrome detects script errors. Bug or my error?

    I'm creating a Tree page for first time, so I don't know how it's done. Following instructions and using the Tree wizard. SQL query works as SQL command. Using Application Express 4.0.1.00.03.
    Region title appears, but nothing else. With Google Chrome browser, I right click on the page to inspect element. The HTML code including data I expect is in the page.
    When I look at the Scripts in the inspect panel, there is a script named 'f'. That's all. It's got the HTML for my page.
    My tree identifier seems to be: 'tree3343403320392902'.
    In the script I find:
    *var l3343403320392902Data = [*                Followed by a llong string of attributes for ID, Data, Titles, Tooltips, etc.
    -->This is where the's a big red message: "<font color="red">Uncaught SyntaxError: Unexpected token ;</font>"
    At the end the HTML is:
    *<!--*
    *apex.jQuery(document).ready(function(){*
    *(function(){apex.widget.tree.init("tree3343403320392902", apex.widget.tree.cTreeTypes, l3343403320392902Data,"classic","Person Query","S","");})();*
    -->The big red message here is: " <font color="red">f:114Uncaught ReferenceError:l3343403320392902Data is not defined</font>"
    *//-->*
    *</script></body>*
    *</html>*
    Same problem in IE8. I have screen shot and text file of the html.

    Hi,
    Could it be bug 9946779 that is fixed on 4.0.2.00.07 ?
    http://www.oracle.com/technetwork/developer-tools/apex/application-express/402-patch-189110.html#BABJCAFA
    Regards,
    Jari
    Edited by: jarola on Jan 15, 2011 11:33 AM
    Sorry, that bug is fixed already on 4.0.1.00.03. My mistake

  • GetXML using PL/SQL SQL Utilities

    Is there a way that I can get XML files based
    on my DTD, instead of query? e.g., input is
    DTD, output is XML file. Current APIs
    requies a query as input, then return xml
    files.
    null

    I posted an example showing how to build a tree in pl/sql using the xmlparser and xmldom packages.

  • Pl/sql DOM MakeDocument using a node fails

    I am new to xml and have a question. Below code fails with an error ORA-31183: Node type element cannot be converted to desired type. Question is why can't I make a document by passing in a node to makedocument function. If you see the last statement in below code I am calling xmldom.MakeDocument(node) . what I am trying to do is create a document for each detail child node so that I can use xmldom.getElementsByTagName to get the elements that I need. I think (?) xmldom.getElementsByTagName only takes a document as parameter. Please help
    DECLARE
    myparser DBMS_XMLPARSER.parser;
    indomdoc xmldom.DOMDocument;
    innode xmldom.DOMNode;
    nchild xmldom.DOMNode;
    ngrandchild xmldom.DOMNode;
    ngreatgrandchild xmldom.DOMNode;
    nworksetdoc xmldom.DOMDocument;
    BEGIN
    myParser := DBMS_XMLPARSER.newParser;
    DBMS_XMLPARSER.parse(myParser, 'FCSDIR/smallexport1.xml');
    indomdoc := DBMS_XMLPARSER.getDocument(myParser);
    nchild := xmldom.getFirstChild(xmldom.MakeNode(indomdoc));
    dbms_output.put_line(xmldom.getNodename(nchild));
    ngrandchild := xmldom.getFirstChild(nchild);
    dbms_output.put_line(xmldom.getNodename(ngrandchild));
    ngreatgrandchild := xmldom.getFirstChild(ngrandchild);
    dbms_output.put_line(xmldom.getNodename(ngreatgrandchild));
    nworksetdoc := xmldom.MakeDocument(ngreatgrandchild);
    END;
    /

    I posted an example showing how to build a tree in pl/sql using the xmlparser and xmldom packages.

  • Question about Tree

    I need to build a dynamic tree based on sql returned from function - is this possible? The only option I see for tree source query is "Dynamic - From SQL Query" there is no option to use PL/SQL function returning SQL query.
    Any suggestions will be appreciated.
    George

    Hi,
    Creating a function that returns a TABLE would probably be the proper way to do this.
    You could, however, create a collection from the string generated by your code using APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY (see: [http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/advnc.htm#sthref2033]) and you could then base your tree on this collection.
    Andy

  • Table does not exist at dw.insertrow(0)

    Hi,
    I am trying to update an old PB app.
    Background of the basic database structure:
    my_data Table:
    col1
    col2 -- lookup to an_old_table.id
    col3 -- newly added as lookup
    my_new_lookup Table:
    code -- 'linked' to col3 above
    description
    an_old_lookup table:
    id -- 'linked' to my_data.col2
    text
    I have created a new lookup table in our oracle database, and added an extra column to an existing table this column matches the lookup code and we can pull the full description of the item from there.
    I would like to add the new lookup table as a dropdown list in a window of my app.
    There is already a dropdown list which does exactly this, displaying an_old_table.text in the dropdown but updating my_table.col2 with the id value.
    I have attempted to duplicate this functionality exactly but with data from my_new_lookup to my_data.col3, but am failing somewhere.
    I have created a new d_dddw_mynewdropdown, which in the preview window lists all my_new_lookup.description values from the database correctly.
    In the datawindow, I added a column control, changed the edit to DropDownDW, making sure the DataWindow is d_dddw_mynewdropdown and display and data columns matched description and code respectively.
    When I do a retreive on the datawindow within powerbuilder, with a record from the my_data table a dropdown box appears correctly in the preview window with the value matching the correct lookup description, so it is flowing through col3 > code > description correctly.
    The datawindow is embedded into an application window, and this is where I think it is failing... The window has two datawindows on it and part of the open() function does:
    If dw_one.Retrieve(ln_id,) > 0 Then
      ll_row = dw_one.GetRow()
    If dw_one.ShareData (dw_two) <> 1 Then
      MessageBox ("Error", "Error in sharing data.")
      Else
      dw_two.ScrollToRow (ll_row)
      End If
    Which passes (IE does not display the message box)
    It then executes:
    dw_one.InsertRow(0)
    dw_two.InsertRow(0)
    Which is where the application displays an error message which says:
    Select Error: ORA-00942: table or view does not exist
    I stepped through the code in debug mode and discovered the error message comes from the dw_one.InsertRow(0) line.
    If I press ok to the error, the application continues to run, but the value of the dropdown box is my_data.col3 (the 'linking' code, not the full description) and the dropdown when pressed is empty.
    I am not sure what I have done wrong.. In powerbuilder itself everything seems to be working and connecting together as it should when I preview the data in the datawindows, but something about the application window has issues.
    Has anyone experienced similar things? I do not know where else to look to fix this.
    Thanks.

    This is correct. The application starts with a log in screen (we have over 80 users) the application then connects to the database using the credentials entered into the login screen.
    The table was created under the db admin account.
    I have very little Oracle experience. what would be the best way to do it so that all users who have access to the application also have access to this table?
    From what I can work out, the application uses the "Other Users" folder under in the database tree in Oracle SQL Developer. The DB admin account is not in the list of users in this folder..
    When I use the application and log in using the db admin credentials there is no error! So I just have to work out how to give all the users access to this table?!
    is the
    alter session set current_schema= <username of table creator>.
    a PowerBuilder command that I should run after the users log into the app? or is it an Oracle Query?
    Thanks! this is down the right track..
    I ran a select * from all_tables query and compared the new table with others that are successfully being used by the application.. as far as I can see, they are exactly the same in terms of OWNER, TABLESPACE_NAME, CLUSTER_NAME, STATUS, BUFFER_POOL... The only thing different is my new table has GLOBAL_STATS = YES where the rest have NO.. not sure if that makes any difference..
    The OWNER column is the database admin user for all tables used by the application
    I also checked the DBA_TAB_PRIVS table and it has all the same info as the other tables aswell.. not sure where else to look.

  • Very Slow Query with CTE inner join

    I have 2 tables (heavily simplified here to show relevant columns):
    CREATE TABLE tblCharge
    (ChargeID int NOT NULL,
    ParentChargeID int NULL,
    ChargeName varchar(200) NULL)
    CREATE TABLE tblChargeShare
    (ChargeShareID int NOT NULL,
    ChargeID int NOT NULL,
    TotalAmount money NOT NULL,
    TaxAmount money NULL,
    DiscountAmount money NULL,
    CustomerID int NOT NULL,
    ChargeShareStatusID int NOT NULL)
    I have a very basic View to Join them:
    CREATE VIEW vwBASEChargeShareRelation as
    Select c.ChargeID, ParentChargeID, s.CustomerID, s.TotalAmount, isnull(s.TaxAmount, 0) as TaxAmount, isnull(s.DiscountAmount, 0) as DiscountAmount
    from tblCharge c inner join tblChargeShare s
    on c.ChargeID = s.ChargeID Where s.ChargeShareStatusID < 3
    GO
    I then have a view containing a CTE to get the children of the Parent Charge:
    ALTER VIEW [vwChargeShareSubCharges] AS
    WITH RCTE AS
    SELECT ParentChargeId, ChargeID, 1 AS Lvl, ISNULL(TotalAmount, 0) as TotalAmount, ISNULL(TaxAmount, 0) as TaxAmount,
    ISNULL(DiscountAmount, 0) as DiscountAmount, CustomerID, ChargeID as MasterChargeID
    FROM vwBASEChargeShareRelation Where ParentChargeID is NULL
    UNION ALL
    SELECT rh.ParentChargeID, rh.ChargeID, Lvl+1 AS Lvl, ISNULL(rh.TotalAmount, 0), ISNULL(rh.TaxAmount, 0), ISNULL(rh.DiscountAmount, 0) , rh.CustomerID
    , rc.MasterChargeID
    FROM vwBASEChargeShareRelation rh
    INNER JOIN RCTE rc ON rh.PArentChargeID = rc.ChargeID and rh.CustomerID = rc.CustomerID
    Select MasterChargeID as ChargeID, CustomerID, Sum(TotalAmount) as TotalCharged, Sum(TaxAmount) as TotalTax, Sum(DiscountAmount) as TotalDiscount
    from RCTE
    Group by MasterChargeID, CustomerID
    GO
    So far so good, I can query this view and get the total cost for a line item including all children.
    The problem occurs when I join this table. The query:
    Select t.* from vwChargeShareSubCharges t
    inner join
    tblChargeShare s
    on t.CustomerID = s.CustomerID
    and t.MasterChargeID = s.ChargeID
    Where s.ChargeID = 1291094
    Takes around 30 ms to return a result (tblCharge and Charge Share have around 3.5 million records).
    But the query:
    Select t.* from vwChargeShareSubCharges t
    inner join
    tblChargeShare s
    on t.CustomerID = s.CustomerID
    and t.MasterChargeID = s.ChargeID
    Where InvoiceID = 1045854
    Takes around 2 minutes to return a result - even though the only charge with that InvoiceID is the same charge as the one used in the previous query.
    The same thing occurs if I do the join in the same query that the CTE is defined in.
    I ran the execution plan for each query. The first (fast) query looks like this:
    The second(slow) query looks like this:
    I am at a loss, and my skills at decoding execution plans to resolve this are lacking.
    I have separate indexes on tblCharge.ChargeID, tblCharge.ParentChargeID, tblChargeShare.ChargeID, tblChargeShare.InvoiceID, tblChargeShare.ChargeShareStatusID
    Any ideas? Tested on SQL 2008R2 and SQL 2012

    >> The database is linked [sic] to an established app and the column and table names can't be changed. <<
    Link? That is a term from pointer chains and network databases, not SQL. I will guess that means the app came back in the old pre-RDBMS days and you are screwed. 
    >> I am not too worried about the money field [sic], this is used for money and money based calculations so the precision and rounding are acceptable at this level. <<
    Field is a COBOL concept; columns are totally different. MONEY is how Sybase mimics the PICTURE clause that puts currency signs, commas, period, etc in a COBOL money field. 
    Using more than one operation (multiplication or division) on money columns will produce severe rounding errors. A simple way to visualize money arithmetic is to place a ROUND() function calls after 
    every operation. For example,
    Amount = (Portion / total_amt) * gross_amt
    can be rewritten using money arithmetic as:
    Amount = ROUND(ROUND(Portion/total_amt, 4) * 
    gross_amt, 4)
    Rounding to four decimal places might not seem an 
    issue, until the numbers you are using are greater 
    than 10,000. 
    BEGIN
    DECLARE @gross_amt MONEY,
     @total_amt MONEY,
     @my_part MONEY,
     @money_result MONEY,
     @float_result FLOAT,
     @all_floats FLOAT;
     SET @gross_amt = 55294.72;
     SET @total_amt = 7328.75;
     SET @my_part = 1793.33;
     SET @money_result = (@my_part / @total_amt) * 
    @gross_amt;
     SET @float_result = (@my_part / @total_amt) * 
    @gross_amt;
     SET @Retult3 = (CAST(@my_part AS FLOAT)
     / CAST( @total_amt AS FLOAT))
     * CAST(FLOAT, @gross_amt AS FLOAT);
     SELECT @money_result, @float_result, @all_floats;
    END;
    @money_result = 13525.09 -- incorrect
    @float_result = 13525.0885 -- incorrect
    @all_floats = 13530.5038673171 -- correct, with a -
    5.42 error 
    >> The keys are ChargeID(int, identity) and ChargeShareID(int, identity). <<
    Sorry, but IDENTITY is not relational and cannot be a key by definition. But it sure works just like a record number in your old COBOL file system. 
    >> .. these need to be int so that they are assigned by the database and unique. <<
    No, the data type of a key is not determined by physical storage, but by logical design. IDENTITY is the number of a parking space in a garage; a VIN is how you identify the automobile. 
    >> What would you recommend I use as keys? <<
    I do not know. I have no specs and without that, I cannot pull a Kabbalah number from the hardware. Your magic numbers can identify Squids, Automobile or Lady Gaga! I would ask the accounting department how they identify a charge. 
    >> Charge_Share_Status_ID links [sic] to another table which contains the name, formatting [sic] and other information [sic] or a charge share's status, so it is both an Id and a status. <<
    More pointer chains! Formatting? Unh? In RDBMS, we use a tiered architecture. That means display formatting is in a presentation layer. A properly created table has cohesion – it does one and only one data element. A status is a state of being that applies
    to an entity over a period time (think employment, marriage, etc. status if that is too abstract). 
    An identifier is based on the Law of Identity from formal logic “To be is to be something in particular” or “A is A” informally. There is no entity here! The Charge_Share_Status table should have the encoded values for a status and perhaps a description if
    they are unclear. If the list of values is clear, short and static, then use a CHECK() constraint. 
    On a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, this is literally that silly and wrong. 
    >> I understand what a CTE is; is there a better way to sum all children for a parent hierarchy? <<
    There are many ways to represent a tree or hierarchy in SQL.  This is called an adjacency list model and it looks like this:
    CREATE TABLE OrgChart 
    (emp_name CHAR(10) NOT NULL PRIMARY KEY, 
     boss_emp_name CHAR(10) REFERENCES OrgChart(emp_name), 
     salary_amt DECIMAL(6,2) DEFAULT 100.00 NOT NULL,
     << horrible cycle constraints >>);
    OrgChart 
    emp_name  boss_emp_name  salary_amt 
    ==============================
    'Albert'    NULL    1000.00
    'Bert'    'Albert'   900.00
    'Chuck'   'Albert'   900.00
    'Donna'   'Chuck'    800.00
    'Eddie'   'Chuck'    700.00
    'Fred'    'Chuck'    600.00
    This approach will wind up with really ugly code -- CTEs hiding recursive procedures, horrible cycle prevention code, etc.  The root of your problem is not knowing that rows are not records, that SQL uses sets and trying to fake pointer chains with some
    vague, magical non-relational "id".  
    This matches the way we did it in old file systems with pointer chains.  Non-RDBMS programmers are comfortable with it because it looks familiar -- it looks like records and not rows.  
    Another way of representing trees is to show them as nested sets. 
    Since SQL is a set oriented language, this is a better model than the usual adjacency list approach you see in most text books. Let us define a simple OrgChart table like this.
    CREATE TABLE OrgChart 
    (emp_name CHAR(10) NOT NULL PRIMARY KEY, 
     lft INTEGER NOT NULL UNIQUE CHECK (lft > 0), 
     rgt INTEGER NOT NULL UNIQUE CHECK (rgt > 1),
      CONSTRAINT order_okay CHECK (lft < rgt));
    OrgChart 
    emp_name         lft rgt 
    ======================
    'Albert'      1   12 
    'Bert'        2    3 
    'Chuck'       4   11 
    'Donna'       5    6 
    'Eddie'       7    8 
    'Fred'        9   10 
    The (lft, rgt) pairs are like tags in a mark-up language, or parens in algebra, BEGIN-END blocks in Algol-family programming languages, etc. -- they bracket a sub-set.  This is a set-oriented approach to trees in a set-oriented language. 
    The organizational chart would look like this as a directed graph:
                Albert (1, 12)
        Bert (2, 3)    Chuck (4, 11)
                       /    |   \
                     /      |     \
                   /        |       \
                 /          |         \
            Donna (5, 6) Eddie (7, 8) Fred (9, 10)
    The adjacency list table is denormalized in several ways. We are modeling both the Personnel and the Organizational chart in one table. But for the sake of saving space, pretend that the names are job titles and that we have another table which describes the
    Personnel that hold those positions.
    Another problem with the adjacency list model is that the boss_emp_name and employee columns are the same kind of thing (i.e. identifiers of personnel), and therefore should be shown in only one column in a normalized table.  To prove that this is not
    normalized, assume that "Chuck" changes his name to "Charles"; you have to change his name in both columns and several places. The defining characteristic of a normalized table is that you have one fact, one place, one time.
    The final problem is that the adjacency list model does not model subordination. Authority flows downhill in a hierarchy, but If I fire Chuck, I disconnect all of his subordinates from Albert. There are situations (i.e. water pipes) where this is true, but
    that is not the expected situation in this case.
    To show a tree as nested sets, replace the nodes with ovals, and then nest subordinate ovals inside each other. The root will be the largest oval and will contain every other node.  The leaf nodes will be the innermost ovals with nothing else inside them
    and the nesting will show the hierarchical relationship. The (lft, rgt) columns (I cannot use the reserved words LEFT and RIGHT in SQL) are what show the nesting. This is like XML, HTML or parentheses. 
    At this point, the boss_emp_name column is both redundant and denormalized, so it can be dropped. Also, note that the tree structure can be kept in one table and all the information about a node can be put in a second table and they can be joined on employee
    number for queries.
    To convert the graph into a nested sets model think of a little worm crawling along the tree. The worm starts at the top, the root, makes a complete trip around the tree. When he comes to a node, he puts a number in the cell on the side that he is visiting
    and increments his counter.  Each node will get two numbers, one of the right side and one for the left. Computer Science majors will recognize this as a modified preorder tree traversal algorithm. Finally, drop the unneeded OrgChart.boss_emp_name column
    which used to represent the edges of a graph.
    This has some predictable results that we can use for building queries.  The root is always (left = 1, right = 2 * (SELECT COUNT(*) FROM TreeTable)); leaf nodes always have (left + 1 = right); subtrees are defined by the BETWEEN predicate; etc. Here are
    two common queries which can be used to build others:
    1. An employee and all their Supervisors, no matter how deep the tree.
     SELECT O2.*
       FROM OrgChart AS O1, OrgChart AS O2
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND O1.emp_name = :in_emp_name;
    2. The employee and all their subordinates. There is a nice symmetry here.
     SELECT O1.*
       FROM OrgChart AS O1, OrgChart AS O2
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND O2.emp_name = :in_emp_name;
    3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries which each employee controls:
     SELECT O2.emp_name, SUM(S1.salary_amt)
       FROM OrgChart AS O1, OrgChart AS O2,
            Salaries AS S1
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND S1.emp_name = O2.emp_name 
       GROUP BY O2.emp_name;
    4. To find the level and the size of the subtree rooted at each emp_name, so you can print the tree as an indented listing. 
    SELECT O1.emp_name, 
       SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt 
       THEN O2.sale_amt ELSE 0.00 END) AS sale_amt_tot,
       SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt 
       THEN 1 ELSE 0 END) AS subtree_size,
       SUM(CASE WHEN O1.lft BETWEEN O2.lft AND O2.rgt
       THEN 1 ELSE 0 END) AS lvl
      FROM OrgChart AS O1, OrgChart AS O2
     GROUP BY O1.emp_name;
    5. The nested set model has an implied ordering of siblings which the adjacency list model does not. To insert a new node, G1, under part G.  We can insert one node at a time like this:
    BEGIN ATOMIC
    DECLARE rightmost_spread INTEGER;
    SET rightmost_spread 
        = (SELECT rgt 
             FROM Frammis 
            WHERE part = 'G');
    UPDATE Frammis
       SET lft = CASE WHEN lft > rightmost_spread
                      THEN lft + 2
                      ELSE lft END,
           rgt = CASE WHEN rgt >= rightmost_spread
                      THEN rgt + 2
                      ELSE rgt END
     WHERE rgt >= rightmost_spread;
     INSERT INTO Frammis (part, lft, rgt)
     VALUES ('G1', rightmost_spread, (rightmost_spread + 1));
     COMMIT WORK;
    END;
    The idea is to spread the (lft, rgt) numbers after the youngest child of the parent, G in this case, over by two to make room for the new addition, G1.  This procedure will add the new node to the rightmost child position, which helps to preserve the idea
    of an age order among the siblings.
    6. To convert a nested sets model into an adjacency list model:
    SELECT B.emp_name AS boss_emp_name, E.emp_name
      FROM OrgChart AS E
           LEFT OUTER JOIN
           OrgChart AS B
           ON B.lft
              = (SELECT MAX(lft)
                   FROM OrgChart AS S
                  WHERE E.lft > S.lft
                    AND E.lft < S.rgt);
    7. To find the immediate parent of a node: 
    SELECT MAX(P2.lft), MIN(P2.rgt)
      FROM Personnel AS P1, Personnel AS P2
     WHERE P1.lft BETWEEN P2.lft AND P2.rgt 
       AND P1.emp_name = @my_emp_name;
    I have a book on TREES & HIERARCHIES IN SQL which you can get at Amazon.com right now. It has a lot of other programming idioms for nested sets, like levels, structural comparisons, re-arrangement procedures, etc. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Display current and previous months records only

    Hello gang,
    My selection criteria looks like this:
    not ({HRDEPBEN.PLAN_CODE} startswith ["C", "EAP", "HMIL", "V", "W"]) and
    (month({hrdepben.Creation_date}) = month(currentdate)) and
    {HRDEPBEN.PLAN_TYPE} = "HL"
    I modified it to this in order to pull in previous month's data too:
    {HRDEPBEN.PLAN_TYPE} = "HL" and
    not ({HRDEPBEN.PLAN_CODE} startswith ["C", "EAP", "HMIL", "V", "W"]) and
    (month({hrdepben.Creation_date}) = month(currentdate) or month ({hrdepben.Creation_Date})= month (currentdate)-1)
    However, it's still pulls the same record count and only January records, not Decembers'.
    Where am I going wrong?
    Thanks

    Looks like you're reporting against Lawson?  What database are you using?
    There are a few issues with the record selection criteria as it's written:
    1)  Month(CurrentMonth) - 1 = 0 when the current month is January.  That's why your not getting any records from December.
    2)  The  monthly criteria won't be passed to the database for processing, which is a huge performance issue when you're reporting against a system like Lawson.  You're basically telling the report to bring back all records that don't start with an array of values, irrespective of the date.  Only after all the possible records are returned across the network will the extraneous records be filtered out on the client side.  That's bad.
    3)  It's easy to use StartsWith or Like, but it's also pretty inefficient, since it forces a full table scan of the underlying table
    Personally, I'd do one of two things in order to both fix the query and optimize it:
    1)  Write the underlying query in SQL as either a View or SQL Command object
    or
    2)  Keep the current report, but make use of SQL Expression fields in order to optimize the query.
    Here are some examples of SQL Expression fields against Oracle (PL/SQL) that could be useful:
    /*{%PLANCODES}*/
    /*This SQL Expression evaluates whether or not a Plan Code starts with the specified values*/
    /*"HRDEPBEN"."PLAN_CODE" is selected directly from the Field Tree in the SQL Expression Editor*/
    CASE
      WHEN SUBSTR("HRDEPBEN"."PLAN_CODE",1) IN ('C','V','W') THEN 'Y'
      WHEN SUBSTR("HRDEPBEN"."PLAN_CODE",3) = 'EAP' THEN 'Y'
      WHEN SUBSTR("HRDEPBEN"."PLAN_CODE",4) = 'HMIL' THEN 'Y'
      ELSE 'N'
    END
    /*{&CREATEDATEMONTH}*/
    /*This SQL Expression returns the month of the Creation Date field*/
    /*"HRDEPBEN"."CREATION_DATE" is selected directly from the Field Tree in the SQL Expression Editor*/
    TO_NUMBER(TO_CHAR("HRDEPBEN"."CREATION_DATE",'mm'))
    You could also create formula to return the Month value for last month and then use it in your record selection:
    //{@LASTMONTH}
    //This formula returns the Month value for Last Month
    //IIF statements can be passed to the database for processing
    IIF(Month(CurrentDate) = 1, 12, Month(CurrentDate) - 1)
    With expressions and formulas like these in place (this code is Oracle and DB2 compatible, it would be different for T-SQL), you could then modify your record selection criteria to be something simpler, like this:
    {HRDEPBEN.PLAN_TYPE} = "HL" and
    {%PLANCODES} = 'N' and
    {%CREATEDATEMONTH} IN {@LASTMONTH} TO MONTH(CURRENTDATE)// MONTH(CURRENTDATE) is passed to the DB
    By laying the groundwork, you'll have a much more efficient report and, in the case of the @LastMonth, more accurate! Hope this helps!
    p.s. a disclaimer on using SQL Expressions in this manner - it's not officially supported, although it's worked since Version 7 (when SQL Expressions were introduced) and there will be support for them in various 2011 versions. As such, they'll work for years. I use them all the time and they're fantastic for optimizing reports.

  • Are TreePaths only valid in the TreeModel they originate from?

    I've got a JTree that lists our warehouse inventory, grouped by primary and secondary invenotry categories. (IE. "Printers" / "Laser" / "SomeLaserPrinter". ) The tree is populated through a SQL query.
    I've got a checkbox that, when the value changes, decides if the tree should show or hide inventory categories that don't contain any inventory items at the moment.
    What happens when I check/uncheck the box is that the tree is rebuilt from scratch according to it's value.
    Now, if there is something selected in the tree when I click that checkbox, I want the same item to be selected and expanded when the tree is rebuilt. This is where I've been running in to problems.
    The ActionListener for the checkbox is as follows:
    //hideEmptyNodes is the JCheckBox
    hideEmptyNodes.addActionListener( new ActionListener() {
          public void actionPerformed( ActionEvent e ) {
           try { //inventoryTree is the tree
                TreePath tp = inventoryTree.getSelectionPath();
                 // the InventoryTree.fillWithInventory(boolean hideEmpty) method
                 // clears and populates the tree from a SQL query.
           inventoryTree.fillWithInventory( hideEmptyNodes.isSelected() );
                inventoryTree.expandPath(tp);
                inventoryTree.setSelectionPath(tp);
         } catch ( SQLException ex ) {
           LGRUtils.debugErrln( "Error filling tree." );
        } );This, does NOT work, for some reason. I tried creating the TreePath from the new TreeModel, but still the same:
    hideEmptyNodes.addActionListener( new ActionListener() {
          public void actionPerformed( ActionEvent e ) {
         try { //inventoryTree is the tree
              Object o = inventoryTree.getLastSelectedPathComponent();
               // the InventoryTree.fillWithInventory(boolean hideEmpty) method
               //clears and populates the tree from a SQL query.
           inventoryTree.fillWithInventory( hideEmptyNodes.isSelected() );
              TreePath tp = new TreePath(
                  ((DefaultTreeModel)inventoryTree.getModel())
                  //SimpleTreeNode extends DefaultMutableTreeNode and only
                  //overrides the boolean equals(Object) method.
                  .getPathToRoot((SimpleTreeNode)o));
              inventoryTree.setSelectionPath(tp);
         } catch ( SQLException ex ) {
           LGRUtils.debugErrln( "Error filling tree." );
        } );Quite frankly, I'm at a loss to how this stuff works. I've searched a bit around the forums, and I've found plenty of other people who have problems with setting the selection paths of trees. None of them have gotten their problems solved in any uniform way, it seems the solution varies from user to user.
    Any pointers to a way of doing this, and making it work, would be greatly appreciated!
    -christig

    First thing I would tell you is that if you will not rebuild a tree from scratch, you will not have this problem!
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

Maybe you are looking for

  • 0I_FYPER - Variable in BEx gives no result

    Hello all, I have a problem in BEx-reporting after a releasechange from BW3.5 to BI7.0 and at the same time SEM-BCS4.0 to SEM-BCS6.0 which belongs to the variable 0I_FYPER. I use this variable in the columns (only) in order to give the user the possi

  • Configuration planning Strategy task bwtn PP/SD Consultant

    Hello Consultant As we known, planning strategy is incdluing two elements( requirements type for PIR; Requirement type for customer requirement) path:SPRO>Production>Production Planning>Demand Management>Planned Independent Requirements>Planning Stra

  • Adobe Pro creating hyperlinks to original documents when converting

    This just started happeing.  When I covert an HTML, Text, Word, Powerpoint, etc - it will create a hyperlink to the orginal document in the converted PDF at the bottom of each page.  I do not want this hyperlink - how do I remove this feature?

  • Prints are darker than what appears on PC screen

    Windows Vista Business OS Acer laptop PC PSE6 Good morning. I'm so hoping that someone has an easy solution to this printing issue. In PSE6, I've created 85 scrapbook poem pages in the following format:  300 dpi; 12 x 12 size that will be reduced to

  • To set username in cookies

    Hi, How to set japanese user name in cookies using java servlet or jsp. Can you help me? By M.Mathan.