Home » SQL & PL/SQL » SQL & PL/SQL » Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run
Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619783] Fri, 25 July 2014 01:11 Go to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
Hello Gurus,
I am not a pl/sql dev but i am struck somewhere with a procedure which i had to execute in sap hana,
my requirement here is
UNLOAD TABLE_NAME;
will unload the table to persistent layer
but i have many tables that are to be unloaded which i have retrieved through a query so i want unload tab1;,unload tab2.....and so onn to run for 150 times through a looping procedure.
can someone please help.

Thanks in advance.Smile

Regards
Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619793 is a reply to message #619783] Fri, 25 July 2014 01:54 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Is this problem related to Oracle? "sap hana" doesn't sound oracleish to me.
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619794 is a reply to message #619783] Fri, 25 July 2014 01:55 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

what "unload" means for you?

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619795 is a reply to message #619793] Fri, 25 July 2014 01:56 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
well although the problem is related to SAP, i ll have to write a stored procedure to execute this task... which is sql
i would really apperciate it if you could explain me the flow of this procedure!!!

Regards,
Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619796 is a reply to message #619794] Fri, 25 July 2014 01:57 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
unload is a function in sap which unloads the column tables to the persistent layer
so i ll have to unload around 150 tables....in one go
I have a query with one column which has around 150 table name
unfortunately i sap doesnot have a function to unload them at once, so i very badly need a procedure to do the task.

Regards,
Krishna

[Updated on: Fri, 25 July 2014 02:00]

Report message to a moderator

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619797 is a reply to message #619795] Fri, 25 July 2014 01:59 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I have no idea what "unloading data to persistent layer" means, even though you have to do it in PL/SQL. What is a "persistent layer"? What is the final result supposed to be? Is it a text file (comma-separated values, perhaps?) that contains contents of a table?

Maybe it would help if you could explain it a little bit further.
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619798 is a reply to message #619797] Fri, 25 July 2014 02:02 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
i want to move the data from the cache memory to the hard disk(persistent layer) for which i have a function called unload table_name;
but this function unloads only one table at a time...i have around 150 tables in a table of single column...so i want all the tables one by one to concatenate with the UNLOAD and get executed.

Regards,
Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619799 is a reply to message #619798] Fri, 25 July 2014 02:10 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Is UNLOAD an Oracle stored function? Where do you run the UNLOAD function from? Operating system command prompt, or Oracle (SQL*Plus prompt)? As far as I understood, if there's a table named EMPLOYEES, then you "unload" it by running
unload employees
Is that correct?

You want to avoid typing 150 table names manually, and want Oracle to do that job for you. If that's so, maybe this is what you are looking for: concatenate UNLOAD with all table names that belong to a single schema:
SQL> select 'unload ' || table_name from user_tables;

'UNLOAD'||TABLE_NAME
-------------------------------------
unload DEPT
unload PLAN_TABLE
unload TOAD_PLAN_TABLE
unload MV_EMP
unload QUEST_SL_TEMP_EXPLAIN1
unload EXT_TABLE_CSV
unload EXCEPTIONS
unload EMP

8 rows selected.

SQL>
So, if you run the UNLOAD function from operating system command prompt, you'd store all those UNLOAD commands into a batch file and run it once (while every UNLOAD line would unload one table).
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619800 is a reply to message #619796] Fri, 25 July 2014 02:12 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
krishnapawan.44@gmail.com wrote on Fri, 25 July 2014 08:57
unload is a function in sap which unloads the column tables to the persistent layer
unfortunately i sap doesnot have a function to unload them at once, so i very badly need a procedure to do the task.


Are you sure that you're not looking for an ABAP program instead of PL/SQL? As far as I know, SAP recommends to avoid using Native SQL and instead using Open SQL (SQL within an ABAP program). Therefore you don't manipulate directly your database yourself.

If you're looking for an ABAP program, some kind of BAPI allowing to run mass data upload as you say, then ask your question on the SAP SDN forum which is for SAP related questions, in paricular ABAP programming.

[Updated on: Fri, 25 July 2014 02:12]

Report message to a moderator

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619802 is a reply to message #619799] Fri, 25 July 2014 02:17 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
/forum/fa/12075/0/
Great guru, i am almost close..I am getting a result like this..
but instead of the UNLOAD TABLE_NAME in the record...
i want each record to get executed now... guess you are halfway to achieve my desired task.


Regards,
Krishna

  • Attachment: Capture.PNG
    (Size: 12.13KB, Downloaded 1146 times)
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619803 is a reply to message #619800] Fri, 25 July 2014 02:18 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
No dariyoosh , i am looking for a procedure in sql coz the query is getting executed in the sql engine of sap hana.

Regards,
Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619804 is a reply to message #619802] Fri, 25 July 2014 02:19 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
As I said: I don't know what your UNLOAD function is. Until you answer that question (re-read my previous message), there's nothing I can do.
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619809 is a reply to message #619804] Fri, 25 July 2014 02:26 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
SAP HANA is an in-memory computing appliance where the tables are stored in cache memory for a faster retrieval but if the cache memory is full we can send the tables back to the hard disk and create some empty space in the cache
hard disk := persistent layer
cache := in-memory

so we have a function called UNLOAD to achieve this task,
eg: UNLOAD emp;
this function will remove the table from the cache and send it back to the persistent layer clearing the cache memory.
Unfortunately the unload function can only unload one table at a time, but my scenario here is to unload around 150 tables in a loop which gets executed one by one
eg: usage of a cursor will process one record at a time

so
UNLOAD emp1;====> should get executed and then move to
UNLOAD emp2;====> should get executed and then move to the next part and so onnnn....

I have a table(with one column) in my case where i have all the table names in it.
now i want the tables names to get dynamically concatenated with "UNLOAD" and get executed...

Hope it is clear now.

Regards,
Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619812 is a reply to message #619809] Fri, 25 July 2014 02:42 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I'm sure that it is clear to you. Unfortunately, it is not to me. I still don't know WHERE is UNLOAD function executed FROM.
a) operating system command prompt
b) SQL*Plus (or PL/SQL)

  • If your answer is (a), then there's no problem (once again: create a batch script, put all those UNLOAD commands in there, run thet script).
  • If your answer is (b), then you'll have to enclose all those UNLOAD commands between BEGIN and END and run it as an anonymous PL/SQL block.
  • If it is a combination of (a) and (b) (i.e. UNLOAD is an operating system function but you want to call it from PL/SQL), then you'll have to use DBMS_SCHEDULER.

[Updated on: Fri, 25 July 2014 02:43]

Report message to a moderator

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619817 is a reply to message #619812] Fri, 25 July 2014 03:55 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
Hi,
The option is (b),the statements have to get executed in the plsql engine...
is there a way out ??


-Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619821 is a reply to message #619817] Fri, 25 July 2014 04:40 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Sure; as I said:
begin
  unload table_1;
  unload table_2;
  ...
  unload table_150;
end;
/
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619825 is a reply to message #619821] Fri, 25 July 2014 05:26 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
yeah absolutely right, i want it to get executed in that manner in a loop.
Can u please help me out?
Thanks a lot for patiently replying to my msgs and trying to help me out, i really appreciate it. Smile

-Krishna

[Updated on: Fri, 25 July 2014 05:29]

Report message to a moderator

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619829 is a reply to message #619825] Fri, 25 July 2014 06:40 Go to previous messageGo to next message
ThomasG
Messages: 3211
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
If you want to execute them "in that manner in a loop." in the PL/SQL engine then you just have to execute them the way Littlefoot posted.

Have you tried that? What happened when you tried that? If you don't tell us these things first, there is nothing more anybody will be able to tell you.



Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619830 is a reply to message #619829] Fri, 25 July 2014 06:44 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
Unfortunately Mr.Thomas there are around 150 table names that i have to execute concatenating with UNLOAD , and so i am afraid that is a tedious and practically impossible task.if you could kindly go through the above thread you will get the exact scenario. i need a plsql program with loop and dynamic sql and cursors where each record can be fetched at a single time.

-Krishna
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619831 is a reply to message #619830] Fri, 25 July 2014 06:58 Go to previous messageGo to next message
ThomasG
Messages: 3211
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Here is an example that executes "Dbms_Output.put_line" in the PL/SQL engine in a loop for the first 10 tables in all_tables :

