Cursor to update hierarchy column in every row in several times

Hierarchy value must be returns to multiple rows Hierarchy holds the value of id for exam I'd=1 the value of 1 holding parent_id checks until the id be null .Can any one help me to write a cursors logic in stored procedures in my sql

I'd   parent_id     hierarchy
1        3.                                
3.        2
2.        1

If we pass 1 as input then output is . This value is stored in hierarchy

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum