Questions in HANA Sql

Hi Team,
I have some questions as under:
     1)how can i use a dynamic tables/fields in the Cursor definition :
               say for eg.., Delcare Cursor Cur_1(dyn_field1 varchar(10), dyn_field2 varchar(10), dyn_table varchar(15)
                               for select <dyn_field1> <dyn_field2>... <dyn_fieldn> from <dyn_table> ? as it is not acceptable in the Cursor definition to use as:
                               for select :dyn_field1 :dyn_field2 from :dyn_table ? as it is not acceptable in the Cursor definition to use a Colon(:) before them..
     2)how to processing the records fetched from a table type:
               say for eg.., if I got a set of records from another procedure that contained a set of records(of a table type)
                                 how to Loop at the records and check for the fields inside them... say I got table that has 5 records and each with 3 fields in it...
                                   after I receive them in the calling procedure, how can Loop at them and check for conditions on the fields... Just like how the
                                   processing will be done in ABAP... Loop at itab into wa_tab.... check the conditions on the fields and Endloop.. ?
     3)how to check for dynamic fields while looping in the Cursor records...
               say for eg.., if I got 10 records from a stored procedure and I am not aware of the names of the fields in the cursor records
                                   if the code is like: I fetched all the fields from a table which has been derived out of another Cursor...
                                   For tab1 as Cursor_1 do
                                             tab1 has a field called Hana_table and this changes for every cursor loop...
                                             I defined a Cursor_2 as Select * from tab1.hana_table...
                                             Now in the Cursor loop of tab2.... For tab2 as Cursor_2 do
                                                  how do I know which fields are there in the Cursor_2 and to process them? 
     4)how to use Local and Global Internal tables in HANA sql and what is its impact on the HANA tables ?
Please provide answers on the above points as they are very much need for my current development.
Thanks in advance for your inputs.
Regards,
Vishnu                   

hi Lars,
thanks for your inputs...
I am very much new to HANA and Sql - just 1.5 months into these areas...
well my requirement is as under:
          I was given a task to check the differences in the loaded tables in HANA...
1)there is a table(say tab_1) which has 3 fields(say field1, field2 and field3) and field1 refers to a HANA table and field2 and field3 refer to the fields in that HANA table...
2)now I need to read all the records of the table tab_1 and for every record of tab_1, I need to take the HANA table(field1) and get the entries against the fields 2 and 3... this referred HANA table can have multiple records....
3)now I have to check other fields say field4 and field5( of the table tab_1) with that of each and every record obtained against the HANA table entries of the Step(2)...
4)if for any one record of Step(2) matches with the field values of field2 and field3(of tab_1), I need to do some INSERTION into a table...
Dynamic things are:
a)the HANA table might change for each record of records of table tab_1
b)the fields in the HANA table get changed.. need compare field2 with first field of HANA table and field3 with the 2nd record of HANA table...
for this requirement I resorted to Cursors as I am not aware of any other Sql result sets that can be useful in my requirement...
I used the following logic:
      For tab1 as cursor_1(fetched fields 1 to 5)
          For tab2 as cursor_2(fetched the fields -> from HANA table of cursor_1-hana_table)
               Now I created a Local temporary table using EXEC statement as under:
              va_sql := 'INSERT INTO #hana_table select "' || tab2.field1 || '" as field1'  || ' ' ||
                '"' || tab2.field2 || '" as field2 ' || 'from ' || :va_hana_table;
              exec (:va_sql);
         the Stored procedure was successful, how to read the values present in #hana_table?
     I am getting an error:
     invalid table name:  Could not find table/view #hana_table in schema SYSTEM
     if I use as under:
     for tab3 as "#hana_table" do
     end for;
     the error is:
     identifier must be declared
I hope the requirement is clear to you... please provide your valuable suggestions...
Regards,
Vishnu