SQL> BEGIN
  2    FOR l IN (SELECT table_name FROM all_tables WHERE ROWNUM < 10) LOOP
  3      Dbms_Output.put_line(l.table_name);
  4    END LOOP;
  5  END;
  6  /
ICOL$
CON$
UNDO$
PROXY_ROLE_DATA$
FILE$
UET$
IND$
SEG$
COL$

PL/SQL procedure successfully completed.


If "unload" can indeed be run as pl/sql command that will work. If not, you have do define where and how "unload" needs to be called exactly.
Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619832 is a reply to message #619830] Fri, 25 July 2014 06:58 Go to previous messageGo to next message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
CREATE PROCEDURE UNLOAD_TO_PERSISTENCE LANGUAGE SQLSCRIPT AS
BEGIN
DECLARE L INT := 0;
CURSOR c_cursor1 FOR
SELECT TABLE_NAME FROM INACTIVE_TABLES;
FOR r1 AS c_cursor1 DO
WHILE L<= (SELECT COUNT(*) FROM INACTIVE_TABLES)
UNLOAD r1.TABLE_NAME;
L := :L + 1;
END WHILE;
END FOR;
END;


If you could have a look at this, and let me know if i am in the right path that would really b helpful.
The syntaxes are a little different from sql.

-Krishna

[Updated on: Fri, 25 July 2014 07:02]

Report message to a moderator

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619833 is a reply to message #619832] Fri, 25 July 2014 07:07 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Here's an example:
- A1_TABLES contains your table names (150 of them) (I inserted only 2)
- TABLE_1 and TABLE_2 are two of those 150 tables, and you want to "unload" them

SQL> create table a1_tables (table_name varchar2(30));

Table created.

SQL> create table table_1 (id number);

Table created.

SQL> create table table_2 (id number);

Table created.

SQL>
SQL> insert all
  2    into a1_tables values ('TABLE_1')
  3    into a1_tables values ('TABLE_2')
  4    into table_1   values (100)
  5    into table_2   values (200)
  6  select * From dual;

4 rows created.


A1_UNLOAD procedure acts as your UNLOAD procedure (which is a black box for me). You are unloading, I'm purely selecting some values:
SQL> create or replace procedure a1_unload (par_table_name in varchar2)
  2  as
  3    l_str    varchar2(500);
  4    l_min_id table_1.id%type;
  5  begin
  6    /* You are "unloading" tables; I don't know what it really does, so I'm
  7       selectning MIN(ID), just to see that the procedure *is doing* something
  8    */
  9    l_str := 'select min(id) from ' || par_table_name;
 10    execute immediate (l_str) into l_min_id;
 11
 12    dbms_output.put_line(par_table_name ||': '|| l_min_id);
 13  end;
 14  /

Procedure created.


Here's the loop you were talking about: selecting 150 tables from A1_TABLES and passing their names to A1_UNLOAD procedure:
SQL> begin
  2    for cur_r in (select table_name from a1_tables) loop
  3      a1_unload(cur_r.table_name);
  4    end loop;
  5  end;
  6  /
TABLE_1: 100
TABLE_2: 200

PL/SQL procedure successfully completed.

SQL>
The result is here (printed table names and min(ID)s from them; so, it kind of works.

Now, see whether you can adjust it to your needs.

[Updated on: Fri, 25 July 2014 07:08]

Report message to a moderator

Re: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run [message #619835 is a reply to message #619833] Fri, 25 July 2014 07:23 Go to previous message
krishnapawan.44@gmail.com
Messages: 12
Registered: July 2014
Location: banglore
Junior Member
THANK YOU LITTLE FOOT FOR THE EFFORT THAT YOU HAVE PUT IN TO SOLVE MY ISSUE, I AM SO THANKFUL TO YOU.I CAN TAKE IT FROM HERE NOW .....

BEST REGARDS Smile ,
Krishna
Previous Topic: Compare SUM of column to another table (column)
Next Topic: How to Restrict User from Connecting to Database Through Specific hostname
Goto Forum:
  


Current Time: Tue Apr 23 05:04:34 CDT 2024