Similar Messages

  • Using HANA SQL Functions in select list of CDS Views

    Dear Expert,
    Kindly please let me know if we can use the HANA SQL Function (Ex: ADD_DAYS, SECONDS_BETWEEN) in the select list of CDS Views?
    If I create a CDS like below I get error that timestamp is not supported.
    For Example:
    @AbapCatalog.sqlViewName: 'ZMR_H_CA'
    @EndUserText.label: 'CAG A'
    define view viewname
    with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
    as select from table {
    key resource_key,
    TO_TIMESTAMP(begtstmp) as start_tmp,
    TO_TIMESTAMP(begtstmp) as end_tmp
    where
    (begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
    and
    (begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
    Thanks,
    Giri

    Hi Giri,
    the list of provided features can be found in the ABAP Language Documentation (F1 in the CDS View).
    As CDS in ABAP is abstracted from the database layer, the database features are not directly accessible. That means, you cannot use any HANA or MaxDB feature available. So the answer to your question is no. The reason for this is, that ABAP CDS views can be created on all SAP-supported databases, hence, we can only provide those features, supported by all databases.
    Having said this, there are some exception, e.g. the CDS views with input parameters, which are not supported by all databases. In these cases, you'd have to additionally use the utility class CL_ABAP_DBFEATURES (see http://scn.sap.com/community/abap/blog/2014/10/10/abap-news-for-740-sp08--abap-core-data-services-cds) for more details.
    Best,
      Jasmin

  • HANA SQL for BPC cubes

    I have been looking for getting start help/ideas on how to push BPC BADI logic down to HANA SQL. Not really sure where is the right place my question. Which forum should I focus on?  Not much help in BPC forum on this subject.
    ~Dilkins

    Hi Dilkins,
    Any responses?
    thanks

  • Some basic questions on HANA

    Hi All,
    I have some basic questions on SAP HANA,
    I heard from one of my colligues that it is mandatory to learn SQL scripts for HANA, is it true?
    Or basic knowledge is enough for HANA???
    Is it added advantage while working on HANA or can we manage with basic knowledge of SQL???
    I tried to find answers for these questions in SCN, but I could not get proper answers, So could you please provide answers for above my questions.
    Thanks in advance,
    Venkat Kalla

    Hi Vladmir,
    SAP HANA is a platform and is more than just database. Which can serve both OLTP and OLAP.
    But since it is a database, Sp SQL skills helps you while modelling in SAP HANA. So When will it be helpful ? It is while addressing some complex requirements using SAP HANA.
    At the end of the day, when you want to work in HANA ( a super duper database ) and you still thinking of whether to learn SQL or not?
    Regards,
    Krishna Tangudu

  • Export arabic character into csv file turns into question mark in sql dev

    Hi,
    I am trying to export a table's output that contains some arabic and english mixed data, when I try to export it in csv, all the arabic characters change into question mark (?) but the same export is working fine on .xls or .xlsx.
    Since we have to export a huge data and csv is much faster thar .xls, kindly let me know why it is happening and what is the solution for this.
    Well, we are on Oracle 11gR2 and Sql Dev is 3.1
    Appreciate your time and experience sharing.
    Regards.

    Hi,
    Since you say it works for xls but not csv, and the only applicable preference setting ( Tools|Preferences|Database|Utilities|Export|Encoding ) should apply to all export formats, I would imagine this is a bug. Especially if the encoding specified in Preferences is consistent with the client OS settings. I was not able to find any prior bug logged against the Export utility for this issue.
    I logged a bug for this:
    Bug 13993410 - FORUM: ARABIC CHARACTER ENCODING RESPECTED FOR XLS BUT NOT CSV
    Regards,
    Gary
    SQL Developer Team

  • A silly question about oracle.sql.timestamp and java.sql.timestamp

    Hi,
    I'm looking at a method that takes objects of type Object and does stuff if the object is really a java.sql.timestamp. If it is not then an error is flagged. In my case it flags an error when an object of type oracle.sql.timestamp is passed to it. Not really entirely comfortable with java (i'm still learning it), here's my stupid question :- why isn't oracle.sql.timestamp a subclass of java.sql.timestamp? Also in various books it indicates that java.sql.timestamp maps to oracle.sql.timestamp. Does that mean you have to physically do the mapping:
    i.e.
    java.sql.Timestamp t = new Timestamp( new oracle.sql.Timestamp( CURRENTTIMESTAMP ).timestampValue() );
    or is there something else to it.
    Thanks.
    Harold.

    The best forum for this is probably Forum Home » Java » SQLJ/JDBC
    Presumably you are refering to oracle.sql.TIMESTAMP. While this is intended to (and does) correspond to java.sql.Timestamp it can't be a subclass because it needs to be a subclass of oracle.sql.Datum.

  • Question on pl/sql developer tool

    Hello,
    I'm trying to debug a package using pl/sql developer. It looks good but the variable defined in the package are not showing their value even in the debug mode to see what they hold at that particular instance.
    How to achieve this?
    Thank You.
    KK

    PL/SQL Developer is not an Oracle tool.
    Post your question on the PL/SQL Forum @ http://www.allroundautomations.com/threads/ubbthreads.php?ubb=cfrm
    If I recall correctly you have to set a Debug checkbox somewhere in the Tools => Preferences menu.
    (But I cannot check it at this moment).

  • Question about PL/SQL Function in report

    Hi all. I have a (basic) question about using a PL/SQL function in a report. In my report page I have an item (PL/SQL function) that has the following syntax:
    return username from t1
    where username like 'Le%'
    I reference this item in an email process. Ideally this function would return all usernames that begin with 'Le' in the drafted email; however, its not looping so I'm only getting a return on the first name.
    I have a few books on PL/SQL but I'm not exactly sure where to start - I imagine there is a loop process I need to integrate into the function but, like I said, I'm not sure.
    I would have posted this to the PL/SQL forum but also wanted some feedback on whether or not using this method is the best way forward. Essentially I have a table with usernames and just want to send email messages based on some simple logic.
    Thanks!
    Len

    Hi Sergio,
    First, it's an honor to have you reply to my post. Thanks!
    To be more specific,
    T1 is a table containing the results from a user security scan. Username is a column in this table containing user names. What I have done is create a page in HTML DB with the following elements:
    1. An 'Item' containing the PL/SQL function that is hidden. The purpose of this Item is to generate information from T1 that meets the simple logic parameters - in this case, the user names that begin with "Le". I have called this Item P145_TT
    2. A 'Process' containing references to HTMLDB_MAIL. The 'Process' looks similar to this:
    HTMLDB_MAIL.SEND(
    P_TO => '[email protected]',
    P_FROM => 'Anon Email Account',
    P_BODY => 'Note: This message was automatically generated. Do not attempt to reply to this email.
    These are the users that begin with Le: '||:P145_TT||' ',
    P_SUBJ => 'Summary');
    3. A 'Button' to submit the process and (hopefully) send the message containing all users that adhere to the logic in the function.
    4. If I use 'return username from t1...' I will get a username generated, but like I said previously, it only gives me the first and does not loop.

  • Basic questions about PL/SQL web services and datasource names

    Hi there,
    I successfully generated a web service for a PL/SQL packaged procedure in JDeveloper 11.1.1.3.0).
    In the web service base class the following code was generated:
    __dataSource = (javax.sql.DataSource) __initCtx.lookup("java:comp/env/jdbc/dbconnectionDS");However in the weblogic server the datasource name is jdbc/somethingelse so the deployment fails at first.
    What is the recommended procedure to solve this issue? The obvious solution is to manually edit the source -- that is what I did and it worked fine. However if I re-generate the web service I will lose my change. Is there a better way to do this?
    Another question -- in the generated web.xml file, there is a resource-ref for the datasource. I was hoping that changing the datasource name there would help but it didn't work. What is it used for in this context?
    Thanks
    Luis

    Hi Vishal,
    I did as you suggested but it didn't work... see below more details.
    Thanks
    Luis
    1 - I re-generated the web service from the PL/SQL package. The constructor in CFBTestWSBase class looks likes this:
    public CFBTestWSBase() throws SQLException
      {  try {
    javax.naming.InitialContext __initCtx = new javax.naming.InitialContext();
    __dataSource = (javax.sql.DataSource) __initCtx.lookup("java:comp/env/jdbc/custfeedbackDS");
    } catch (Exception __jndie) {
    throw new java.sql.SQLException("Error looking up <java:comp/env/jdbc/custfeedbackDS>: " + __jndie.getMessage());
    }2 - I added the following section to weblogic.xml:
      <resource-description>
        <res-ref-name>comp/env/jdbc/custfeedbackDS</res-ref-name>
        <jndi-name>jdbc/DataSource</jndi-name>
      </resource-description>3 - I got the following error when during deployment to weblogic server:
    [HTTP:101216]Servlet: "CFBTestWSPort" failed to preload on startup in Web application: "CustFeedbackTestWS.war".
    java.sql.SQLException: Error looking up <java:comp/env/jdbc/custfeedbackDS>: While trying to look up comp/env/jdbc/custfeedbackDS in /app/webapp/CustFeedbackTestWS.war/346617503.
    at cfbtestws.CFBTestWSBase.<init>(CFBTestWSBase.java:33)
    at cfbtestws.CFBTestWSUser.<init>(CFBTestWSUser.java:11)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    ...

  • STATSPACK question using spauto.sql

    Using spauto.sql takes a snapshot of the database every hour, which is exactly what i want , but the question is when i run spreport, and trying to compare performance e.g ( 5.00p.m and 7.00p.m) how do go about it.

    Hi ,
    Following query will give you the snapshot id 's along with timings .
    select name,snap_id,to_char(snap_time,'mm/dd/yyyy hh24:mi:ss') from stats$snapshot,v$database.
    Provide start and end Id's to the spreport.sql .

  • Question about updating SQL Server on failover cluster

    Hi all,
    I would like to better understand the update process of SQL Server (2008 r2) in a failover cluster environment.
    In our cluster we have 4 instances of SQL running, where two of them I am able to at anytime stop the instance and update it.
    The question is... Applying the latest update, will update forcibly all instances installed on that node, or do I have the ability to choose which instance I want to update?
    This way, I could "test" the update process in those two SQL Instances, as described in http://support.microsoft.com/kb/958734 and after finishing I would update the remaining instances.
    Please let me know.
    Thanks in advance.
    Nuno Silva

    Hi Nuno,
    It's a failover cluster issue, I moved it to SQL Server High Availability and Disaster Recovery. So that you can get better help.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Question about The SQL*Plus menu item

    The help doc says we can use SQL*Plus commands. So I open it from the SQL*Plus menu item under Tools. After I gave the installed SQL*Plus location and file name, SQL*Plus was opened by itself asking for a password. The question is are all SQL*Plus commands are supported/will be supported in Raptor? Thanks.
    ben

    See this.. http://www.oracle.com/technology/products/database/project_raptor/sql_worksheet_commands.html
    Not everything in plus is supported
    -kris

  • Simple question aboout PL/SQL nested tables

    Hello, my question is about nested tables. Suppose I have a nested table:
    TYPE int_array IS TABLE OF INT;
    v_int_array int_array;
    Is there a built in function to allow me to search v_int_array for a specific integer value?
    George

    Use MEMBER OF operator:
    declare
        TYPE int_array IS TABLE OF INT;
        v_int_array int_array := int_array(1,2,3,4,5);
    begin
        if 1 member of v_int_array
          then
            dbms_output.put_line('Found it!');
        end if;
    end;
    Found it!
    PL/SQL procedure successfully completed.
    SQL> SY.

  • STRING_AGG function in SAP HANA SQL Script

    Hi,
    We have HANA Revision 7.3.
    STRING_AGG function seems to work when we just execute the query without assinging it to the value.
    However as soon as we assign it to a value in a stored procedure or scripted Calcuation view, it fails.
    Any ideas?
    Thanks,
    Hyun

    Lars,
    My apologies.
    Here are 3 screen shots. Two are error message generated
    when using STRING_AGG in a Calculation View, one is it running successfully in
    SQL window when it is not assigned to output variable.
    Thanks,
    Hyun

  • Guidelines for HANA SQL Script

    Dear Experts,
    Could you please share best practices on the usage of SQL script in procedures and Script based calculation views?
    I searched already for the relevant information, but could not find any yet. I request you share any information other than what is available in help.sap.com based on your experience.
    Thank you,
    Raghavendra.

    Hi Raghavendra,
    As Lars said, it is very difficult to answer your question and it always depend on the designing solution for specific requirements. General rules we follow in scripting are
    1. Avoid inline queries
    2. Break complex SQL to small and simple SQL statements and club the results
    3. Always analyze cost using Visualize Plan
    4. Avoid cursors/loops
    5. Avoid mix of SQL and CE (most commonly found best practice )
    Regards,
    Chandra.

Maybe you are looking for